Source for file Driver.php
Documentation is available at Driver.php
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* Doctrine_Expression_Driver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* returns the regular expression operator
* Returns the average value of a column
* @param string $column the column to use
* @return string generated sql including an AVG aggregate function
public function avg($column)
return 'AVG(' .
$column .
')';
* Returns the number of rows (without a NULL value) of a column
* If a '*' is used instead of a column the number of selected rows
* @param string|integer$column the column to use
* @return string generated sql including a COUNT aggregate function
public function count($column)
return 'COUNT(' .
$column .
')';
* Returns the highest value of a column
* @param string $column the column to use
* @return string generated sql including a MAX aggregate function
public function max($column)
return 'MAX(' .
$column .
')';
* Returns the lowest value of a column
* @param string $column the column to use
public function min($column)
return 'MIN(' .
$column .
')';
* Returns the total sum of a column
* @param string $column the column to use
public function sum($column)
return 'SUM(' .
$column .
')';
* Returns the md5 sum of a field.
* Note: Not SQL92, but common functionality
public function md5($column)
return 'MD5(' .
$column .
')';
* Returns the length of a text field.
* @param string $expression1
* @param string $expression2
public function length($column)
return 'LENGTH(' .
$column .
')';
* Rounds a numeric field to the number of decimals specified.
* @param string $expression1
* @param string $expression2
public function round($column, $decimals =
0)
return 'ROUND(' .
$column .
', ' .
$decimals .
')';
* Returns the remainder of the division operation
* $expression1 / $expression2.
* @param string $expression1
* @param string $expression2
public function mod($expression1, $expression2)
return 'MOD(' .
$expression1 .
', ' .
$expression2 .
')';
* returns the string $str with leading and proceeding space characters removed
* @param string $str literal string or column name
public function trim($str)
return 'TRIM(' .
$str .
')';
* returns the string $str with proceeding space characters removed
* @param string $str literal string or column name
public function rtrim($str)
return 'RTRIM(' .
$str .
')';
* returns the string $str with leading space characters removed
* @param string $str literal string or column name
public function ltrim($str)
return 'LTRIM(' .
$str .
')';
* 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
public function upper($str)
return 'UPPER(' .
$str .
')';
* 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
public function lower($str)
return 'LOWER(' .
$str .
')';
* returns the position of the first occurrence of substring $substr in string $str
* @param string $substr literal string to find
* @param string $str literal string
public function locate($str, $substr)
return 'LOCATE(' .
$str .
', ' .
$substr .
')';
* Returns the current system date.
* Returns a string to call a function to compute the
* soundex encoding of a string
* The string "?000" is returned if the argument is NULL.
* @return string SQL soundex function with given parameter
* 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, $from, $len =
null)
return 'SUBSTRING(' .
$value .
' FROM ' .
$from .
')';
return 'SUBSTRING(' .
$value .
' FROM ' .
$from .
' FOR ' .
$len .
')';
* Returns a series of strings concatinated
* concat() accepts an arbitrary number of parameters. Each parameter
* must contain an expression or an array with expressions.
* @param string|array(string)strings that will be concatinated.
return 'CONCAT(' .
join(', ', (array)
$args) .
')';
* Returns the SQL for a logical not.
* $q = new Doctrine_Query();
* $q->select('*')->from('table')
* ->where($e->eq('id', $e->not('null'));
* @return string a logical expression
public function not($expression)
return 'NOT(' .
$expression .
')';
* Returns the SQL to perform the same mathematical operation over an array
* of values or expressions.
* basicMath() accepts an arbitrary number of parameters. Each parameter
* must contain a value or an expression or an array with values or
* @param string $type the type of operation, can be '+', '-', '*' or '/'.
* @param string|array(string)
* @return string an expression
private function basicMath($type, array $args)
$elements =
$this->getIdentifiers($args);
if (count($elements) <
1) {
if (count($elements) ==
1) {
return '(' .
implode(' ' .
$type .
' ', $elements) .
')';
* Returns the SQL to add values or expressions together.
* add() accepts an arbitrary number of parameters. Each parameter
* must contain a value or an expression or an array with values or
* $q = new Doctrine_Query();
* ->where($e->eq($e->add('id', 2), 12));
* @param string|array(string)
* @return string an expression
public function add(array $args)
return $this->basicMath('+', $args);
* Returns the SQL to subtract values or expressions from eachother.
* subtract() accepts an arbitrary number of parameters. Each parameter
* must contain a value or an expression or an array with values or
* $q = new Doctrine_Query();
* ->where($e->eq($e->sub('id', 2), 12));
* @param string|array(string)
* @return string an expression
public function sub(array $args)
return $this->basicMath('-', $args );
* Returns the SQL to multiply values or expressions by eachother.
* multiply() accepts an arbitrary number of parameters. Each parameter
* must contain a value or an expression or an array with values or
* $q = new Doctrine_Query();
* ->where($e->eq($e->mul('id', 2), 12));
* @param string|array(string)
* @return string an expression
public function mul(array $args)
return $this->basicMath('*', $args);
* Returns the SQL to divide values or expressions by eachother.
* divide() accepts an arbitrary number of parameters. Each parameter
* must contain a value or an expression or an array with values or
* $q = new Doctrine_Query();
* ->where($e->eq($e->div('id', 2), 12));
* @param string|array(string)
* @return string an expression
public function div(array $args)
return $this->basicMath('/', $args);
* Returns the SQL to check if two values are equal.
* $q = new Doctrine_Query();
* ->where($q->expr->eq('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function eq($value1, $value2)
return $value1 .
' = ' .
$value2;
* Returns the SQL to check if two values are unequal.
* $q = new Doctrine_Query();
* ->where($q->expr->neq('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function neq($value1, $value2)
return $value1 .
' <> ' .
$value2;
* Returns the SQL to check if one value is greater than another value.
* $q = new Doctrine_Query();
* ->where($q->expr->gt('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function gt($value1, $value2)
return $value1 .
' > ' .
$value2;
* Returns the SQL to check if one value is greater than or equal to
* $q = new Doctrine_Query();
* ->where($q->expr->gte('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function gte($value1, $value2)
return $value1 .
' >= ' .
$value2;
* Returns the SQL to check if one value is less than another value.
* $q = new Doctrine_Query();
* ->where($q->expr->lt('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function lt($value1, $value2)
return $value1 .
' < ' .
$value2;
* Returns the SQL to check if one value is less than or equal to
* $q = new Doctrine_Query();
* ->where($q->expr->lte('id', 1));
* @param string $value1 logical expression to compare
* @param string $value2 logical expression to compare with
* @return string logical expression
public function lte($value1, $value2)
return $value1 .
' <= ' .
$value2;
* Returns the SQL to check if a value is one in a set of
* in() accepts an arbitrary number of parameters. The first parameter
* must always specify the value that should be matched against. Successive
* must contain a logical expression or an array with logical expressions.
* These expressions will be matched against the first parameter.
* $q = new Doctrine_Query();
* ->where($q->expr->in( 'id', array(1,2,3)));
* @param string $column the value that should be matched against
* @param string|array(string) values that will be matched against $column
* @return string logical expression
public function in($column, $values)
$values =
array($values);
if (count($values) ==
0) {
return $column .
' IN (' .
implode(', ', $values) .
')';
* Returns SQL that checks if a expression is null.
* $q = new Doctrine_Query();
* ->where($q->expr->isNull('id'));
* @param string $expression the expression that should be compared to null
* @return string logical expression
public function isNull($expression)
return $expression .
' IS NULL';
* Returns SQL that checks if a expression is not null.
* $q = new Doctrine_Query();
* ->where($q->expr->isNotNull('id'));
* @param string $expression the expression that should be compared to null
* @return string logical expression
return $expression .
' IS NOT NULL';
* Returns SQL that checks if an expression evaluates to a value between
* The parameter $expression is checked if it is between $value1 and $value2.
* Note: There is a slight difference in the way BETWEEN works on some databases.
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database
* independence you should avoid using between().
* $q = new Doctrine_Query();
* ->where($q->expr->between('id', 1, 5));
* @param string $expression the value to compare to
* @param string $value1 the lower value to compare with
* @param string $value2 the higher value to compare with
* @return string logical expression
public function between($expression, $value1, $value2)
return $expression .
' BETWEEN ' .
$value1 .
' AND ' .
$value2;
* Returns global unique identifier
* @return string to get global unique identifier
* returns arcus cosine SQL string
public function acos($value)
return 'ACOS(' .
$value .
')';
* for all native RDBMS functions the function name itself is returned
public function __call($m, $a)
return $m .
'(' .
implode(', ', $a) .
')';