mirror of
https://github.com/dg/dibi.git
synced 2025-08-11 08:34:59 +02:00
- removed 'FIELD_' from dibi data types
This commit is contained in:
@@ -492,11 +492,11 @@ class DibiConnection extends DibiObject
|
||||
/**
|
||||
* Encodes data for use in an SQL statement.
|
||||
* @param string unescaped string
|
||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
||||
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||
* @return string escaped and quoted string
|
||||
* @deprecated
|
||||
*/
|
||||
public function escape($value, $type = dibi::FIELD_TEXT)
|
||||
public function escape($value, $type = dibi::TEXT)
|
||||
{
|
||||
trigger_error('Deprecated: use getDriver()->escape(...) instead.', E_USER_WARNING);
|
||||
$this->connect(); // MySQL & PDO require connection
|
||||
@@ -508,11 +508,11 @@ class DibiConnection extends DibiObject
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string value
|
||||
* @param string type (dibi::FIELD_BINARY)
|
||||
* @param string type (dibi::BINARY)
|
||||
* @return string decoded value
|
||||
* @deprecated
|
||||
*/
|
||||
public function unescape($value, $type = dibi::FIELD_BINARY)
|
||||
public function unescape($value, $type = dibi::BINARY)
|
||||
{
|
||||
trigger_error('Deprecated: use getDriver()->unescape(...) instead.', E_USER_WARNING);
|
||||
return $this->driver->unescape($value, $type);
|
||||
|
@@ -476,17 +476,17 @@ class DibiColumnInfo extends DibiObject
|
||||
public static function detectType($type)
|
||||
{
|
||||
static $patterns = array(
|
||||
'BYTE|COUNTER|SERIAL|INT|LONG' => dibi::FIELD_INTEGER,
|
||||
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FIELD_FLOAT,
|
||||
'^TIME$' => dibi::FIELD_TIME,
|
||||
'TIME' => dibi::FIELD_DATETIME, // DATETIME, TIMESTAMP
|
||||
'YEAR|DATE' => dibi::FIELD_DATE,
|
||||
'BYTEA|BLOB|BIN' => dibi::FIELD_BINARY,
|
||||
'BOOL|BIT' => dibi::FIELD_BOOL,
|
||||
'BYTE|COUNTER|SERIAL|INT|LONG' => dibi::INTEGER,
|
||||
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FLOAT,
|
||||
'^TIME$' => dibi::TIME,
|
||||
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP
|
||||
'YEAR|DATE' => dibi::DATE,
|
||||
'BYTEA|BLOB|BIN' => dibi::BINARY,
|
||||
'BOOL|BIT' => dibi::BOOL,
|
||||
);
|
||||
|
||||
if (!isset(self::$types[$type])) {
|
||||
self::$types[$type] = dibi::FIELD_TEXT;
|
||||
self::$types[$type] = dibi::TEXT;
|
||||
foreach ($patterns as $s => $val) {
|
||||
if (preg_match("#$s#i", $type)) {
|
||||
return self::$types[$type] = $val;
|
||||
|
@@ -441,7 +441,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
/**
|
||||
* Define column type.
|
||||
* @param string column
|
||||
* @param string type (use constant Dibi::FIELD_*)
|
||||
* @param string type (use constant Dibi::*)
|
||||
* @param string optional format
|
||||
* @return void
|
||||
*/
|
||||
@@ -500,24 +500,24 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case dibi::FIELD_TEXT:
|
||||
case dibi::TEXT:
|
||||
return (string) $value;
|
||||
|
||||
case dibi::FIELD_BINARY:
|
||||
case dibi::BINARY:
|
||||
return $this->getDriver()->unescape($value, $type);
|
||||
|
||||
case dibi::FIELD_INTEGER:
|
||||
case dibi::INTEGER:
|
||||
return (int) $value;
|
||||
|
||||
case dibi::FIELD_FLOAT:
|
||||
case dibi::FLOAT:
|
||||
return (float) $value;
|
||||
|
||||
case dibi::FIELD_DATE:
|
||||
case dibi::FIELD_DATETIME:
|
||||
case dibi::DATE:
|
||||
case dibi::DATETIME:
|
||||
$value = is_numeric($value) ? (int) $value : strtotime($value);
|
||||
return $format === NULL ? $value : date($format, $value);
|
||||
|
||||
case dibi::FIELD_BOOL:
|
||||
case dibi::BOOL:
|
||||
return ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||
|
||||
default:
|
||||
|
@@ -316,7 +316,7 @@ final class DibiTranslator extends DibiObject
|
||||
return $value === NULL ? 'NULL' : $this->driver->escape($value, $modifier);
|
||||
|
||||
case 'sn': // string or NULL
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value, dibi::FIELD_TEXT); // notice two equal signs
|
||||
return $value == '' ? 'NULL' : $this->driver->escape($value, dibi::TEXT); // notice two equal signs
|
||||
|
||||
case 'i': // signed int
|
||||
case 'u': // unsigned int, ignored
|
||||
@@ -383,13 +383,13 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
// without modifier procession
|
||||
if (is_string($value))
|
||||
return $this->driver->escape($value, dibi::FIELD_TEXT);
|
||||
return $this->driver->escape($value, dibi::TEXT);
|
||||
|
||||
if (is_int($value) || is_float($value))
|
||||
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
|
||||
|
||||
if (is_bool($value))
|
||||
return $this->driver->escape($value, dibi::FIELD_BOOL);
|
||||
return $this->driver->escape($value, dibi::BOOL);
|
||||
|
||||
if ($value === NULL)
|
||||
return 'NULL';
|
||||
@@ -491,10 +491,10 @@ final class DibiTranslator extends DibiObject
|
||||
return $this->delimite($matches[2]);
|
||||
|
||||
if ($matches[3]) // SQL strings: '...'
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]), dibi::FIELD_TEXT);
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]), dibi::TEXT);
|
||||
|
||||
if ($matches[5]) // SQL strings: "..."
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]), dibi::FIELD_TEXT);
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]), dibi::TEXT);
|
||||
|
||||
if ($matches[7]) { // string quote
|
||||
$this->hasError = TRUE;
|
||||
|
@@ -204,7 +204,7 @@ interface IDibiDriver
|
||||
/**
|
||||
* Encodes data for use in an SQL statement.
|
||||
* @param string value
|
||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
||||
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||
* @return string encoded value
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@@ -215,7 +215,7 @@ interface IDibiDriver
|
||||
/**
|
||||
* Decodes data from result set.
|
||||
* @param string value
|
||||
* @param string type (dibi::FIELD_BINARY)
|
||||
* @param string type (dibi::BINARY)
|
||||
* @return string decoded value
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user