mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
* quoteName -> delimite
* fixed mysql_connect bug
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* @license GNU GENERAL PUBLIC LICENSE version 2
|
||||
* @package dibi
|
||||
* @category Database
|
||||
* @version 0.7g (Revision: $WCREV$, Date: $WCDATE$)
|
||||
* @version 0.7h (Revision: $WCREV$, Date: $WCDATE$)
|
||||
*/
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
|
||||
define('DIBI', '0.7g (Revision: $WCREV$, Date: $WCDATE$)');
|
||||
define('DIBI', '0.7h (Revision: $WCREV$, Date: $WCDATE$)');
|
||||
|
||||
|
||||
if (version_compare(PHP_VERSION , '5.0.3', '<'))
|
||||
@@ -153,7 +153,7 @@ class dibi
|
||||
* @return void
|
||||
* @throw DibiException
|
||||
*/
|
||||
static public function connect($config, $name='1')
|
||||
static public function connect($config, $name=0)
|
||||
{
|
||||
// DSN string
|
||||
if (is_string($config))
|
||||
|
@@ -63,7 +63,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
$php_errormsg = '';
|
||||
|
||||
if (empty($config['persistent']))
|
||||
$conn = @mysql_connect($host, $config['username'], $config['password']);
|
||||
$conn = @mysql_connect($host, $config['username'], $config['password'], TRUE);
|
||||
else
|
||||
$conn = @mysql_pconnect($host, $config['username'], $config['password']);
|
||||
|
||||
@@ -159,7 +159,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
return $appendQuotes
|
||||
? "'" . mysql_real_escape_string($value, $this->conn) . "'"
|
||||
@@ -167,7 +167,7 @@ class DibiMySqlDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||
}
|
||||
|
@@ -133,7 +133,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
return $appendQuotes
|
||||
? "'" . mysqli_real_escape_string($this->conn, $value) . "'"
|
||||
@@ -141,7 +141,7 @@ class DibiMySqliDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||
}
|
||||
|
@@ -133,7 +133,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
$value = str_replace("'", "''", $value);
|
||||
return $appendQuotes
|
||||
@@ -142,7 +142,7 @@ class DibiOdbcDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
return '[' . str_replace('.', '].[', $value) . ']';
|
||||
}
|
||||
|
@@ -112,7 +112,7 @@ class DibiPdoDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
if (!$appendQuotes) {
|
||||
trigger_error('dibi: escaping without qoutes is not supported by PDO', E_USER_WARNING);
|
||||
@@ -122,7 +122,7 @@ class DibiPdoDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
// quoting is not supported by PDO
|
||||
return $value;
|
||||
|
@@ -123,7 +123,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
return $appendQuotes
|
||||
? "'" . pg_escape_string($value) . "'"
|
||||
@@ -131,7 +131,7 @@ class DibiPostgreDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
@@ -125,7 +125,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function escape($value, $appendQuotes = FALSE)
|
||||
public function escape($value, $appendQuotes=TRUE)
|
||||
{
|
||||
return $appendQuotes
|
||||
? "'" . sqlite_escape_string($value) . "'"
|
||||
@@ -133,7 +133,7 @@ class DibiSqliteDriver extends DibiDriver
|
||||
}
|
||||
|
||||
|
||||
public function quoteName($value)
|
||||
public function delimite($value)
|
||||
{
|
||||
return '[' . $value . ']';
|
||||
}
|
||||
|
@@ -197,16 +197,16 @@ abstract class DibiDriver
|
||||
* @param bool quote string?
|
||||
* @return string escaped and optionally quoted string
|
||||
*/
|
||||
abstract public function escape($value, $appendQuotes = FALSE);
|
||||
abstract public function escape($value, $appendQuotes=TRUE);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Quotes SQL identifier (table's or column's name, etc.)
|
||||
* Delimites identifier (table's or column's name, etc.)
|
||||
* @param string identifier
|
||||
* @return string quoted identifier
|
||||
* @return string delimited identifier
|
||||
*/
|
||||
abstract public function quoteName($value);
|
||||
abstract public function delimite($value);
|
||||
|
||||
|
||||
|
||||
|
@@ -140,7 +140,7 @@ class DibiTranslator
|
||||
$pair = explode('%', $k, 2);
|
||||
|
||||
// generate array
|
||||
$vx[] = $this->quote($pair[0]) . '='
|
||||
$vx[] = $this->delimite($pair[0]) . '='
|
||||
. $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
|
||||
}
|
||||
return implode(', ', $vx);
|
||||
@@ -152,7 +152,7 @@ class DibiTranslator
|
||||
$pair = explode('%', $k, 2);
|
||||
|
||||
// generate arrays
|
||||
$kx[] = $this->quote($pair[0]);
|
||||
$kx[] = $this->delimite($pair[0]);
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
|
||||
}
|
||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||
@@ -181,9 +181,9 @@ class DibiTranslator
|
||||
|
||||
switch ($modifier) {
|
||||
case 's': // string
|
||||
return $this->driver->escape($value, TRUE);
|
||||
return $this->driver->escape($value);
|
||||
case 'sn': // string or NULL
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value, TRUE);
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value);
|
||||
case 'b': // boolean
|
||||
return $value
|
||||
? $this->driver->formats['TRUE']
|
||||
@@ -202,7 +202,7 @@ class DibiTranslator
|
||||
? strtotime($value)
|
||||
: $value);
|
||||
case 'n': // identifier name
|
||||
return $this->quote($value);
|
||||
return $this->delimite($value);
|
||||
case 'sql':// preserve as SQL
|
||||
case 'p': // back compatibility
|
||||
$value = (string) $value;
|
||||
@@ -250,7 +250,7 @@ class DibiTranslator
|
||||
|
||||
// without modifier procession
|
||||
if (is_string($value))
|
||||
return $this->driver->escape($value, TRUE);
|
||||
return $this->driver->escape($value);
|
||||
|
||||
if (is_int($value) || is_float($value))
|
||||
return (string) $value; // something like -9E-005 is accepted by SQL
|
||||
@@ -326,16 +326,16 @@ class DibiTranslator
|
||||
|
||||
|
||||
if ($matches[1]) // SQL identifiers: `ident`
|
||||
return $this->quote($matches[1]);
|
||||
return $this->delimite($matches[1]);
|
||||
|
||||
if ($matches[2]) // SQL identifiers: [ident]
|
||||
return $this->quote($matches[2]);
|
||||
return $this->delimite($matches[2]);
|
||||
|
||||
if ($matches[3]) // SQL strings: '....'
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]), TRUE);
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]));
|
||||
|
||||
if ($matches[5]) // SQL strings: "..."
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]), TRUE);
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]));
|
||||
|
||||
|
||||
if ($matches[9]) { // string quote
|
||||
@@ -349,13 +349,13 @@ class DibiTranslator
|
||||
|
||||
|
||||
/**
|
||||
* Apply substitutions to indentifier and quotes it
|
||||
* Apply substitutions to indentifier and delimites it
|
||||
* @param string indentifier
|
||||
* @return string
|
||||
*/
|
||||
private function quote($value)
|
||||
private function delimite($value)
|
||||
{
|
||||
return $this->driver->quoteName( dibi::substitute($value) );
|
||||
return $this->driver->delimite( dibi::substitute($value) );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Dibi version 0.7g
|
||||
Dibi version 0.7h
|
||||
|
||||
Revision: $WCREV$
|
||||
Date: $WCDATE$
|
||||
|
Reference in New Issue
Block a user