Moved connection driver functionality to expression drivers
This commit is contained in:
parent
7ef869ee40
commit
53e9b06f6c
@ -44,26 +44,31 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
|
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
|
||||||
*/
|
*/
|
||||||
protected $tables = array();
|
protected $tables = array();
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName;
|
||||||
|
/**
|
||||||
|
* @var array $supported an array containing all features this driver supports,
|
||||||
|
* keys representing feature names and values as
|
||||||
|
* one of the following (true, false, 'emulated')
|
||||||
|
*/
|
||||||
|
protected $supported = array();
|
||||||
/**
|
/**
|
||||||
* @var Doctrine_DataDict $dataDict
|
* @var Doctrine_DataDict $dataDict
|
||||||
*/
|
*/
|
||||||
private $dataDict;
|
private $dataDict;
|
||||||
|
|
||||||
|
|
||||||
private static $availibleDrivers = array(
|
private static $availibleDrivers = array(
|
||||||
"Mysql",
|
'Mysql',
|
||||||
"Pgsql",
|
'Pgsql',
|
||||||
"Oracle",
|
'Oracle',
|
||||||
"Informix",
|
'Informix',
|
||||||
"Mssql",
|
'Mssql',
|
||||||
"Sqlite",
|
'Sqlite',
|
||||||
"Firebird"
|
'Firebird'
|
||||||
);
|
);
|
||||||
private static $driverMap = array('oracle' => 'oci8',
|
|
||||||
'postgres' => 'pgsql',
|
|
||||||
'oci' => 'oci8',
|
|
||||||
'sqlite2' => 'sqlite',
|
|
||||||
'sqlite3' => 'sqlite');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the constructor
|
* the constructor
|
||||||
@ -84,6 +89,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
|
|
||||||
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
|
$this->getAttribute(Doctrine::ATTR_LISTENER)->onOpen($this);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* getName
|
||||||
|
*
|
||||||
|
* @return string returns the name of this driver
|
||||||
|
*/
|
||||||
|
public function getName() {
|
||||||
|
return $this->driverName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* quoteIdentifier
|
* quoteIdentifier
|
||||||
*
|
*
|
||||||
@ -145,28 +159,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
if(isset($this->dataDict))
|
if(isset($this->dataDict))
|
||||||
return $this->dataDict;
|
return $this->dataDict;
|
||||||
|
|
||||||
$driver = $this->dbh->getAttribute(PDO::ATTR_DRIVER_NAME);
|
$class = 'Doctrine_DataDict_' . $this->getName();
|
||||||
switch($driver) {
|
$this->dataDict = new $class($this->dbh);
|
||||||
case "mysql":
|
|
||||||
$this->dataDict = new Doctrine_DataDict_Mysql($this->dbh);
|
|
||||||
break;
|
|
||||||
case "sqlite":
|
|
||||||
case "sqlite2":
|
|
||||||
$this->dataDict = new Doctrine_DataDict_Sqlite($this->dbh);
|
|
||||||
break;
|
|
||||||
case "pgsql":
|
|
||||||
$this->dataDict = new Doctrine_DataDict_Pgsql($this->dbh);
|
|
||||||
break;
|
|
||||||
case "oci":
|
|
||||||
case "oci8":
|
|
||||||
$this->dataDict = new Doctrine_DataDict_Oracle($this->dbh);
|
|
||||||
break;
|
|
||||||
case "mssql":
|
|
||||||
$this->dataDict = new Doctrine_DataDict_Mssql($this->dbh);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Doctrine_Connection_Exception("No datadict driver availible for ".$driver);
|
|
||||||
}
|
|
||||||
return $this->dataDict;
|
return $this->dataDict;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -185,16 +180,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
public function setTransactionIsolation($isolation) {
|
public function setTransactionIsolation($isolation) {
|
||||||
throw new Doctrine_Connection_Exception('Transaction isolation levels not supported by this database driver.');
|
throw new Doctrine_Connection_Exception('Transaction isolation levels not supported by this database driver.');
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* getRegexpOperator
|
|
||||||
* returns the regular expression operator
|
|
||||||
* (implemented by the connection drivers)
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getRegexpOperator() {
|
|
||||||
throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.');
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* getTransactionIsolation
|
* getTransactionIsolation
|
||||||
*
|
*
|
||||||
@ -246,9 +232,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
* hasTable
|
||||||
* whether or not this connection has table $name initialized
|
* whether or not this connection has table $name initialized
|
||||||
*
|
*
|
||||||
* @param $mixed $name
|
* @param mixed $name
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function hasTable($name) {
|
public function hasTable($name) {
|
||||||
|
@ -27,6 +27,11 @@ Doctrine::autoload('Doctrine_Connection');
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Firebird extends Doctrine_Connection {
|
class Doctrine_Connection_Firebird extends Doctrine_Connection {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Firebird';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
* Adds an driver-specific LIMIT clause to the query
|
||||||
*
|
*
|
||||||
|
@ -26,4 +26,9 @@ Doctrine::autoload('Doctrine_Connection');
|
|||||||
* @url www.phpdoctrine.com
|
* @url www.phpdoctrine.com
|
||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Informix extends Doctrine_Connection { }
|
class Doctrine_Connection_Informix extends Doctrine_Connection {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Informix';
|
||||||
|
}
|
||||||
|
@ -27,6 +27,10 @@ Doctrine::autoload('Doctrine_Connection');
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Mssql extends Doctrine_Connection {
|
class Doctrine_Connection_Mssql extends Doctrine_Connection {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Mssql';
|
||||||
/**
|
/**
|
||||||
* returns the next value in the given sequence
|
* returns the next value in the given sequence
|
||||||
* @param string $sequence
|
* @param string $sequence
|
||||||
|
@ -27,7 +27,10 @@ Doctrine::autoload('Doctrine_Connection_Common');
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Mysql';
|
||||||
/**
|
/**
|
||||||
* the constructor
|
* the constructor
|
||||||
* @param PDO $pdo -- database handle
|
* @param PDO $pdo -- database handle
|
||||||
@ -59,15 +62,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
|
|
||||||
parent::__construct($manager,$pdo);
|
parent::__construct($manager,$pdo);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* returns the regular expression operator
|
|
||||||
* (implemented by the connection drivers)
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getRegexpOperator() {
|
|
||||||
return 'RLIKE';
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* getTransactionIsolation
|
* getTransactionIsolation
|
||||||
*
|
*
|
||||||
|
@ -27,6 +27,10 @@ Doctrine::autoload('Doctrine_Connection');
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Oracle';
|
||||||
/**
|
/**
|
||||||
* Adds an driver-specific LIMIT clause to the query
|
* Adds an driver-specific LIMIT clause to the query
|
||||||
*
|
*
|
||||||
@ -78,44 +82,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
|
|||||||
$data = $stmt->fetch(PDO::FETCH_NUM);
|
$data = $stmt->fetch(PDO::FETCH_NUM);
|
||||||
return $data[0];
|
return $data[0];
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Return string to call a variable with the current timestamp inside an SQL statement
|
|
||||||
* There are three special variables for current date and time:
|
|
||||||
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
|
|
||||||
* - CURRENT_DATE (date, DATE type)
|
|
||||||
* - CURRENT_TIME (time, TIME type)
|
|
||||||
*
|
|
||||||
* @return string to call a variable with the current timestamp
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
function now($type = 'timestamp')
|
|
||||||
{
|
|
||||||
switch ($type) {
|
|
||||||
case 'date':
|
|
||||||
case 'time':
|
|
||||||
case 'timestamp':
|
|
||||||
default:
|
|
||||||
return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* substring
|
|
||||||
*
|
|
||||||
* @return string SQL substring function with given parameters
|
|
||||||
*/
|
|
||||||
function substring($value, $position = 1, $length = null) {
|
|
||||||
if($length !== null)
|
|
||||||
return "SUBSTR($value, $position, $length)";
|
|
||||||
|
|
||||||
return "SUBSTR($value, $position)";
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* random
|
|
||||||
*
|
|
||||||
* @return string an oracle SQL string that generates a float between 0 and 1
|
|
||||||
*/
|
|
||||||
function random() {
|
|
||||||
return 'dbms_random.value';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@ Doctrine::autoload("Doctrine_Connection_Common");
|
|||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
|
class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
|
||||||
|
/**
|
||||||
|
* @var string $driverName the name of this connection driver
|
||||||
|
*/
|
||||||
|
protected $driverName = 'Pgsql';
|
||||||
/**
|
/**
|
||||||
* returns the next value in the given sequence
|
* returns the next value in the given sequence
|
||||||
* @param string $sequence
|
* @param string $sequence
|
||||||
@ -60,22 +64,6 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
|
|||||||
$query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation;
|
$query = 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $isolation;
|
||||||
return $this->dbh->query($query);
|
return $this->dbh->query($query);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* getRegexpOperator
|
|
||||||
*
|
|
||||||
* @return string the regular expression operator
|
|
||||||
*/
|
|
||||||
public function getRegexpOperator() {
|
|
||||||
return 'SIMILAR TO';
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* return string to call a function to get random value inside an SQL statement
|
|
||||||
*
|
|
||||||
* @return return string to generate float between 0 and 1
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public function random() {
|
|
||||||
return 'RANDOM()';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,22 +29,9 @@ Doctrine::autoload("Doctrine_Connection_Common");
|
|||||||
|
|
||||||
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
|
class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
|
||||||
/**
|
/**
|
||||||
* Return string to call a variable with the current timestamp inside an SQL statement
|
* @var string $driverName the name of this connection driver
|
||||||
* There are three special variables for current date and time.
|
|
||||||
*
|
|
||||||
* @return string sqlite function as string
|
|
||||||
*/
|
*/
|
||||||
public function now($type = 'timestamp') {
|
protected $driverName = 'Sqlite';
|
||||||
switch ($type) {
|
|
||||||
case 'time':
|
|
||||||
return 'time(\'now\')';
|
|
||||||
case 'date':
|
|
||||||
return 'date(\'now\')';
|
|
||||||
case 'timestamp':
|
|
||||||
default:
|
|
||||||
return 'datetime(\'now\')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Set the transacton isolation level.
|
* Set the transacton isolation level.
|
||||||
*
|
*
|
||||||
@ -72,27 +59,6 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
|
|||||||
$query = "PRAGMA read_uncommitted=$isolation";
|
$query = "PRAGMA read_uncommitted=$isolation";
|
||||||
return $this->_doQuery($query, true);
|
return $this->_doQuery($query, true);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* return string to call a function to get a substring inside an SQL statement
|
|
||||||
*
|
|
||||||
* @return string to call a function to get a substring
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
public function substring($value, $position = 1, $length = null) {
|
|
||||||
if($length !== null)
|
|
||||||
return "substr($value,$position,$length)";
|
|
||||||
|
|
||||||
return "substr($value,$position,length($value))";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return string to call a function to get random value inside an SQL statement
|
|
||||||
*
|
|
||||||
* @return string to generate float between 0 and 1
|
|
||||||
*/
|
|
||||||
public function random()
|
|
||||||
{
|
|
||||||
return '((RANDOM() + 2147483648) / 4294967296)';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,11 @@
|
|||||||
* @package Doctrine
|
* @package Doctrine
|
||||||
*/
|
*/
|
||||||
class Doctrine_DB_Profiler extends Doctrine_DB_EventListener {
|
class Doctrine_DB_Profiler extends Doctrine_DB_EventListener {
|
||||||
public function onPreQuery(Doctrine_DB $dbh, array $args) { }
|
private $queries;
|
||||||
|
|
||||||
|
public function onPreQuery(Doctrine_DB $dbh, array $args) {
|
||||||
|
$this->queries[] = $args[0];
|
||||||
|
}
|
||||||
public function onQuery(Doctrine_DB $dbh, array $args) { }
|
public function onQuery(Doctrine_DB $dbh, array $args) { }
|
||||||
|
|
||||||
public function onPrePrepare(Doctrine_DB $dbh, array $args) { }
|
public function onPrePrepare(Doctrine_DB $dbh, array $args) { }
|
||||||
|
@ -38,6 +38,15 @@ class Doctrine_Expression {
|
|||||||
public function __construct(Doctrine_Connection $conn) {
|
public function __construct(Doctrine_Connection $conn) {
|
||||||
$this->conn = $conn;
|
$this->conn = $conn;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* regexp
|
||||||
|
* returns the regular expression operator
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function regexp() {
|
||||||
|
throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the average value of a column
|
* Returns the average value of a column
|
||||||
*
|
*
|
||||||
@ -160,7 +169,8 @@ class Doctrine_Expression {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* upper
|
* upper
|
||||||
* Returns the string $str with all characters changed to uppercase according to the current character set mapping.
|
* Returns the string $str with all characters changed to
|
||||||
|
* uppercase according to the current character set mapping.
|
||||||
*
|
*
|
||||||
* @param string $str literal string or column name
|
* @param string $str literal string or column name
|
||||||
* @return string
|
* @return string
|
||||||
@ -170,7 +180,8 @@ class Doctrine_Expression {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* lower
|
* lower
|
||||||
* Returns the string $str with all characters changed to lowercase according to the current character set mapping.
|
* Returns the string $str with all characters changed to
|
||||||
|
* lowercase according to the current character set mapping.
|
||||||
*
|
*
|
||||||
* @param string $str literal string or column name
|
* @param string $str literal string or column name
|
||||||
* @return string
|
* @return string
|
||||||
@ -198,16 +209,18 @@ class Doctrine_Expression {
|
|||||||
return 'NOW()';
|
return 'NOW()';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns part of a string.
|
* return string to call a function to get a substring inside an SQL statement
|
||||||
*
|
*
|
||||||
* Note: Not SQL92, but common functionality.
|
* Note: Not SQL92, but common functionality.
|
||||||
*
|
*
|
||||||
* @param string $value the target $value the string or the string column.
|
* SQLite only supports the 2 parameter variant of this function
|
||||||
* @param int $from extract from this characeter.
|
*
|
||||||
* @param int $len extract this amount of characters.
|
* @param string $value an sql string literal or column name/alias
|
||||||
* @return string sql that extracts part of a string.
|
* @param integer $position where to start the substring portion
|
||||||
|
* @param integer $length the substring portion length
|
||||||
|
* @return string SQL substring function with given parameters
|
||||||
*/
|
*/
|
||||||
public function subString($value, $from, $len = null) {
|
public function substring($value, $from, $len = null) {
|
||||||
$value = $this->getIdentifier($value);
|
$value = $this->getIdentifier($value);
|
||||||
if ($len === null)
|
if ($len === null)
|
||||||
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
|
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
|
||||||
|
@ -26,4 +26,13 @@ Doctrine::autoload('Doctrine_Expression');
|
|||||||
* @url www.phpdoctrine.com
|
* @url www.phpdoctrine.com
|
||||||
* @license LGPL
|
* @license LGPL
|
||||||
*/
|
*/
|
||||||
class Doctrine_Expression_Mysql extends Doctrine_Expression { }
|
class Doctrine_Expression_Mysql extends Doctrine_Expression {
|
||||||
|
/**
|
||||||
|
* returns the regular expression operator
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function regexp() {
|
||||||
|
return 'RLIKE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -42,4 +42,46 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
|
|||||||
$cols = $this->getIdentifiers( $args );
|
$cols = $this->getIdentifiers( $args );
|
||||||
return join( ' || ' , $cols );
|
return join( ' || ' , $cols );
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* return string to call a function to get a substring inside an SQL statement
|
||||||
|
*
|
||||||
|
* Note: Not SQL92, but common functionality.
|
||||||
|
*
|
||||||
|
* @param string $value an sql string literal or column name/alias
|
||||||
|
* @param integer $position where to start the substring portion
|
||||||
|
* @param integer $length the substring portion length
|
||||||
|
* @return string SQL substring function with given parameters
|
||||||
|
*/
|
||||||
|
public function substring($value, $position = 1, $length = null) {
|
||||||
|
if($length !== null)
|
||||||
|
return "SUBSTR($value, $position, $length)";
|
||||||
|
|
||||||
|
return "SUBSTR($value, $position)";
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Return string to call a variable with the current timestamp inside an SQL statement
|
||||||
|
* There are three special variables for current date and time:
|
||||||
|
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
|
||||||
|
* - CURRENT_DATE (date, DATE type)
|
||||||
|
* - CURRENT_TIME (time, TIME type)
|
||||||
|
*
|
||||||
|
* @return string to call a variable with the current timestamp
|
||||||
|
*/
|
||||||
|
public function now($type = 'timestamp') {
|
||||||
|
switch ($type) {
|
||||||
|
case 'date':
|
||||||
|
case 'time':
|
||||||
|
case 'timestamp':
|
||||||
|
default:
|
||||||
|
return 'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* random
|
||||||
|
*
|
||||||
|
* @return string an oracle SQL string that generates a float between 0 and 1
|
||||||
|
*/
|
||||||
|
function random() {
|
||||||
|
return 'dbms_random.value';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,4 +88,21 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
|
|||||||
|
|
||||||
return join(' || ' , $cols);
|
return join(' || ' , $cols);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* regexp
|
||||||
|
*
|
||||||
|
* @return string the regular expression operator
|
||||||
|
*/
|
||||||
|
public function regexp() {
|
||||||
|
return 'SIMILAR TO';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* return string to call a function to get random value inside an SQL statement
|
||||||
|
*
|
||||||
|
* @return return string to generate float between 0 and 1
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
public function random() {
|
||||||
|
return 'RANDOM()';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,22 +28,54 @@ Doctrine::autoload('Doctrine_Expression');
|
|||||||
*/
|
*/
|
||||||
class Doctrine_Expression_Sqlite extends Doctrine_Expression {
|
class Doctrine_Expression_Sqlite extends Doctrine_Expression {
|
||||||
/**
|
/**
|
||||||
* Returns part of a string.
|
* returns the regular expression operator
|
||||||
*
|
*
|
||||||
* Note: Not SQL92, but common functionality. SQLite only supports the 3
|
* @return string
|
||||||
* parameter variant of this function, so we are using 2^30-1 as
|
|
||||||
* artificial length in that case.
|
|
||||||
*
|
|
||||||
* @param string $value the target $value the string or the string column.
|
|
||||||
* @param int $from extract from this characeter.
|
|
||||||
* @param int $len extract this amount of characters.
|
|
||||||
* @return string sql that extracts part of a string.
|
|
||||||
*/
|
*/
|
||||||
public function subString($value, $from, $len = null) {
|
public function regexp() {
|
||||||
$value = $this->getIdentifier( $value );
|
return 'RLIKE';
|
||||||
if ( $len === null )
|
}
|
||||||
$len = 1073741823;
|
/**
|
||||||
|
* Return string to call a variable with the current timestamp inside an SQL statement
|
||||||
|
* There are three special variables for current date and time.
|
||||||
|
*
|
||||||
|
* @return string sqlite function as string
|
||||||
|
*/
|
||||||
|
public function now($type = 'timestamp') {
|
||||||
|
switch ($type) {
|
||||||
|
case 'time':
|
||||||
|
return 'time(\'now\')';
|
||||||
|
case 'date':
|
||||||
|
return 'date(\'now\')';
|
||||||
|
case 'timestamp':
|
||||||
|
default:
|
||||||
|
return 'datetime(\'now\')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* return string to call a function to get random value inside an SQL statement
|
||||||
|
*
|
||||||
|
* @return string to generate float between 0 and 1
|
||||||
|
*/
|
||||||
|
public function random() {
|
||||||
|
return '((RANDOM() + 2147483648) / 4294967296)';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* return string to call a function to get a substring inside an SQL statement
|
||||||
|
*
|
||||||
|
* Note: Not SQL92, but common functionality.
|
||||||
|
*
|
||||||
|
* SQLite only supports the 2 parameter variant of this function
|
||||||
|
*
|
||||||
|
* @param string $value an sql string literal or column name/alias
|
||||||
|
* @param integer $position where to start the substring portion
|
||||||
|
* @param integer $length the substring portion length
|
||||||
|
* @return string SQL substring function with given parameters
|
||||||
|
*/
|
||||||
|
public function substring($value, $position = 1, $length = null) {
|
||||||
|
if($length !== null)
|
||||||
|
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
|
||||||
|
|
||||||
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
|
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user