mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 20:57:36 +02:00
- dibi::substitute -> dibi::getSubst
- dibi:removeSubst(TRUE) removes all substitutes
This commit is contained in:
@@ -166,7 +166,7 @@ class dibi
|
|||||||
* @return DibiDriver
|
* @return DibiDriver
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
public static function connect($config, $name = 0)
|
public static function connect($config = 'driver=mysql', $name = 0)
|
||||||
{
|
{
|
||||||
// DSN string
|
// DSN string
|
||||||
if (is_string($config)) {
|
if (is_string($config)) {
|
||||||
@@ -192,7 +192,7 @@ class dibi
|
|||||||
/** like $connection = $class::connect($config); */
|
/** like $connection = $class::connect($config); */
|
||||||
self::$connection = self::$registry[$name] = new $class($config);
|
self::$connection = self::$registry[$name] = new $class($config);
|
||||||
|
|
||||||
if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'");
|
if (self::$logAll) self::log("OK: connected to DB '$config[driver]'");
|
||||||
|
|
||||||
return self::$connection;
|
return self::$connection;
|
||||||
}
|
}
|
||||||
@@ -460,26 +460,28 @@ class dibi
|
|||||||
/**
|
/**
|
||||||
* Remove substitution pair
|
* Remove substitution pair
|
||||||
*
|
*
|
||||||
* @param string from
|
* @param mixed from or TRUE
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function removeSubst($expr)
|
public static function removeSubst($expr)
|
||||||
{
|
{
|
||||||
unset(self::$substs[':'.$expr.':']);
|
if ($expr === TRUE) {
|
||||||
|
self::$substs = array();
|
||||||
|
} else {
|
||||||
|
unset(self::$substs[':'.$expr.':']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process substitutions in string
|
* Returns substitution pairs
|
||||||
*
|
*
|
||||||
* @param string
|
* @return array
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public static function substitute($s)
|
public static function getSubst()
|
||||||
{
|
{
|
||||||
if (strpos($s, ':') === FALSE) return $s;
|
return self::$substs;
|
||||||
return strtr($s, self::$substs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -116,8 +116,8 @@ final class DibiTranslator
|
|||||||
// TODO: check !!!
|
// TODO: check !!!
|
||||||
$sql = preg_replace('#\x00.*?\x00#s', '', $sql);
|
$sql = preg_replace('#\x00.*?\x00#s', '', $sql);
|
||||||
|
|
||||||
// error handling
|
|
||||||
if ($this->hasError) {
|
if ($this->hasError) {
|
||||||
|
// TODO: do it better, remove dibi::$...
|
||||||
if (dibi::$logFile) { // log to file
|
if (dibi::$logFile) { // log to file
|
||||||
dibi::log(
|
dibi::log(
|
||||||
"ERROR: SQL generate error"
|
"ERROR: SQL generate error"
|
||||||
@@ -402,7 +402,10 @@ final class DibiTranslator
|
|||||||
*/
|
*/
|
||||||
private function delimite($value)
|
private function delimite($value)
|
||||||
{
|
{
|
||||||
return $this->driver->delimite( dibi::substitute($value) );
|
if (strpos($value, ':') !== FALSE) {
|
||||||
|
$value = strtr($value, dibi::getSubst());
|
||||||
|
}
|
||||||
|
return $this->driver->delimite($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user