mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 13:47:33 +02:00
* support for big int & big floats
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* @author David Grudl
|
||||
* @copyright Copyright (c) 2005-2007 David Grudl aka -dgx- (http://www.dgx.cz)
|
||||
* @license New BSD License
|
||||
* @version 0.8d (Revision: $WCREV$, Date: $WCDATE$)
|
||||
* @version 0.8e (Revision: $WCREV$, Date: $WCDATE$)
|
||||
* @category Database
|
||||
* @package Dibi
|
||||
* @link http://dibi.texy.info/
|
||||
@@ -87,7 +87,7 @@ class dibi
|
||||
FIELD_COUNTER = 'c', // counter or autoincrement, is integer
|
||||
|
||||
// dibi version
|
||||
VERSION = '0.8d (Revision: $WCREV$, Date: $WCDATE$)';
|
||||
VERSION = '0.8e (Revision: $WCREV$, Date: $WCDATE$)';
|
||||
|
||||
|
||||
/**
|
||||
@@ -143,7 +143,7 @@ class dibi
|
||||
/**
|
||||
* Monostate class
|
||||
*/
|
||||
private function __construct()
|
||||
final private function __construct()
|
||||
{}
|
||||
|
||||
|
||||
@@ -168,18 +168,18 @@ class dibi
|
||||
}
|
||||
|
||||
// include dibi driver
|
||||
$className = "Dibi$config[driver]Driver";
|
||||
if (!class_exists($className)) {
|
||||
$class = "Dibi$config[driver]Driver";
|
||||
if (!class_exists($class)) {
|
||||
include_once dirname(__FILE__) . "/drivers/$config[driver].php";
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new DibiException("Unable to create instance of dibi driver class '$className'.");
|
||||
if (!class_exists($class)) {
|
||||
throw new DibiException("Unable to create instance of dibi driver class '$class'.");
|
||||
}
|
||||
}
|
||||
|
||||
// create connection object and store in list
|
||||
/** like $connection = $className::connect($config); */
|
||||
self::$connection = self::$registry[$name] = new $className($config);
|
||||
/** like $connection = $class::connect($config); */
|
||||
self::$connection = self::$registry[$name] = new $class($config);
|
||||
|
||||
if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'");
|
||||
|
||||
|
@@ -261,7 +261,7 @@ abstract class DibiDriver
|
||||
* Access to undeclared property
|
||||
* @throws Exception
|
||||
*/
|
||||
private function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function &__get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
/**#@-*/
|
||||
|
@@ -412,7 +412,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
* Access to undeclared property
|
||||
* @throws Exception
|
||||
*/
|
||||
private function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function &__get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
/**#@-*/
|
||||
|
@@ -209,27 +209,43 @@ final class DibiTranslator
|
||||
switch ($modifier) {
|
||||
case 's': // string
|
||||
return $this->driver->escape($value);
|
||||
|
||||
case 'sn': // string or NULL
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value);
|
||||
|
||||
case 'b': // boolean
|
||||
return $value
|
||||
? $this->driver->formats['TRUE']
|
||||
: $this->driver->formats['FALSE'];
|
||||
|
||||
case 'i': // signed int
|
||||
case 'u': // unsigned int
|
||||
return (string) (int) $value;
|
||||
case 'u': // unsigned int, ignored
|
||||
// support for numbers - keep them unchanged
|
||||
if (is_string($value) && preg_match('#[+-]?\d+(e\d+)?$#A', $value)) {
|
||||
return $value;
|
||||
}
|
||||
return (string) (int) ($value + 0);
|
||||
|
||||
case 'f': // float
|
||||
return (string) (float) $value; // something like -9E-005 is accepted by SQL
|
||||
// support for numbers - keep them unchanged
|
||||
if (is_numeric($value) && (!is_string($value) || strpos($value, 'x') === FALSE)) {
|
||||
return $value; // something like -9E-005 is accepted by SQL, HEX values is not
|
||||
}
|
||||
return (string) ($value + 0);
|
||||
|
||||
case 'd': // date
|
||||
return date($this->driver->formats['date'], is_string($value)
|
||||
? strtotime($value)
|
||||
: $value);
|
||||
|
||||
case 't': // datetime
|
||||
return date($this->driver->formats['datetime'], is_string($value)
|
||||
? strtotime($value)
|
||||
: $value);
|
||||
|
||||
case 'n': // identifier name
|
||||
return $this->delimite($value);
|
||||
|
||||
case 'sql':// preserve as SQL
|
||||
case 'p': // back compatibility
|
||||
$value = (string) $value;
|
||||
@@ -265,9 +281,11 @@ final class DibiTranslator
|
||||
case 'v':
|
||||
$this->hasError = TRUE;
|
||||
return "**Unexpected ".gettype($value)."**";
|
||||
|
||||
case 'if':
|
||||
$this->hasError = TRUE;
|
||||
return "**The %$modifier is not allowed here**";
|
||||
|
||||
default:
|
||||
$this->hasError = TRUE;
|
||||
return "**Unknown modifier %$modifier**";
|
||||
@@ -391,7 +409,7 @@ final class DibiTranslator
|
||||
* Access to undeclared property
|
||||
* @throws Exception
|
||||
*/
|
||||
private function __get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function &__get($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __set($name, $value) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
|
||||
/**#@-*/
|
||||
|
@@ -69,3 +69,13 @@ dibi::test("UPDATE [mytable] SET", $array4, " WHERE [id]=%i", $n);
|
||||
|
||||
// array with modifier %a - assoc
|
||||
dibi::test("UPDATE [mytable] SET%a", $array4, " WHERE [id]=%i", $n);
|
||||
|
||||
|
||||
// long numbers
|
||||
dibi::test("SELECT %i", '-123456789123456789123456789');
|
||||
|
||||
// long float numbers
|
||||
dibi::test("SELECT %f", '-.12345678912345678912345678e10');
|
||||
|
||||
// hex numbers
|
||||
dibi::test("SELECT %i", '0x11');
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Dibi version 0.8d
|
||||
Dibi version 0.8e
|
||||
|
||||
Revision: $WCREV$
|
||||
Date: $WCDATE$
|
||||
|
Reference in New Issue
Block a user