mirror of
https://github.com/dg/dibi.git
synced 2025-08-16 11:04:43 +02:00
prefix & substitution support (0.6c)
This commit is contained in:
@@ -4,4 +4,3 @@ complete phpdoc
|
||||
|
||||
PostgreSql driver
|
||||
|
||||
table prefix suppor
|
@@ -14,11 +14,11 @@
|
||||
* @license GNU GENERAL PUBLIC LICENSE v2
|
||||
* @package dibi
|
||||
* @category Database
|
||||
* @version 0.6b $Revision$ $Date$
|
||||
* @version 0.6c $Revision$ $Date$
|
||||
*/
|
||||
|
||||
|
||||
define('DIBI', 'Version 0.6b $Revision$');
|
||||
define('DIBI', 'Version 0.6c $Revision$');
|
||||
|
||||
|
||||
if (version_compare(PHP_VERSION , '5.0.3', '<'))
|
||||
@@ -328,9 +328,7 @@ class dibi
|
||||
*/
|
||||
static public function insertId()
|
||||
{
|
||||
if (!self::$conn) return FALSE; // is connected?
|
||||
|
||||
return self::$conn->insertId();
|
||||
return self::$conn ? self::$conn->insertId() : FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,9 +340,19 @@ class dibi
|
||||
*/
|
||||
static public function affectedRows()
|
||||
{
|
||||
if (!self::$conn) return FALSE; // is connected?
|
||||
return self::$conn ? self::$conn->affectedRows() : FALSE;
|
||||
}
|
||||
|
||||
return self::$conn->affectedRows();
|
||||
|
||||
/**
|
||||
* Monostate for DibiDriver::addSubst()
|
||||
* @param string
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
static public function addSubst($expr, $subst)
|
||||
{
|
||||
return self::$conn ? self::$conn->addSubst($expr, $subst) : FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -165,7 +165,7 @@ class DibiMySqlDriver extends DibiDriver {
|
||||
|
||||
public function quoteName($value)
|
||||
{
|
||||
return '`' . strtr($value, array('.' => '`.`')) . '`';
|
||||
return '`' . strtr( $this->applySubsts($value), array('.' => '`.`')) . '`';
|
||||
}
|
||||
|
||||
|
||||
|
@@ -143,7 +143,7 @@ class DibiMySqliDriver extends DibiDriver {
|
||||
|
||||
public function quoteName($value)
|
||||
{
|
||||
return '`' . strtr($value, array('.' => '`.`')) . '`';
|
||||
return '`' . strtr( $this->applySubsts($value), array('.' => '`.`')) . '`';
|
||||
}
|
||||
|
||||
|
||||
|
@@ -138,7 +138,7 @@ class DibiOdbcDriver extends DibiDriver {
|
||||
|
||||
public function quoteName($value)
|
||||
{
|
||||
return '[' . strtr($value, array('.' => '].[')) . ']';
|
||||
return '[' . strtr( $this->applySubsts($value), array('.' => '].[')) . ']';
|
||||
}
|
||||
|
||||
|
||||
|
@@ -133,7 +133,7 @@ class DibiSqliteDriver extends DibiDriver {
|
||||
|
||||
public function quoteName($value)
|
||||
{
|
||||
return $value;
|
||||
return $this->applySubsts($value);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -34,6 +34,13 @@ abstract class DibiDriver
|
||||
protected
|
||||
$config;
|
||||
|
||||
/**
|
||||
* Substitutions for identifiers
|
||||
* @var array
|
||||
*/
|
||||
protected
|
||||
$substs = array();
|
||||
|
||||
/**
|
||||
* Describes how convert some datatypes to SQL command
|
||||
* @var array
|
||||
@@ -153,6 +160,45 @@ abstract class DibiDriver
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new substitution pair for indentifiers
|
||||
* @param string from
|
||||
* @param string to
|
||||
* @return void
|
||||
*/
|
||||
public function addSubst($expr, $subst)
|
||||
{
|
||||
$this->substs[':'.$expr.':'] = $subst;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove substitution pair
|
||||
* @param string from
|
||||
* @return void
|
||||
*/
|
||||
public function removeSubst($expr)
|
||||
{
|
||||
unset($this->substs[':'.$expr.':']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply substitutions to indentifier
|
||||
* @param string indentifier
|
||||
* @return string
|
||||
*/
|
||||
protected function applySubsts($value)
|
||||
{
|
||||
// apply substitutions
|
||||
if ($this->substs && (strpos($value, ':') !== FALSE))
|
||||
return strtr($value, $this->substs);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // class DibiDriver
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user