mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 05:37:39 +02:00
improved DibiPdoDriver identifier escaping
This commit is contained in:
@@ -235,7 +235,28 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
return $this->connection->quote($value, PDO::PARAM_LOB);
|
return $this->connection->quote($value, PDO::PARAM_LOB);
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
return $value; // quoting is not supported by PDO
|
switch ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)) {
|
||||||
|
case 'mysql':
|
||||||
|
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||||
|
|
||||||
|
case 'pgsql':
|
||||||
|
$a = strrpos($value, '.');
|
||||||
|
if ($a === FALSE) {
|
||||||
|
return '"' . str_replace('"', '""', $value) . '"';
|
||||||
|
} else {
|
||||||
|
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'sqlite':
|
||||||
|
case 'sqlite2':
|
||||||
|
case 'odbc':
|
||||||
|
case 'oci': // TODO: not tested
|
||||||
|
case 'mssql':
|
||||||
|
return '[' . str_replace('.', '].[', $value) . ']';
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::FIELD_BOOL:
|
||||||
return $this->connection->quote($value, PDO::PARAM_BOOL);
|
return $this->connection->quote($value, PDO::PARAM_BOOL);
|
||||||
|
@@ -250,9 +250,12 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
|
|||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
$a = strrpos($value, '.');
|
$a = strrpos($value, '.');
|
||||||
if ($a === FALSE) return '"' . str_replace('"', '""', $value) . '"';
|
if ($a === FALSE) {
|
||||||
// table.col delimite as table."col"
|
return '"' . str_replace('"', '""', $value) . '"';
|
||||||
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
|
} else {
|
||||||
|
// table.col delimite as table."col"
|
||||||
|
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
|
||||||
|
}
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::FIELD_BOOL:
|
||||||
return $value ? 'TRUE' : 'FALSE';
|
return $value ? 'TRUE' : 'FALSE';
|
||||||
|
Reference in New Issue
Block a user