3
* $Id: Condition.php 5218 2008-11-26 00:28:49Z jwage $
5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.phpdoctrine.org>.
23
* Doctrine_Query_Condition
27
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28
* @link www.phpdoctrine.org
30
* @version $Revision: 5218 $
31
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
33
abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
36
* DQL CONDITION PARSER
37
* parses the join condition/where/having part of the query string
42
public function parse($str)
46
$parts = $this->_tokenizer->bracketExplode($str, array(' OR '), '(', ')');
48
if (count($parts) > 1) {
50
foreach ($parts as $part) {
51
$part = $this->_tokenizer->bracketTrim($part, '(', ')');
52
$ret[] = $this->parse($part);
54
$r = implode(' OR ', $ret);
56
$parts = $this->_tokenizer->bracketExplode($str, array(' AND '), '(', ')');
58
// Ticket #1388: We need to make sure we're not splitting a BETWEEN ... AND ... clause
61
for ($i = 0, $l = count($parts); $i < $l; $i++) {
62
$test = $this->_tokenizer->sqlExplode($parts[$i]);
64
if (count($test) == 3 && strtoupper($test[1]) == 'BETWEEN') {
65
$tmp[] = $parts[$i] . ' AND ' . $parts[++$i];
74
if (count($parts) > 1) {
76
foreach ($parts as $part) {
77
$part = $this->_tokenizer->bracketTrim($part, '(', ')');
78
$ret[] = $this->parse($part);
80
$r = implode(' AND ', $ret);
83
if (substr($parts[0],0,1) == '(' && substr($parts[0], -1) == ')') {
84
return $this->parse(substr($parts[0], 1, -1));
86
// Processing NOT here
87
if (strtoupper(substr($parts[0], 0, 4)) === 'NOT ') {
88
$r = 'NOT ('.$this->parse(substr($parts[0], 4)).')';
90
return $this->load($parts[0]);
96
return '(' . $r . ')';
100
* parses a literal value and returns the parsed value
102
* boolean literals are parsed to integers
103
* components are parsed to associated table aliases
105
* @param string $value literal value to be parsed
108
public function parseLiteralValue($value)
110
// check that value isn't a string
111
if (strpos($value, '\'') === false) {
113
$value = $this->query->getConnection()
114
->dataDict->parseBoolean($value);
116
$a = explode('.', $value);
119
// either a float or a component..
121
if ( ! is_numeric($a[0])) {
123
$field = array_pop($a);
124
$reference = implode('.', $a);
125
$value = $this->query->getConnection()->quoteIdentifier($this->query->getTableAlias($reference). '.' . $field);
129
// string literal found
b'\\ No newline at end of file'