mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 06:07:39 +02:00
- removed 'FIELD_' from dibi data types
This commit is contained in:
@@ -92,22 +92,31 @@ require_once dirname(__FILE__) . '/libs/DibiProfiler.php';
|
|||||||
class dibi
|
class dibi
|
||||||
{
|
{
|
||||||
/**#@+
|
/**#@+
|
||||||
* dibi column type
|
* dibi data type
|
||||||
*/
|
*/
|
||||||
const FIELD_TEXT = 's'; // as 'string'
|
const TEXT = 's'; // as 'string'
|
||||||
const FIELD_BINARY = 'bin';
|
const BINARY = 'bin';
|
||||||
const FIELD_BOOL = 'b';
|
const BOOL = 'b';
|
||||||
const FIELD_INTEGER = 'i';
|
const INTEGER = 'i';
|
||||||
const FIELD_FLOAT = 'f';
|
const FLOAT = 'f';
|
||||||
const FIELD_DATE = 'd';
|
const DATE = 'd';
|
||||||
const FIELD_DATETIME = 't';
|
const DATETIME = 't';
|
||||||
const FIELD_TIME = 't';
|
const TIME = 't';
|
||||||
|
const IDENTIFIER = 'n';
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
/**
|
/**#@+
|
||||||
* Identifier type
|
* @deprecated column types
|
||||||
*/
|
*/
|
||||||
const IDENTIFIER = 'n';
|
const FIELD_TEXT = self::TEXT;
|
||||||
|
const FIELD_BINARY = self::BINARY;
|
||||||
|
const FIELD_BOOL = self::BOOL;
|
||||||
|
const FIELD_INTEGER = self::INTEGER;
|
||||||
|
const FIELD_FLOAT = self::FLOAT;
|
||||||
|
const FIELD_DATE = self::DATE;
|
||||||
|
const FIELD_DATETIME = self::DATETIME;
|
||||||
|
const FIELD_TIME = self::TIME;
|
||||||
|
/**#@-*/
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* dibi version
|
* dibi version
|
||||||
@@ -579,7 +588,7 @@ class dibi
|
|||||||
} else {
|
} else {
|
||||||
$time = strtotime($time); // try convert to timestamp
|
$time = strtotime($time); // try convert to timestamp
|
||||||
}
|
}
|
||||||
return new DibiVariable($time, dibi::FIELD_DATETIME);
|
return new DibiVariable($time, dibi::DATETIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -592,7 +601,7 @@ class dibi
|
|||||||
public static function date($date = NULL)
|
public static function date($date = NULL)
|
||||||
{
|
{
|
||||||
$var = self::datetime($date);
|
$var = self::datetime($date);
|
||||||
$var->modifier = dibi::FIELD_DATE;
|
$var->modifier = dibi::DATE;
|
||||||
return $var;
|
return $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -201,15 +201,15 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "'" . str_replace("'", "''", $value) . "'";
|
return "'" . str_replace("'", "''", $value) . "'";
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
@@ -217,13 +217,13 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver
|
|||||||
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
||||||
return '[' . str_replace('.', '].[', $value) . ']';
|
return '[' . str_replace('.', '].[', $value) . ']';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? -1 : 0;
|
return $value ? -1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -236,7 +236,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -201,15 +201,15 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "'" . str_replace("'", "''", $value) . "'";
|
return "'" . str_replace("'", "''", $value) . "'";
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
@@ -217,13 +217,13 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver
|
|||||||
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
||||||
return '[' . str_replace('.', '].[', $value) . ']';
|
return '[' . str_replace('.', '].[', $value) . ']';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? -1 : 0;
|
return $value ? -1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -236,7 +236,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -273,17 +273,17 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
return "'" . mysql_real_escape_string($value, $this->connection) . "'";
|
return "'" . mysql_real_escape_string($value, $this->connection) . "'";
|
||||||
|
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
|
return "_binary'" . mysql_real_escape_string($value, $this->connection) . "'";
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
@@ -291,13 +291,13 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
|
|||||||
$value = str_replace('`', '``', $value);
|
$value = str_replace('`', '``', $value);
|
||||||
return '`' . str_replace('.', '`.`', $value) . '`';
|
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? 1 : 0;
|
return $value ? 1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -310,7 +310,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -257,30 +257,30 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
return "'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
return "'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
||||||
|
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "_binary'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
return "_binary'" . mysqli_real_escape_string($this->connection, $value) . "'";
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
$value = str_replace('`', '``', $value);
|
$value = str_replace('`', '``', $value);
|
||||||
return '`' . str_replace('.', '`.`', $value) . '`';
|
return '`' . str_replace('.', '`.`', $value) . '`';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? 1 : 0;
|
return $value ? 1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -293,7 +293,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@@ -461,7 +461,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function getColumns($table)
|
public function getColumns($table)
|
||||||
{
|
{
|
||||||
/*$table = $this->escape($table, dibi::FIELD_TEXT);
|
/*$table = $this->escape($table, dibi::TEXT);
|
||||||
$this->query("
|
$this->query("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
@@ -494,7 +494,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function getIndexes($table)
|
public function getIndexes($table)
|
||||||
{
|
{
|
||||||
/*$table = $this->escape($table, dibi::FIELD_TEXT);
|
/*$table = $this->escape($table, dibi::TEXT);
|
||||||
$this->query("
|
$this->query("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||||
|
@@ -208,28 +208,28 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "'" . str_replace("'", "''", $value) . "'";
|
return "'" . str_replace("'", "''", $value) . "'";
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
$value = str_replace(array('[', ']'), array('[[', ']]'), $value);
|
||||||
return '[' . str_replace('.', '].[', $value) . ']';
|
return '[' . str_replace('.', '].[', $value) . ']';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? -1 : 0;
|
return $value ? -1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("#m/d/Y#", $value);
|
return date("#m/d/Y#", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("#m/d/Y H:i:s#", $value);
|
return date("#m/d/Y H:i:s#", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -242,7 +242,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -208,15 +208,15 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "'" . str_replace("'", "''", $value) . "'"; // TODO: not tested
|
return "'" . str_replace("'", "''", $value) . "'"; // TODO: not tested
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
@@ -224,13 +224,13 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
|
|||||||
$value = str_replace('"', '""', $value);
|
$value = str_replace('"', '""', $value);
|
||||||
return '"' . str_replace('.', '"."', $value) . '"';
|
return '"' . str_replace('.', '"."', $value) . '"';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? 1 : 0;
|
return $value ? 1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("U", $value);
|
return date("U", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("U", $value);
|
return date("U", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -243,7 +243,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -226,17 +226,17 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
return $this->connection->quote($value, PDO::PARAM_STR);
|
return $this->connection->quote($value, PDO::PARAM_STR);
|
||||||
|
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return $this->connection->quote($value, PDO::PARAM_LOB);
|
return $this->connection->quote($value, PDO::PARAM_LOB);
|
||||||
|
|
||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
@@ -266,13 +266,13 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $this->connection->quote($value, PDO::PARAM_BOOL);
|
return $this->connection->quote($value, PDO::PARAM_BOOL);
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -285,7 +285,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -233,21 +233,21 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
if ($this->escMethod) {
|
if ($this->escMethod) {
|
||||||
return "'" . pg_escape_string($this->connection, $value) . "'";
|
return "'" . pg_escape_string($this->connection, $value) . "'";
|
||||||
} else {
|
} else {
|
||||||
return "'" . pg_escape_string($value) . "'";
|
return "'" . pg_escape_string($value) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
if ($this->escMethod) {
|
if ($this->escMethod) {
|
||||||
return "'" . pg_escape_bytea($this->connection, $value) . "'";
|
return "'" . pg_escape_bytea($this->connection, $value) . "'";
|
||||||
} else {
|
} else {
|
||||||
@@ -264,13 +264,13 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
|
|||||||
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
|
return substr($value, 0, $a) . '."' . str_replace('"', '""', substr($value, $a + 1)) . '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? 'TRUE' : 'FALSE';
|
return $value ? 'TRUE' : 'FALSE';
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date("'Y-m-d'", $value);
|
return date("'Y-m-d'", $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date("'Y-m-d H:i:s'", $value);
|
return date("'Y-m-d H:i:s'", $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -283,14 +283,14 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function unescape($value, $type)
|
public function unescape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return pg_unescape_bytea($value);
|
return pg_unescape_bytea($value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -438,7 +438,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function getColumns($table)
|
public function getColumns($table)
|
||||||
{
|
{
|
||||||
$_table = $this->escape($table, dibi::FIELD_TEXT);
|
$_table = $this->escape($table, dibi::TEXT);
|
||||||
$this->query("
|
$this->query("
|
||||||
SELECT indkey
|
SELECT indkey
|
||||||
FROM pg_class
|
FROM pg_class
|
||||||
@@ -480,7 +480,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver
|
|||||||
*/
|
*/
|
||||||
public function getIndexes($table)
|
public function getIndexes($table)
|
||||||
{
|
{
|
||||||
$_table = $this->escape($table, dibi::FIELD_TEXT);
|
$_table = $this->escape($table, dibi::TEXT);
|
||||||
$this->query("
|
$this->query("
|
||||||
SELECT ordinal_position, column_name
|
SELECT ordinal_position, column_name
|
||||||
FROM information_schema.columns
|
FROM information_schema.columns
|
||||||
|
@@ -220,18 +220,18 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function escape($value, $type)
|
public function escape($value, $type)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return "'" . sqlite_escape_string($value) . "'";
|
return "'" . sqlite_escape_string($value) . "'";
|
||||||
|
|
||||||
/*case dibi::FIELD_BINARY: // SQLite 3
|
/*case dibi::BINARY: // SQLite 3
|
||||||
static $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
|
static $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
$len = strlen($value);
|
$len = strlen($value);
|
||||||
@@ -244,13 +244,13 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
|
|||||||
case dibi::IDENTIFIER:
|
case dibi::IDENTIFIER:
|
||||||
return '[' . str_replace('.', '].[', strtr($value, '[]', ' ')) . ']';
|
return '[' . str_replace('.', '].[', strtr($value, '[]', ' ')) . ']';
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return $value ? 1 : 0;
|
return $value ? 1 : 0;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
return date($this->fmtDate, $value);
|
return date($this->fmtDate, $value);
|
||||||
|
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
return date($this->fmtDateTime, $value);
|
return date($this->fmtDateTime, $value);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -263,7 +263,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -492,11 +492,11 @@ class DibiConnection extends DibiObject
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string unescaped string
|
* @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
|
* @return string escaped and quoted string
|
||||||
* @deprecated
|
* @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);
|
trigger_error('Deprecated: use getDriver()->escape(...) instead.', E_USER_WARNING);
|
||||||
$this->connect(); // MySQL & PDO require connection
|
$this->connect(); // MySQL & PDO require connection
|
||||||
@@ -508,11 +508,11 @@ class DibiConnection extends DibiObject
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @deprecated
|
* @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);
|
trigger_error('Deprecated: use getDriver()->unescape(...) instead.', E_USER_WARNING);
|
||||||
return $this->driver->unescape($value, $type);
|
return $this->driver->unescape($value, $type);
|
||||||
|
@@ -476,17 +476,17 @@ class DibiColumnInfo extends DibiObject
|
|||||||
public static function detectType($type)
|
public static function detectType($type)
|
||||||
{
|
{
|
||||||
static $patterns = array(
|
static $patterns = array(
|
||||||
'BYTE|COUNTER|SERIAL|INT|LONG' => dibi::FIELD_INTEGER,
|
'BYTE|COUNTER|SERIAL|INT|LONG' => dibi::INTEGER,
|
||||||
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FIELD_FLOAT,
|
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FLOAT,
|
||||||
'^TIME$' => dibi::FIELD_TIME,
|
'^TIME$' => dibi::TIME,
|
||||||
'TIME' => dibi::FIELD_DATETIME, // DATETIME, TIMESTAMP
|
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP
|
||||||
'YEAR|DATE' => dibi::FIELD_DATE,
|
'YEAR|DATE' => dibi::DATE,
|
||||||
'BYTEA|BLOB|BIN' => dibi::FIELD_BINARY,
|
'BYTEA|BLOB|BIN' => dibi::BINARY,
|
||||||
'BOOL|BIT' => dibi::FIELD_BOOL,
|
'BOOL|BIT' => dibi::BOOL,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isset(self::$types[$type])) {
|
if (!isset(self::$types[$type])) {
|
||||||
self::$types[$type] = dibi::FIELD_TEXT;
|
self::$types[$type] = dibi::TEXT;
|
||||||
foreach ($patterns as $s => $val) {
|
foreach ($patterns as $s => $val) {
|
||||||
if (preg_match("#$s#i", $type)) {
|
if (preg_match("#$s#i", $type)) {
|
||||||
return self::$types[$type] = $val;
|
return self::$types[$type] = $val;
|
||||||
|
@@ -441,7 +441,7 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
/**
|
/**
|
||||||
* Define column type.
|
* Define column type.
|
||||||
* @param string column
|
* @param string column
|
||||||
* @param string type (use constant Dibi::FIELD_*)
|
* @param string type (use constant Dibi::*)
|
||||||
* @param string optional format
|
* @param string optional format
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -500,24 +500,24 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case dibi::FIELD_TEXT:
|
case dibi::TEXT:
|
||||||
return (string) $value;
|
return (string) $value;
|
||||||
|
|
||||||
case dibi::FIELD_BINARY:
|
case dibi::BINARY:
|
||||||
return $this->getDriver()->unescape($value, $type);
|
return $this->getDriver()->unescape($value, $type);
|
||||||
|
|
||||||
case dibi::FIELD_INTEGER:
|
case dibi::INTEGER:
|
||||||
return (int) $value;
|
return (int) $value;
|
||||||
|
|
||||||
case dibi::FIELD_FLOAT:
|
case dibi::FLOAT:
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
|
|
||||||
case dibi::FIELD_DATE:
|
case dibi::DATE:
|
||||||
case dibi::FIELD_DATETIME:
|
case dibi::DATETIME:
|
||||||
$value = is_numeric($value) ? (int) $value : strtotime($value);
|
$value = is_numeric($value) ? (int) $value : strtotime($value);
|
||||||
return $format === NULL ? $value : date($format, $value);
|
return $format === NULL ? $value : date($format, $value);
|
||||||
|
|
||||||
case dibi::FIELD_BOOL:
|
case dibi::BOOL:
|
||||||
return ((bool) $value) && $value !== 'f' && $value !== 'F';
|
return ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@@ -316,7 +316,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
return $value === NULL ? 'NULL' : $this->driver->escape($value, $modifier);
|
return $value === NULL ? 'NULL' : $this->driver->escape($value, $modifier);
|
||||||
|
|
||||||
case 'sn': // string or NULL
|
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 'i': // signed int
|
||||||
case 'u': // unsigned int, ignored
|
case 'u': // unsigned int, ignored
|
||||||
@@ -383,13 +383,13 @@ final class DibiTranslator extends DibiObject
|
|||||||
|
|
||||||
// without modifier procession
|
// without modifier procession
|
||||||
if (is_string($value))
|
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))
|
if (is_int($value) || is_float($value))
|
||||||
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
|
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
|
||||||
|
|
||||||
if (is_bool($value))
|
if (is_bool($value))
|
||||||
return $this->driver->escape($value, dibi::FIELD_BOOL);
|
return $this->driver->escape($value, dibi::BOOL);
|
||||||
|
|
||||||
if ($value === NULL)
|
if ($value === NULL)
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
@@ -491,10 +491,10 @@ final class DibiTranslator extends DibiObject
|
|||||||
return $this->delimite($matches[2]);
|
return $this->delimite($matches[2]);
|
||||||
|
|
||||||
if ($matches[3]) // SQL strings: '...'
|
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: "..."
|
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
|
if ($matches[7]) { // string quote
|
||||||
$this->hasError = TRUE;
|
$this->hasError = TRUE;
|
||||||
|
@@ -204,7 +204,7 @@ interface IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Encodes data for use in an SQL statement.
|
* Encodes data for use in an SQL statement.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_TEXT, dibi::FIELD_BOOL, ...)
|
* @param string type (dibi::TEXT, dibi::BOOL, ...)
|
||||||
* @return string encoded value
|
* @return string encoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@@ -215,7 +215,7 @@ interface IDibiDriver
|
|||||||
/**
|
/**
|
||||||
* Decodes data from result set.
|
* Decodes data from result set.
|
||||||
* @param string value
|
* @param string value
|
||||||
* @param string type (dibi::FIELD_BINARY)
|
* @param string type (dibi::BINARY)
|
||||||
* @return string decoded value
|
* @return string decoded value
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@@ -15,8 +15,8 @@ dibi::connect(array(
|
|||||||
$res = dibi::query('SELECT * FROM [customers]');
|
$res = dibi::query('SELECT * FROM [customers]');
|
||||||
|
|
||||||
// auto-converts this column to integer
|
// auto-converts this column to integer
|
||||||
$res->setType('customer_id', Dibi::FIELD_INTEGER);
|
$res->setType('customer_id', Dibi::INTEGER);
|
||||||
$res->setType('added', Dibi::FIELD_DATETIME, 'H:i j.n.Y');
|
$res->setType('added', Dibi::DATETIME, 'H:i j.n.Y');
|
||||||
|
|
||||||
$row = $res->fetch();
|
$row = $res->fetch();
|
||||||
Debug::dump($row);
|
Debug::dump($row);
|
||||||
|
Reference in New Issue
Block a user