1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 12:47:33 +02:00

PdoDriver: applied #332 #287

This commit is contained in:
David Grudl
2024-09-03 00:09:05 +02:00
parent 0a32bb5bdf
commit 29b58d64dd
2 changed files with 11 additions and 7 deletions

View File

@@ -217,17 +217,21 @@ class PdoDriver implements Dibi\Driver
*/ */
public function escapeText(string $value): string public function escapeText(string $value): string
{ {
return $this->driverName === 'odbc' return match ($this->driverName) {
? "'" . str_replace("'", "''", $value) . "'" 'odbc' => "'" . str_replace("'", "''", $value) . "'",
: $this->connection->quote($value, PDO::PARAM_STR); 'sqlsrv' => "N'" . str_replace("'", "''", $value) . "'",
default => $this->connection->quote($value, PDO::PARAM_STR),
};
} }
public function escapeBinary(string $value): string public function escapeBinary(string $value): string
{ {
return $this->driverName === 'odbc' return match ($this->driverName) {
? "'" . str_replace("'", "''", $value) . "'" 'odbc' => "'" . str_replace("'", "''", $value) . "'",
: $this->connection->quote($value, PDO::PARAM_LOB); 'sqlsrv' => '0x' . bin2hex($value),
default => $this->connection->quote($value, PDO::PARAM_LOB),
};
} }

View File

@@ -33,7 +33,7 @@ enum PureEnum
Assert::equal('1', $translator->formatValue(EnumInt::One, null)); Assert::equal('1', $translator->formatValue(EnumInt::One, null));
Assert::equal(match ($config['driver']) { Assert::equal(match ($config['system']) {
'sqlsrv' => "N'one'", 'sqlsrv' => "N'one'",
default => "'one'", default => "'one'",
}, $translator->formatValue(EnumString::One, null)); }, $translator->formatValue(EnumString::One, null));