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

* support for big int & big floats

This commit is contained in:
David Grudl
2007-08-27 22:38:14 +00:00
parent 7f995a558b
commit 5243122e6a
6 changed files with 44 additions and 16 deletions

View File

@@ -14,7 +14,7 @@
* @author David Grudl * @author David Grudl
* @copyright Copyright (c) 2005-2007 David Grudl aka -dgx- (http://www.dgx.cz) * @copyright Copyright (c) 2005-2007 David Grudl aka -dgx- (http://www.dgx.cz)
* @license New BSD License * @license New BSD License
* @version 0.8d (Revision: $WCREV$, Date: $WCDATE$) * @version 0.8e (Revision: $WCREV$, Date: $WCDATE$)
* @category Database * @category Database
* @package Dibi * @package Dibi
* @link http://dibi.texy.info/ * @link http://dibi.texy.info/
@@ -87,7 +87,7 @@ class dibi
FIELD_COUNTER = 'c', // counter or autoincrement, is integer FIELD_COUNTER = 'c', // counter or autoincrement, is integer
// dibi version // dibi version
VERSION = '0.8d (Revision: $WCREV$, Date: $WCDATE$)'; VERSION = '0.8e (Revision: $WCREV$, Date: $WCDATE$)';
/** /**
@@ -143,7 +143,7 @@ class dibi
/** /**
* Monostate class * Monostate class
*/ */
private function __construct() final private function __construct()
{} {}
@@ -168,18 +168,18 @@ class dibi
} }
// include dibi driver // include dibi driver
$className = "Dibi$config[driver]Driver"; $class = "Dibi$config[driver]Driver";
if (!class_exists($className)) { if (!class_exists($class)) {
include_once dirname(__FILE__) . "/drivers/$config[driver].php"; include_once dirname(__FILE__) . "/drivers/$config[driver].php";
if (!class_exists($className)) { if (!class_exists($class)) {
throw new DibiException("Unable to create instance of dibi driver class '$className'."); throw new DibiException("Unable to create instance of dibi driver class '$class'.");
} }
} }
// create connection object and store in list // create connection object and store in list
/** like $connection = $className::connect($config); */ /** like $connection = $class::connect($config); */
self::$connection = self::$registry[$name] = new $className($config); self::$connection = self::$registry[$name] = new $class($config);
if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'"); if (dibi::$logAll) dibi::log("OK: connected to DB '$config[driver]'");

View File

@@ -261,7 +261,7 @@ abstract class DibiDriver
* Access to undeclared property * Access to undeclared property
* @throws Exception * @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 __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"); } private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
/**#@-*/ /**#@-*/

View File

@@ -412,7 +412,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
* Access to undeclared property * Access to undeclared property
* @throws Exception * @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 __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"); } private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
/**#@-*/ /**#@-*/

View File

@@ -209,27 +209,43 @@ final class DibiTranslator
switch ($modifier) { switch ($modifier) {
case 's': // string case 's': // string
return $this->driver->escape($value); return $this->driver->escape($value);
case 'sn': // string or NULL case 'sn': // string or NULL
return $value == '' ? 'NULL' : $this->driver->escape($value); 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']
: $this->driver->formats['FALSE']; : $this->driver->formats['FALSE'];
case 'i': // signed int case 'i': // signed int
case 'u': // unsigned int case 'u': // unsigned int, ignored
return (string) (int) $value; // 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 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 case 'd': // date
return date($this->driver->formats['date'], is_string($value) return date($this->driver->formats['date'], is_string($value)
? strtotime($value) ? strtotime($value)
: $value); : $value);
case 't': // datetime case 't': // datetime
return date($this->driver->formats['datetime'], is_string($value) return date($this->driver->formats['datetime'], is_string($value)
? strtotime($value) ? strtotime($value)
: $value); : $value);
case 'n': // identifier name case 'n': // identifier name
return $this->delimite($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;
@@ -265,9 +281,11 @@ final class DibiTranslator
case 'v': case 'v':
$this->hasError = TRUE; $this->hasError = TRUE;
return "**Unexpected ".gettype($value)."**"; return "**Unexpected ".gettype($value)."**";
case 'if': case 'if':
$this->hasError = TRUE; $this->hasError = TRUE;
return "**The %$modifier is not allowed here**"; return "**The %$modifier is not allowed here**";
default: default:
$this->hasError = TRUE; $this->hasError = TRUE;
return "**Unknown modifier %$modifier**"; return "**Unknown modifier %$modifier**";
@@ -391,7 +409,7 @@ final class DibiTranslator
* Access to undeclared property * Access to undeclared property
* @throws Exception * @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 __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"); } private function __unset($name) { throw new Exception("Access to undeclared property: " . get_class($this) . "::$$name"); }
/**#@-*/ /**#@-*/

View File

@@ -69,3 +69,13 @@ dibi::test("UPDATE [mytable] SET", $array4, " WHERE [id]=%i", $n);
// array with modifier %a - assoc // array with modifier %a - assoc
dibi::test("UPDATE [mytable] SET%a", $array4, " WHERE [id]=%i", $n); 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');

View File

@@ -1,4 +1,4 @@
Dibi version 0.8d Dibi version 0.8e
Revision: $WCREV$ Revision: $WCREV$
Date: $WCDATE$ Date: $WCDATE$