Little fix for expression class
This commit is contained in:
parent
61c906266b
commit
da0f27d93a
@ -31,6 +31,12 @@ Doctrine::autoload('Doctrine_Connection_Module');
|
|||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||||
*/
|
*/
|
||||||
class Doctrine_Expression extends Doctrine_Connection_Module {
|
class Doctrine_Expression extends Doctrine_Connection_Module {
|
||||||
|
public function getIdentifier($column) {
|
||||||
|
return $column;
|
||||||
|
}
|
||||||
|
public function getIdentifiers($columns) {
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* regexp
|
* regexp
|
||||||
* returns the regular expression operator
|
* returns the regular expression operator
|
||||||
@ -38,7 +44,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function regexp() {
|
public function regexp() {
|
||||||
throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.');
|
throw new Doctrine_Expression_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
|
||||||
@ -131,7 +137,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
* @param string $expression2
|
* @param string $expression2
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function round($column, $decimals) {
|
public function round($column, $decimals = 0) {
|
||||||
$column = $this->getIdentifier($column);
|
$column = $this->getIdentifier($column);
|
||||||
|
|
||||||
return 'ROUND(' . $column . ', ' . $decimals . ')';
|
return 'ROUND(' . $column . ', ' . $decimals . ')';
|
||||||
@ -190,7 +196,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
* @param string $str literal string
|
* @param string $str literal string
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function locate($substr, $str) {
|
public function locate($str, $substr) {
|
||||||
return 'LOCATE(' . $str . ', ' . $substr . ')';
|
return 'LOCATE(' . $str . ', ' . $substr . ')';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -243,9 +249,8 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
*
|
*
|
||||||
* @param string|array(string) strings that will be concatinated.
|
* @param string|array(string) strings that will be concatinated.
|
||||||
*/
|
*/
|
||||||
public function concat($arg1, $arg2) {
|
public function concat(array $args) {
|
||||||
$args = func_get_args();
|
$cols = $this->getIdentifiers($args);
|
||||||
$cols = $this->getIdentifiers($cols);
|
|
||||||
return 'CONCAT(' . join(', ', $cols) . ')';
|
return 'CONCAT(' . join(', ', $cols) . ')';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -263,7 +268,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
*/
|
*/
|
||||||
public function not($expression) {
|
public function not($expression) {
|
||||||
$expression = $this->getIdentifier($expression);
|
$expression = $this->getIdentifier($expression);
|
||||||
return 'NOT (' . $expression . ')';
|
return 'NOT(' . $expression . ')';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the SQL to perform the same mathematical operation over an array
|
* Returns the SQL to perform the same mathematical operation over an array
|
||||||
@ -278,15 +283,14 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
* @return string an expression
|
* @return string an expression
|
||||||
*/
|
*/
|
||||||
private function basicMath($type, array $args) {
|
private function basicMath($type, array $args) {
|
||||||
$args = func_get_args();
|
$elements = $this->getIdentifiers($args);
|
||||||
$elements = $this->getIdentifiers($elements);
|
|
||||||
if (count($elements) < 1)
|
if (count($elements) < 1)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
if (count($elements) == 1) {
|
if (count($elements) == 1) {
|
||||||
return $elements[0];
|
return $elements[0];
|
||||||
} else {
|
} else {
|
||||||
return '(' . join(' ' . $type . ' ', $elements) . ')';
|
return '(' . implode(' ' . $type . ' ', $elements) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -382,7 +386,6 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
* @return string an expression
|
* @return string an expression
|
||||||
*/
|
*/
|
||||||
public function div(array $args) {
|
public function div(array $args) {
|
||||||
$args = func_get_args();
|
|
||||||
return $this->basicMath('/', $args);
|
return $this->basicMath('/', $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -545,7 +548,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
|
|||||||
if(count($values) == 0)
|
if(count($values) == 0)
|
||||||
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
|
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
|
||||||
|
|
||||||
return $column . ' IN ( ' . join(', ', $values) . ' )';
|
return $column . ' IN (' . implode(', ', $values) . ')';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns SQL that checks if a expression is null.
|
* Returns SQL that checks if a expression is null.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user