3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\ORM\Persisters;
22 use Doctrine\Common\Collections\Expr\ExpressionVisitor;
23 use Doctrine\Common\Collections\Expr\Comparison;
24 use Doctrine\Common\Collections\Expr\Value;
25 use Doctrine\Common\Collections\Expr\CompositeExpression;
28 * Visit Expressions and generate SQL WHERE conditions from them.
30 * @author Benjamin Eberlei <kontakt@beberlei.de>
33 class SqlExpressionVisitor extends ExpressionVisitor
36 * @var \Doctrine\ORM\Persisters\BasicEntityPersister
41 * @param \Doctrine\ORM\Persisters\BasicEntityPersister $persister
43 public function __construct(BasicEntityPersister $persister)
45 $this->persister = $persister;
49 * Convert a comparison expression into the target query language output
51 * @param \Doctrine\Common\Collections\Expr\Comparison $comparison
55 public function walkComparison(Comparison $comparison)
57 $field = $comparison->getField();
58 $value = $comparison->getValue()->getValue(); // shortcut for walkValue()
60 return $this->persister->getSelectConditionStatementSQL($field, $value, null, $comparison->getOperator());
64 * Convert a composite expression into the target query language output
66 * @param \Doctrine\Common\Collections\Expr\CompositeExpression $expr
70 public function walkCompositeExpression(CompositeExpression $expr)
72 $expressionList = array();
74 foreach ($expr->getExpressionList() as $child) {
75 $expressionList[] = $this->dispatch($child);
78 switch($expr->getType()) {
79 case CompositeExpression::TYPE_AND:
80 return '(' . implode(' AND ', $expressionList) . ')';
82 case CompositeExpression::TYPE_OR:
83 return '(' . implode(' OR ', $expressionList) . ')';
86 throw new \RuntimeException("Unknown composite " . $expr->getType());
91 * Convert a value expression into the target query language part.
93 * @param \Doctrine\Common\Collections\Expr\Value $value
97 public function walkValue(Value $value)