mirror of
https://github.com/dg/dibi.git
synced 2025-08-15 02:25:10 +02:00
* fixed identifier delimitation in DibiPostgreDriver (table.col -> table."col")
* better SQL syntax highlighting * removed addslashes from DibiPostgreDriver
This commit is contained in:
@@ -543,9 +543,9 @@ class dibi extends NClass
|
|||||||
static $keywords1 = 'SELECT|UPDATE|INSERT(?:\s+INTO)|REPLACE(?:\s+INTO)|DELETE|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN';
|
static $keywords1 = 'SELECT|UPDATE|INSERT(?:\s+INTO)|REPLACE(?:\s+INTO)|DELETE|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN';
|
||||||
|
|
||||||
// insert new lines
|
// insert new lines
|
||||||
$sql = preg_replace("#\\b(?:$keywords1)\\b#i", "\n\$0", $sql);
|
$sql = ' ' . $sql;
|
||||||
|
$sql = preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql);
|
||||||
|
|
||||||
$sql = trim($sql);
|
|
||||||
// reduce spaces
|
// reduce spaces
|
||||||
$sql = preg_replace('# {2,}#', ' ', $sql);
|
$sql = preg_replace('# {2,}#', ' ', $sql);
|
||||||
|
|
||||||
@@ -554,7 +554,8 @@ class dibi extends NClass
|
|||||||
$sql = preg_replace("#\n{2,}#", "\n", $sql);
|
$sql = preg_replace("#\n{2,}#", "\n", $sql);
|
||||||
|
|
||||||
// syntax highlight
|
// syntax highlight
|
||||||
$sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|\\b($keywords1)\\b|\\b($keywords2)\\b#i", array('dibi', 'highlightCallback'), $sql);
|
$sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(])($keywords2)(?=[\\s,)])#i", array('dibi', 'highlightCallback'), $sql);
|
||||||
|
$sql = trim($sql);
|
||||||
echo '<pre class="dump">', $sql, "</pre>\n";
|
echo '<pre class="dump">', $sql, "</pre>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -344,8 +344,7 @@ class DibiMySqlDriver extends NObject implements DibiDriverInterface
|
|||||||
$meta = array();
|
$meta = array();
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
// items 'name' and 'table' are required
|
// items 'name' and 'table' are required
|
||||||
$info = (array) mysql_fetch_field($this->resultset, $i);
|
$meta[] = (array) mysql_fetch_field($this->resultset, $i);
|
||||||
$meta[] = $info;
|
|
||||||
}
|
}
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
@@ -320,8 +320,7 @@ class DibiMySqliDriver extends NObject implements DibiDriverInterface
|
|||||||
$meta = array();
|
$meta = array();
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
// items 'name' and 'table' are required
|
// items 'name' and 'table' are required
|
||||||
$info = (array) mysqli_fetch_field_direct($this->resultset, $i);
|
$meta[] = (array) mysqli_fetch_field_direct($this->resultset, $i);
|
||||||
$meta[] = $info;
|
|
||||||
}
|
}
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
@@ -52,9 +52,9 @@ class DibiPostgreDriver extends NObject implements DibiDriverInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape method
|
* Escape method
|
||||||
* @var int
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $escMethod;
|
private $escMethod = FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -66,8 +66,6 @@ class DibiPostgreDriver extends NObject implements DibiDriverInterface
|
|||||||
if (!extension_loaded('pgsql')) {
|
if (!extension_loaded('pgsql')) {
|
||||||
throw new DibiDriverException("PHP extension 'pgsql' is not loaded");
|
throw new DibiDriverException("PHP extension 'pgsql' is not loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->escMethod = version_compare(PHP_VERSION , '5.2.0', '>=') ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,7 +104,7 @@ class DibiPostgreDriver extends NObject implements DibiDriverInterface
|
|||||||
DibiDriverException::restore();
|
DibiDriverException::restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($config['escapefix'])) $this->escMethod = -1;
|
$this->escMethod = version_compare(PHP_VERSION , '5.2.0', '>=');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -226,11 +224,17 @@ class DibiPostgreDriver extends NObject implements DibiDriverInterface
|
|||||||
public function format($value, $type)
|
public function format($value, $type)
|
||||||
{
|
{
|
||||||
if ($type === dibi::FIELD_TEXT) {
|
if ($type === dibi::FIELD_TEXT) {
|
||||||
if ($this->escMethod === -1) return "'" . addSlashes($value) . "'";
|
if ($this->escMethod) return "'" . pg_escape_string($this->connection, $value) . "'";
|
||||||
if ($this->escMethod === 1 && $this->connection) return "'" . pg_escape_string($this->connection, $value) . "'";
|
|
||||||
return "'" . pg_escape_string($value) . "'";
|
return "'" . pg_escape_string($value) . "'";
|
||||||
}
|
}
|
||||||
if ($type === dibi::IDENTIFIER) return '"' . str_replace('.', '"."', str_replace('"', '""', $value)) . '"';
|
|
||||||
|
if ($type === 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 ($type === dibi::FIELD_BOOL) return $value ? 'TRUE' : 'FALSE';
|
if ($type === dibi::FIELD_BOOL) return $value ? 'TRUE' : 'FALSE';
|
||||||
if ($type === dibi::FIELD_DATE) return date("'Y-m-d'", $value);
|
if ($type === dibi::FIELD_DATE) return date("'Y-m-d'", $value);
|
||||||
if ($type === dibi::FIELD_DATETIME) return date("'Y-m-d H:i:s'", $value);
|
if ($type === dibi::FIELD_DATETIME) return date("'Y-m-d H:i:s'", $value);
|
||||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user