diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index 670faa29..0d087b5a 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -217,17 +217,21 @@ public function createResultDriver(\PDOStatement $result): PdoResult */ public function escapeText(string $value): string { - return $this->driverName === 'odbc' - ? "'" . str_replace("'", "''", $value) . "'" - : $this->connection->quote($value, PDO::PARAM_STR); + return match ($this->driverName) { + 'odbc' => "'" . str_replace("'", "''", $value) . "'", + 'sqlsrv' => "N'" . str_replace("'", "''", $value) . "'", + default => $this->connection->quote($value, PDO::PARAM_STR), + }; } public function escapeBinary(string $value): string { - return $this->driverName === 'odbc' - ? "'" . str_replace("'", "''", $value) . "'" - : $this->connection->quote($value, PDO::PARAM_LOB); + return match ($this->driverName) { + 'odbc' => "'" . str_replace("'", "''", $value) . "'", + 'sqlsrv' => '0x' . bin2hex($value), + default => $this->connection->quote($value, PDO::PARAM_LOB), + }; } diff --git a/tests/dibi/Translator.enums.phpt b/tests/dibi/Translator.enums.phpt index 270a8f81..1e9c919b 100644 --- a/tests/dibi/Translator.enums.phpt +++ b/tests/dibi/Translator.enums.phpt @@ -33,7 +33,7 @@ enum PureEnum Assert::equal('1', $translator->formatValue(EnumInt::One, null)); -Assert::equal(match ($config['driver']) { +Assert::equal(match ($config['system']) { 'sqlsrv' => "N'one'", default => "'one'", }, $translator->formatValue(EnumString::One, null));