Doctrine 1.2.4
Doctrine_Expression_Pgsql Class Reference

Inherits Doctrine_Expression_Driver.

Public Member Functions

 __call ($m, $a)
 
 acos ($value)
 
 add (array $args)
 
 age ($timestamp1, $timestamp2=null)
 
 avg ($column)
 
 between ($expression, $value1, $value2)
 
 coalesce ()
 
 concat ()
 
 cos ($value)
 
 count ($column)
 
 date_part ($text, $time)
 
 div (array $args)
 
 eq ($value1, $value2)
 
 getConnection ()
 
 getModuleName ()
 
 gt ($value1, $value2)
 
 gte ($value1, $value2)
 
 guid ()
 
 in ($column, $values)
 
 isNotNull ($expression)
 
 isNull ($expression)
 
 length ($column)
 
 locate ($substr, $str)
 
 lower ($str)
 
 lt ($value1, $value2)
 
 lte ($value1, $value2)
 
 ltrim ($str)
 
 matchPattern ($pattern, $operator=null, $field=null)
 
 max ($column)
 
 md5 ($column)
 
 min ($column)
 
 mod ($expression1, $expression2)
 
 mul (array $args)
 
 neq ($value1, $value2)
 
 not ($expression)
 
 now ()
 
 pi ()
 
 position ($substr, $str)
 
 random ()
 
 regexp ()
 
 round ($column, $decimals=0)
 
 rtrim ($str)
 
 sin ($value)
 
 soundex ($value)
 
 sub (array $args)
 
 substring ($value, $from, $len=null)
 
 sum ($column)
 
 to_char ($time, $text)
 
 translate ($string, $from, $to)
 
 trim ($str)
 
 upper ($str)
 

Detailed Description

Definition at line 33 of file Pgsql.php.

Member Function Documentation

Doctrine_Expression_Driver::__call (   $m,
  $a 
)
inherited

__call

for all native RDBMS functions the function name itself is returned

Definition at line 639 of file Driver.php.

{
if ($this->conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_EXPR) {
throw new Doctrine_Expression_Exception('Unknown expression: ' . $m);
}
return $m . '(' . implode(', ', $a) . ')';
}
Doctrine_Expression_Driver::acos (   $value)
inherited

returns arcus cosine SQL string

Returns
string

Definition at line 585 of file Driver.php.

{
return 'ACOS(' . $value . ')';
}
Doctrine_Expression_Driver::add ( array  $args)
inherited

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 expressions.

Parameters
string|array(string)
Returns
string an expression

Definition at line 360 of file Driver.php.

{
return $this->basicMath('+', $args);
}
Doctrine_Expression_Pgsql::age (   $timestamp1,
  $timestamp2 = null 
)

Returns a series of strings concatinated

concat() accepts an arbitrary number of parameters. Each parameter must contain an expression or an array with expressions.

Parameters
string|array(string)strings that will be concatinated.
Returns
string PostgreSQLs AGE(<timestamp1> [, <timestamp2>]) function.
Parameters
string$timestamp1timestamp to subtract from NOW()
string$timestamp2optional; if given: subtract arguments
Returns
string

Definition at line 100 of file Pgsql.php.

{
if ( $timestamp2 == null ) {
return 'AGE(' . $timestamp1 . ')';
}
return 'AGE(' . $timestamp1 . ', ' . $timestamp2 . ')';
}
Doctrine_Expression_Driver::avg (   $column)
inherited

Returns the average value of a column

Parameters
string$columnthe column to use
Returns
string generated sql including an AVG aggregate function

Definition at line 62 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'AVG(' . $column . ')';
}
Doctrine_Expression_Driver::between (   $expression,
  $value1,
  $value2 
)
inherited

Returns SQL that checks if an expression evaluates to a value between two values.

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().

Parameters
string$expressionthe value to compare to
string$value1the lower value to compare with
string$value2the higher value to compare with
Returns
string logical expression

Definition at line 562 of file Driver.php.

{
$expression = $this->getIdentifier($expression);
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2;
}
Doctrine_Expression_Driver::coalesce ( )
inherited

coalesce

Returns
string

Definition at line 627 of file Driver.php.

{
$args = func_get_args();
return 'COALESCE(' . join(', ', (array) $args) . ')';
}
Doctrine_Expression_Pgsql::concat ( )

PostgreSQLs CONCAT() function

Parameters
anarray of values
Returns
string

Definition at line 136 of file Pgsql.php.

{
$args = func_get_args();
return join(' || ' , $args);
}
Doctrine_Expression_Driver::cos (   $value)
inherited

cos

Parameters
string$value
Returns
void

Definition at line 617 of file Driver.php.

{
return 'COS(' . $value . ')';
}
Doctrine_Expression_Driver::count (   $column)
inherited

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 is returned.

Parameters
string | integer$columnthe column to use
Returns
string generated sql including a COUNT aggregate function

Definition at line 77 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'COUNT(' . $column . ')';
}
Doctrine_Expression_Pgsql::date_part (   $text,
  $time 
)

PostgreSQLs DATE_PART( <text>, <time> ) function.

Parameters
string$textwhat to extract
string$timetimestamp or interval to extract from
Returns
string

Definition at line 114 of file Pgsql.php.

{
return 'DATE_PART(' . $text . ', ' . $time . ')';
}
Doctrine_Expression_Driver::div ( array  $args)
inherited

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 expressions.

Parameters
string|array(string)
Returns
string an expression

Definition at line 405 of file Driver.php.

{
return $this->basicMath('/', $args);
}
Doctrine_Expression_Driver::eq (   $value1,
  $value2 
)
inherited

Returns the SQL to check if two values are equal.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 417 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' = ' . $value2;
}
Doctrine_Connection_Module::getConnection ( )
inherited

getConnection returns the connection object this module uses

Returns
Doctrine_Connection

Definition at line 68 of file Module.php.

{
return $this->conn;
}
Doctrine_Connection_Module::getModuleName ( )
inherited

getModuleName returns the name of this module

Returns
string the name of this module

Definition at line 79 of file Module.php.

{
return $this->moduleName;
}
Doctrine_Expression_Driver::gt (   $value1,
  $value2 
)
inherited

Returns the SQL to check if one value is greater than another value.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 445 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' > ' . $value2;
}
Doctrine_Expression_Driver::gte (   $value1,
  $value2 
)
inherited

Returns the SQL to check if one value is greater than or equal to another value.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 460 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' >= ' . $value2;
}
Doctrine_Expression_Driver::guid ( )
inherited

Returns global unique identifier

Returns
string to get global unique identifier

Definition at line 575 of file Driver.php.

{
throw new Doctrine_Expression_Exception('method not implemented');
}
Doctrine_Expression_Driver::in (   $column,
  $values 
)
inherited

Returns the SQL to check if a value is one in a set of given values..

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.

Parameters
string$columnthe value that should be matched against
string|array(string)values that will be matched against $column
Returns
string logical expression

Definition at line 509 of file Driver.php.

{
if ( ! is_array($values)) {
$values = array($values);
}
$values = $this->getIdentifiers($values);
$column = $this->getIdentifier($column);
if (count($values) == 0) {
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
}
return $column . ' IN (' . implode(', ', $values) . ')';
}
Doctrine_Expression_Driver::isNotNull (   $expression)
inherited

Returns SQL that checks if a expression is not null.

Parameters
string$expressionthe expression that should be compared to null
Returns
string logical expression

Definition at line 541 of file Driver.php.

{
$expression = $this->getIdentifier($expression);
return $expression . ' IS NOT NULL';
}
Doctrine_Expression_Driver::isNull (   $expression)
inherited

Returns SQL that checks if a expression is null.

Parameters
string$expressionthe expression that should be compared to null
Returns
string logical expression

Definition at line 529 of file Driver.php.

{
$expression = $this->getIdentifier($expression);
return $expression . ' IS NULL';
}
Doctrine_Expression_Driver::length (   $column)
inherited

Returns the length of a text field.

Parameters
string$expression1
string$expression2
Returns
string

Definition at line 141 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'LENGTH(' . $column . ')';
}
Doctrine_Expression_Pgsql::locate (   $substr,
  $str 
)

transform locate to position

Parameters
string$substrstring to find
string$strto find where
Returns
string

Definition at line 241 of file Pgsql.php.

{
return $this->position($substr, $str);
}
Doctrine_Expression_Driver::lower (   $str)
inherited

lower Returns the string $str with all characters changed to lowercase according to the current character set mapping.

Parameters
string$strliteral string or column name
Returns
string

Definition at line 233 of file Driver.php.

{
return 'LOWER(' . $str . ')';
}
Doctrine_Expression_Driver::lt (   $value1,
  $value2 
)
inherited

Returns the SQL to check if one value is less than another value.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 474 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' < ' . $value2;
}
Doctrine_Expression_Driver::lte (   $value1,
  $value2 
)
inherited

Returns the SQL to check if one value is less than or equal to another value.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 489 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' <= ' . $value2;
}
Doctrine_Expression_Driver::ltrim (   $str)
inherited

ltrim returns the string $str with leading space characters removed

Parameters
string$strliteral string or column name
Returns
string

Definition at line 207 of file Driver.php.

{
return 'LTRIM(' . $str . ')';
}
Doctrine_Expression_Pgsql::matchPattern (   $pattern,
  $operator = null,
  $field = null 
)

build a pattern matching string

EXPERIMENTAL

WARNING: this function is experimental and may change signature at any time until labelled as non-experimental

public

Parameters
array$patterneven keys are strings, odd are patterns (% and _)
string$operatoroptional pattern operator (LIKE, ILIKE and maybe others in the future)
string$fieldoptional field name that is being matched against (might be required when emulating ILIKE)
Returns
string SQL pattern

Definition at line 191 of file Pgsql.php.

{
$match = '';
if ( ! is_null($operator)) {
$field = is_null($field) ? '' : $field.' ';
$operator = strtoupper($operator);
switch ($operator) {
// case insensitive
case 'ILIKE':
$match = $field.'ILIKE ';
break;
// case sensitive
case 'LIKE':
$match = $field.'LIKE ';
break;
default:
throw new Doctrine_Expression_Pgsql_Exception('not a supported operator type:'. $operator);
}
}
$match.= "'";
foreach ($pattern as $key => $value) {
if ($key % 2) {
$match.= $value;
} else {
$match.= $this->conn->escapePattern($this->conn->escape($value));
}
}
$match.= "'";
$match.= $this->patternEscapeString();
return $match;
}
Doctrine_Expression_Driver::max (   $column)
inherited

Returns the highest value of a column

Parameters
string$columnthe column to use
Returns
string generated sql including a MAX aggregate function

Definition at line 89 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'MAX(' . $column . ')';
}
Doctrine_Expression_Pgsql::md5 (   $column)

Returns the md5 sum of a field.

Note: Not SQL92, but common functionality

md5() works with the default PostgreSQL 8 versions.

If you are using PostgreSQL 7.x or older you need to make sure that the digest procedure is installed. If you use RPMS (Redhat and Mandrake) install the postgresql-contrib package. You must then install the procedure by running this shell command: psql [dbname] < /usr/share/pgsql/contrib/pgcrypto.sql You should make sure you run this as the postgres user.

Returns
string

Definition at line 53 of file Pgsql.php.

{
$column = $this->getIdentifier($column);
return 'MD5(' . $column . ')';
}
Doctrine_Expression_Driver::min (   $column)
inherited

Returns the lowest value of a column

Parameters
string$columnthe column to use
Returns
string

Definition at line 101 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'MIN(' . $column . ')';
}
Doctrine_Expression_Driver::mod (   $expression1,
  $expression2 
)
inherited

Returns the remainder of the division operation $expression1 / $expression2.

Parameters
string$expression1
string$expression2
Returns
string

Definition at line 169 of file Driver.php.

{
$expression1 = $this->getIdentifier($expression1);
$expression2 = $this->getIdentifier($expression2);
return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
}
Doctrine_Expression_Driver::mul ( array  $args)
inherited

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 expressions.

Parameters
string|array(string)
Returns
string an expression

Definition at line 390 of file Driver.php.

{
return $this->basicMath('*', $args);
}
Doctrine_Expression_Driver::neq (   $value1,
  $value2 
)
inherited

Returns the SQL to check if two values are unequal.

Parameters
string$value1logical expression to compare
string$value2logical expression to compare with
Returns
string logical expression

Definition at line 431 of file Driver.php.

{
$value1 = $this->getIdentifier($value1);
$value2 = $this->getIdentifier($value2);
return $value1 . ' <> ' . $value2;
}
Doctrine_Expression_Driver::not (   $expression)
inherited

Returns the SQL for a logical not.

Returns
string a logical expression

Definition at line 319 of file Driver.php.

{
$expression = $this->getIdentifier($expression);
return 'NOT(' . $expression . ')';
}
Doctrine_Expression_Pgsql::now ( )

Returns the SQL string to return the current system date and time.

Returns
string

Definition at line 148 of file Pgsql.php.

{
return 'LOCALTIMESTAMP(0)';
}
Doctrine_Expression_Driver::pi ( )
inherited

pi

Returns
void

Definition at line 606 of file Driver.php.

{
return 'PI()';
}
Doctrine_Expression_Pgsql::position (   $substr,
  $str 
)

position

Parameters
string$substrstring to find
string$strto find where
Returns
string

Definition at line 253 of file Pgsql.php.

{
$substr = $this->getIdentifier($substr);
$str = $this->getIdentifier($str);
return sprintf('POSITION(%s IN %s)', $substr, $str);
}
Doctrine_Expression_Pgsql::random ( )

return string to call a function to get random value inside an SQL statement

Returns
return string to generate float between 0 and 1 public

Definition at line 169 of file Pgsql.php.

{
return 'RANDOM()';
}
Doctrine_Expression_Pgsql::regexp ( )

regexp

Returns
string the regular expression operator

Definition at line 158 of file Pgsql.php.

{
return 'SIMILAR TO';
}
Doctrine_Expression_Driver::round (   $column,
  $decimals = 0 
)
inherited

Rounds a numeric field to the number of decimals specified.

Parameters
string$expression1
string$expression2
Returns
string

Definition at line 154 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'ROUND(' . $column . ', ' . $decimals . ')';
}
Doctrine_Expression_Driver::rtrim (   $str)
inherited

rtrim returns the string $str with proceeding space characters removed

Parameters
string$strliteral string or column name
Returns
string

Definition at line 195 of file Driver.php.

{
return 'RTRIM(' . $str . ')';
}
Doctrine_Expression_Driver::sin (   $value)
inherited

sin

Parameters
string$value
Returns
void

Definition at line 596 of file Driver.php.

{
return 'SIN(' . $value . ')';
}
Doctrine_Expression_Driver::soundex (   $value)
inherited

soundex 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.

Parameters
string$value
Returns
string SQL soundex function with given parameter

Definition at line 271 of file Driver.php.

{
throw new Doctrine_Expression_Exception('SQL soundex function not supported by this driver.');
}
Doctrine_Expression_Driver::sub ( array  $args)
inherited

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 expressions.

Parameters
string|array(string)
Returns
string an expression

Definition at line 375 of file Driver.php.

{
return $this->basicMath('-', $args );
}
Doctrine_Expression_Pgsql::substring (   $value,
  $from,
  $len = null 
)

Returns part of a string.

Note: Not SQL92, but common functionality.

Parameters
string$valuethe target $value the string or the string column.
int$fromextract from this characeter.
int$lenextract this amount of characters.
Returns
string sql that extracts part of a string.

Definition at line 70 of file Pgsql.php.

{
$value = $this->getIdentifier($value);
if ($len === null) {
$len = $this->getIdentifier($len);
return 'SUBSTR(' . $value . ', ' . $from . ')';
} else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
}
}
Doctrine_Expression_Driver::sum (   $column)
inherited

Returns the total sum of a column

Parameters
string$columnthe column to use
Returns
string

Definition at line 113 of file Driver.php.

{
$column = $this->getIdentifier($column);
return 'SUM(' . $column . ')';
}
Doctrine_Expression_Pgsql::to_char (   $time,
  $text 
)

PostgreSQLs TO_CHAR( <time>, <text> ) function.

Parameters
string$timetimestamp or interval
string$texthow to the format the output
Returns
string

Definition at line 126 of file Pgsql.php.

{
return 'TO_CHAR(' . $time . ', ' . $text . ')';
}
Doctrine_Expression_Pgsql::translate (   $string,
  $from,
  $to 
)

return syntax for pgsql TRANSLATE() dbms function

Returns
string $sql

Definition at line 228 of file Pgsql.php.

{
$translate = 'TRANSLATE(' . $string . ', ' . $from . ', ' . $to . ')';
return $translate;
}
Doctrine_Expression_Driver::trim (   $str)
inherited

trim returns the string $str with leading and proceeding space characters removed

Parameters
string$strliteral string or column name
Returns
string

Definition at line 183 of file Driver.php.

{
return 'TRIM(' . $str . ')';
}
Doctrine_Expression_Driver::upper (   $str)
inherited

upper Returns the string $str with all characters changed to uppercase according to the current character set mapping.

Parameters
string$strliteral string or column name
Returns
string

Definition at line 220 of file Driver.php.

{
return 'UPPER(' . $str . ')';
}

The documentation for this class was generated from the following file: