mirror of
https://github.com/dg/dibi.git
synced 2025-07-31 19:30:30 +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
|
||||
* @throws DibiException
|
||||
*/
|
||||
public static function connect($config, $name = 0)
|
||||
public static function connect($config = 'driver=mysql', $name = 0)
|
||||
{
|
||||
// DSN string
|
||||
if (is_string($config)) {
|
||||
@@ -192,7 +192,7 @@ class dibi
|
||||
/** like $connection = $class::connect($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;
|
||||
}
|
||||
@@ -460,26 +460,28 @@ class dibi
|
||||
/**
|
||||
* Remove substitution pair
|
||||
*
|
||||
* @param string from
|
||||
* @param mixed from or TRUE
|
||||
* @return void
|
||||
*/
|
||||
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 string
|
||||
* @return array
|
||||
*/
|
||||
public static function substitute($s)
|
||||
public static function getSubst()
|
||||
{
|
||||
if (strpos($s, ':') === FALSE) return $s;
|
||||
return strtr($s, self::$substs);
|
||||
return self::$substs;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -116,8 +116,8 @@ final class DibiTranslator
|
||||
// TODO: check !!!
|
||||
$sql = preg_replace('#\x00.*?\x00#s', '', $sql);
|
||||
|
||||
// error handling
|
||||
if ($this->hasError) {
|
||||
// TODO: do it better, remove dibi::$...
|
||||
if (dibi::$logFile) { // log to file
|
||||
dibi::log(
|
||||
"ERROR: SQL generate error"
|
||||
@@ -402,7 +402,10 @@ final class DibiTranslator
|
||||
*/
|
||||
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