diff --git a/src/Connection.php b/src/Connection.php index a42310b8..b6ad48b4 100755 --- a/src/Connection.php +++ b/src/Connection.php @@ -1222,7 +1222,7 @@ public function getCacheSize(): int * An internal wrapper to dbsafeString, used to process a complete array of parameters * as used by prepared statements. * - * @param array $params + * @param array $params * @param list|false $escapes An array of boolean for each param, used to block the escaping of html-special chars. * If not passed, all params will be cleaned. * @@ -1257,7 +1257,7 @@ private function dbsafeParams(array $params, array | false $escapes = []): array $replace[$key] = $param; } - return array_values($replace); + return array_values($replace); // @phpstan-ignore return.type (Unable to fix right now) } /** diff --git a/src/ConnectionInterface.php b/src/ConnectionInterface.php index 1dfd3df2..066aac01 100755 --- a/src/ConnectionInterface.php +++ b/src/ConnectionInterface.php @@ -20,6 +20,7 @@ use Artemeon\Database\Schema\DataType; use Artemeon\Database\Schema\Table; use Artemeon\Database\Schema\TableIndex; +use BackedEnum; use Generator; use Stringable; @@ -313,7 +314,7 @@ public function encloseTableName(string $tableName): string; * Helper to replace all param-placeholder with the matching value, only to be used * to render a debuggable-statement. * - * @param list $params + * @param list $params */ public function prettifyQuery(string $query, array $params): string; diff --git a/src/DriverInterface.php b/src/DriverInterface.php index f0687baa..dfd17dbd 100755 --- a/src/DriverInterface.php +++ b/src/DriverInterface.php @@ -18,6 +18,7 @@ use Artemeon\Database\Schema\DataType; use Artemeon\Database\Schema\Table; use Artemeon\Database\Schema\TableIndex; +use BackedEnum; use Generator; use Stringable; @@ -68,7 +69,7 @@ public function insertOrUpdate(string $table, array $columns, array $values, arr * Sends a prepared statement to the database. All params must be represented by the "?" char. * The params themselves are stored using the second params using the matching order. * - * @param list $params + * @param list $params * * @throws QueryException */ diff --git a/src/EscapeableParameterInterface.php b/src/EscapeableParameterInterface.php index 9a2709f1..623d6122 100644 --- a/src/EscapeableParameterInterface.php +++ b/src/EscapeableParameterInterface.php @@ -13,8 +13,14 @@ namespace Artemeon\Database; +use Stringable; + interface EscapeableParameterInterface { public function isEscape(): bool; + + /** + * @return scalar|Stringable|null + */ public function getValue(): mixed; } diff --git a/src/Exception/QueryException.php b/src/Exception/QueryException.php index 747fd76d..5d0c35e6 100644 --- a/src/Exception/QueryException.php +++ b/src/Exception/QueryException.php @@ -13,6 +13,8 @@ namespace Artemeon\Database\Exception; +use Artemeon\Database\EscapeableParameterInterface; +use BackedEnum; use Exception; use Stringable; use Throwable; @@ -20,7 +22,7 @@ class QueryException extends Exception { /** - * @param list $params + * @param list $params */ public function __construct(string $message, private readonly string $query, private readonly array $params, ?Throwable $previous = null) { @@ -33,7 +35,7 @@ public function getQuery(): string } /** - * @return list + * @return list */ public function getParams(): array { diff --git a/src/MockConnection.php b/src/MockConnection.php index eae6ac27..18605e14 100644 --- a/src/MockConnection.php +++ b/src/MockConnection.php @@ -17,6 +17,7 @@ use Artemeon\Database\Schema\DataType; use Artemeon\Database\Schema\Table; use Artemeon\Database\Schema\TableIndex; +use BackedEnum; use Generator; use Override; @@ -336,6 +337,14 @@ public function encloseTableName(string $tableName): string public function prettifyQuery(string $query, array $params): string { foreach ($params as $param) { + if ($param instanceof BackedEnum) { + $param = $param->value; + } + + if ($param instanceof EscapeableParameterInterface) { + $param = $param->getValue(); + } + $query = (string) preg_replace('/\?/', isset($param) ? '"' . $param . '"' : 'NULL', $query, 1); }