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

* quoteName -> delimite

* fixed mysql_connect bug
This commit is contained in:
David Grudl
2007-04-16 03:01:55 +00:00
parent 57fa5831b1
commit 166f716091
10 changed files with 34 additions and 34 deletions

View File

@@ -12,7 +12,7 @@
* @license GNU GENERAL PUBLIC LICENSE version 2 * @license GNU GENERAL PUBLIC LICENSE version 2
* @package dibi * @package dibi
* @category Database * @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', '<')) if (version_compare(PHP_VERSION , '5.0.3', '<'))
@@ -153,7 +153,7 @@ class dibi
* @return void * @return void
* @throw DibiException * @throw DibiException
*/ */
static public function connect($config, $name='1') static public function connect($config, $name=0)
{ {
// DSN string // DSN string
if (is_string($config)) if (is_string($config))

View File

@@ -63,7 +63,7 @@ class DibiMySqlDriver extends DibiDriver
$php_errormsg = ''; $php_errormsg = '';
if (empty($config['persistent'])) if (empty($config['persistent']))
$conn = @mysql_connect($host, $config['username'], $config['password']); $conn = @mysql_connect($host, $config['username'], $config['password'], TRUE);
else else
$conn = @mysql_pconnect($host, $config['username'], $config['password']); $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 return $appendQuotes
? "'" . mysql_real_escape_string($value, $this->conn) . "'" ? "'" . 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) . '`'; return '`' . str_replace('.', '`.`', $value) . '`';
} }

View File

@@ -133,7 +133,7 @@ class DibiMySqliDriver extends DibiDriver
public function escape($value, $appendQuotes = FALSE) public function escape($value, $appendQuotes=TRUE)
{ {
return $appendQuotes return $appendQuotes
? "'" . mysqli_real_escape_string($this->conn, $value) . "'" ? "'" . 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) . '`'; return '`' . str_replace('.', '`.`', $value) . '`';
} }

View File

@@ -133,7 +133,7 @@ class DibiOdbcDriver extends DibiDriver
public function escape($value, $appendQuotes = FALSE) public function escape($value, $appendQuotes=TRUE)
{ {
$value = str_replace("'", "''", $value); $value = str_replace("'", "''", $value);
return $appendQuotes return $appendQuotes
@@ -142,7 +142,7 @@ class DibiOdbcDriver extends DibiDriver
} }
public function quoteName($value) public function delimite($value)
{ {
return '[' . str_replace('.', '].[', $value) . ']'; return '[' . str_replace('.', '].[', $value) . ']';
} }

View File

@@ -112,7 +112,7 @@ class DibiPdoDriver extends DibiDriver
} }
public function escape($value, $appendQuotes = FALSE) public function escape($value, $appendQuotes=TRUE)
{ {
if (!$appendQuotes) { if (!$appendQuotes) {
trigger_error('dibi: escaping without qoutes is not supported by PDO', E_USER_WARNING); 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 // quoting is not supported by PDO
return $value; return $value;

View File

@@ -123,7 +123,7 @@ class DibiPostgreDriver extends DibiDriver
} }
public function escape($value, $appendQuotes = FALSE) public function escape($value, $appendQuotes=TRUE)
{ {
return $appendQuotes return $appendQuotes
? "'" . pg_escape_string($value) . "'" ? "'" . pg_escape_string($value) . "'"
@@ -131,7 +131,7 @@ class DibiPostgreDriver extends DibiDriver
} }
public function quoteName($value) public function delimite($value)
{ {
return $value; return $value;
} }

View File

@@ -125,7 +125,7 @@ class DibiSqliteDriver extends DibiDriver
} }
public function escape($value, $appendQuotes = FALSE) public function escape($value, $appendQuotes=TRUE)
{ {
return $appendQuotes return $appendQuotes
? "'" . sqlite_escape_string($value) . "'" ? "'" . sqlite_escape_string($value) . "'"
@@ -133,7 +133,7 @@ class DibiSqliteDriver extends DibiDriver
} }
public function quoteName($value) public function delimite($value)
{ {
return '[' . $value . ']'; return '[' . $value . ']';
} }

View File

@@ -197,16 +197,16 @@ abstract class DibiDriver
* @param bool quote string? * @param bool quote string?
* @return string escaped and optionally quoted 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 * @param string identifier
* @return string quoted identifier * @return string delimited identifier
*/ */
abstract public function quoteName($value); abstract public function delimite($value);

View File

@@ -140,7 +140,7 @@ class DibiTranslator
$pair = explode('%', $k, 2); $pair = explode('%', $k, 2);
// generate array // generate array
$vx[] = $this->quote($pair[0]) . '=' $vx[] = $this->delimite($pair[0]) . '='
. $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE); . $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
} }
return implode(', ', $vx); return implode(', ', $vx);
@@ -152,7 +152,7 @@ class DibiTranslator
$pair = explode('%', $k, 2); $pair = explode('%', $k, 2);
// generate arrays // generate arrays
$kx[] = $this->quote($pair[0]); $kx[] = $this->delimite($pair[0]);
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE); $vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
} }
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')'; return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
@@ -181,9 +181,9 @@ class DibiTranslator
switch ($modifier) { switch ($modifier) {
case 's': // string case 's': // string
return $this->driver->escape($value, TRUE); return $this->driver->escape($value);
case 'sn': // string or NULL case 'sn': // string or NULL
return $value == '' ? 'NULL' : $this->driver->escape($value, TRUE); return $value == '' ? 'NULL' : $this->driver->escape($value);
case 'b': // boolean case 'b': // boolean
return $value return $value
? $this->driver->formats['TRUE'] ? $this->driver->formats['TRUE']
@@ -202,7 +202,7 @@ class DibiTranslator
? strtotime($value) ? strtotime($value)
: $value); : $value);
case 'n': // identifier name case 'n': // identifier name
return $this->quote($value); return $this->delimite($value);
case 'sql':// preserve as SQL case 'sql':// preserve as SQL
case 'p': // back compatibility case 'p': // back compatibility
$value = (string) $value; $value = (string) $value;
@@ -250,7 +250,7 @@ class DibiTranslator
// without modifier procession // without modifier procession
if (is_string($value)) if (is_string($value))
return $this->driver->escape($value, TRUE); return $this->driver->escape($value);
if (is_int($value) || is_float($value)) if (is_int($value) || is_float($value))
return (string) $value; // something like -9E-005 is accepted by SQL return (string) $value; // something like -9E-005 is accepted by SQL
@@ -326,16 +326,16 @@ class DibiTranslator
if ($matches[1]) // SQL identifiers: `ident` if ($matches[1]) // SQL identifiers: `ident`
return $this->quote($matches[1]); return $this->delimite($matches[1]);
if ($matches[2]) // SQL identifiers: [ident] if ($matches[2]) // SQL identifiers: [ident]
return $this->quote($matches[2]); return $this->delimite($matches[2]);
if ($matches[3]) // SQL strings: '....' 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: "..." 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 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 * @param string indentifier
* @return string * @return string
*/ */
private function quote($value) private function delimite($value)
{ {
return $this->driver->quoteName( dibi::substitute($value) ); return $this->driver->delimite( dibi::substitute($value) );
} }

View File

@@ -1,4 +1,4 @@
Dibi version 0.7g Dibi version 0.7h
Revision: $WCREV$ Revision: $WCREV$
Date: $WCDATE$ Date: $WCDATE$