Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 2, 2024
1 parent db76716 commit 4271a41
Showing 1 changed file with 21 additions and 53 deletions.
74 changes: 21 additions & 53 deletions src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,14 @@ public function getResource(): ?PDO
*/
public function getReflector(): Dibi\Reflector
{
switch ($this->driverName) {
case 'mysql':
return new MySqlReflector($this);

case 'oci':
return new OracleReflector($this);

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;
}
return match ($this->driverName) {
'mysql' => new MySqlReflector($this),
'oci' => new OracleReflector($this),
'pgsql' => new PostgreReflector($this, $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION)),
'sqlite' => new SqliteReflector($this),
'mssql', 'dblib', 'sqlsrv' => new SqlsrvReflector($this),
default => throw new Dibi\NotSupportedException,
};
}


Expand Down Expand Up @@ -237,28 +224,14 @@ public function escapeBinary(string $value): string

public function escapeIdentifier(string $value): string
{
switch ($this->driverName) {
case 'mysql':
return '`' . str_replace('`', '``', $value) . '`';

case 'oci':
case 'pgsql':
return '"' . str_replace('"', '""', $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;
}
return match ($this->driverName) {
'mysql' => '`' . str_replace('`', '``', $value) . '`',
'oci', 'pgsql' => '"' . str_replace('"', '""', $value) . '"',
'sqlite' => '[' . strtr($value, '[]', ' ') . ']',
'odbc', 'mssql' => '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']',
'dblib', 'sqlsrv' => '[' . str_replace(']', ']]', $value) . ']',
default => $value,
};
}


Expand All @@ -280,16 +253,11 @@ public function escapeDate(\DateTimeInterface $value): string

public function escapeDateTime(\DateTimeInterface $value): string
{
switch ($this->driverName) {
case 'odbc':
return $value->format('#m/d/Y H:i:s.u#');
case 'mssql':
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'");
}
return match ($this->driverName) {
'odbc' => $value->format('#m/d/Y H:i:s.u#'),
'mssql', 'dblib', 'sqlsrv' => 'CONVERT(DATETIME2(7), ' . $value->format("'Y-m-d H:i:s.u'") . ')',
default => $value->format("'Y-m-d H:i:s.u'"),
};
}


Expand Down

0 comments on commit 4271a41

Please sign in to comment.