1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00
This commit is contained in:
David Grudl
2024-09-03 00:10:21 +02:00
parent 29b58d64dd
commit 7d8c39f42a

View File

@@ -176,27 +176,14 @@ class PdoDriver implements Dibi\Driver
*/ */
public function getReflector(): Dibi\Reflector public function getReflector(): Dibi\Reflector
{ {
switch ($this->driverName) { return match ($this->driverName) {
case 'mysql': 'mysql' => new MySqlReflector($this),
return new MySqlReflector($this); 'oci' => new OracleReflector($this),
'pgsql' => new PostgreReflector($this, $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION)),
case 'oci': 'sqlite' => new SqliteReflector($this),
return new OracleReflector($this); 'mssql', 'dblib', 'sqlsrv' => new SqlsrvReflector($this),
default => throw new Dibi\NotSupportedException,
case 'pgsql': };
return new PostgreReflector($this, $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION));
case 'sqlite':
return new SqliteReflector($this);
case 'mssql':
case 'dblib':
case 'sqlsrv':
return new SqlsrvReflector($this);
default:
throw new Dibi\NotSupportedException;
}
} }
@@ -237,28 +224,14 @@ class PdoDriver implements Dibi\Driver
public function escapeIdentifier(string $value): string public function escapeIdentifier(string $value): string
{ {
switch ($this->driverName) { return match ($this->driverName) {
case 'mysql': 'mysql' => '`' . str_replace('`', '``', $value) . '`',
return '`' . str_replace('`', '``', $value) . '`'; 'oci', 'pgsql' => '"' . str_replace('"', '""', $value) . '"',
'sqlite' => '[' . strtr($value, '[]', ' ') . ']',
case 'oci': 'odbc', 'mssql' => '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']',
case 'pgsql': 'dblib', 'sqlsrv' => '[' . str_replace(']', ']]', $value) . ']',
return '"' . str_replace('"', '""', $value) . '"'; default => $value,
};
case 'sqlite':
return '[' . strtr($value, '[]', ' ') . ']';
case 'odbc':
case 'mssql':
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
case 'dblib':
case 'sqlsrv':
return '[' . str_replace(']', ']]', $value) . ']';
default:
return $value;
}
} }
@@ -280,16 +253,11 @@ class PdoDriver implements Dibi\Driver
public function escapeDateTime(\DateTimeInterface $value): string public function escapeDateTime(\DateTimeInterface $value): string
{ {
switch ($this->driverName) { return match ($this->driverName) {
case 'odbc': 'odbc' => $value->format('#m/d/Y H:i:s.u#'),
return $value->format('#m/d/Y H:i:s.u#'); 'mssql', 'dblib', 'sqlsrv' => 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')',
case 'mssql': default => $value->format("'Y-m-d H:i:s.u'"),
case 'dblib': };
case 'sqlsrv':
return 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')';
default:
return $value->format("'Y-m-d H:i:s.u'");
}
} }