1
0
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:
David Grudl
2008-06-18 23:34:35 +00:00
parent d12895102f
commit 2a4f5ec456
2 changed files with 28 additions and 4 deletions

View File

@@ -235,7 +235,28 @@ class DibiPdoDriver extends /*Nette::*/Object implements IDibiDriver
return $this->connection->quote($value, PDO::PARAM_LOB);
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:
return $this->connection->quote($value, PDO::PARAM_BOOL);

View File

@@ -250,9 +250,12 @@ class DibiPostgreDriver extends /*Nette::*/Object implements IDibiDriver
case dibi::IDENTIFIER:
$a = strrpos($value, '.');
if ($a === FALSE) return '"' . str_replace('"', '""', $value) . '"';
// table.col delimite as table."col"
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
if ($a === FALSE) {
return '"' . str_replace('"', '""', $value) . '"';
} else {
// table.col delimite as table."col"
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
}
case dibi::FIELD_BOOL:
return $value ? 'TRUE' : 'FALSE';