1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 21:58:10 +02:00

- improved binary escaping

This commit is contained in:
David Grudl
2009-03-16 05:47:20 +00:00
parent 97969edace
commit a9afe1e397
4 changed files with 17 additions and 3 deletions

View File

@@ -281,9 +281,11 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
{
switch ($type) {
case dibi::FIELD_TEXT:
case dibi::FIELD_BINARY:
return "'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::FIELD_BINARY:
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
case dibi::IDENTIFIER:
// @see http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
$value = str_replace('`', '``', $value);

View File

@@ -265,9 +265,11 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
{
switch ($type) {
case dibi::FIELD_TEXT:
case dibi::FIELD_BINARY:
return "'" . mysqli_real_escape_string($this->connection, $value) . "'";
case dibi::FIELD_BINARY:
return "_binary'" . mysqli_real_escape_string($this->connection, $value) . "'";
case dibi::IDENTIFIER:
$value = str_replace('`', '``', $value);
return '`' . str_replace('.', '`.`', $value) . '`';

View File

@@ -231,6 +231,16 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
case dibi::FIELD_BINARY:
return "'" . sqlite_escape_string($value) . "'";
/*case dibi::FIELD_BINARY: // SQLite 3
static $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
$value = (string) $value;
$len = strlen($value);
$res = "X'";
for ($i = 0; $i < $len; $i++) {
$res .= $hex[ord($value[$i]) >> 4] . $hex[ord($value[$i]) & 15];
}
return $res . "'";*/
case dibi::IDENTIFIER:
return '[' . str_replace('.', '].[', strtr($value, '[]', ' ')) . ']';

View File

@@ -293,7 +293,7 @@ class DibiDataSource extends DibiObject implements IDataSource
return $this->connection->sql('
SELECT %n', (empty($this->cols) ? '*' : $this->cols), '
FROM %SQL', $this->sql, '
WHERE %and', $this->conds, '
%ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, '
%ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, '
%ofs %lmt', $this->offset, $this->limit
);