001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.sql.exp.op;
020
021import lucee.runtime.sql.exp.Expression;
022import lucee.runtime.sql.exp.ExpressionSupport;
023
024public class Operation3 extends ExpressionSupport implements Operation {
025
026        private Expression exp;
027        private Expression left;
028        private Expression right;
029        private int operator;
030
031
032        public Operation3(Expression exp, Expression left, Expression right, int operator) {
033                this.exp=exp;
034                this.left=left;
035                this.right=right;
036                this.operator=operator;
037        }
038
039        public String toString(boolean noAlias) {
040                // like escape
041                if(Operation.OPERATION3_LIKE==operator){
042                        if(!hasAlias() || noAlias) {
043                                return exp.toString(true)+" like "+
044                                                left.toString(true)+" escape "+
045                                                right.toString(true);
046                        }
047                        return toString(true)+" as "+getAlias();
048                }
049                // between
050                if(!hasAlias() || noAlias) {
051                        return exp.toString(true)+" between "+left.toString(true)+" and "+right.toString(true);
052                }
053                return toString(true)+" as "+getAlias();
054        }
055
056        /**
057         * @return the exp
058         */
059        public Expression getExp() {
060                return exp;
061        }
062
063        /**
064         * @return the left
065         */
066        public Expression getLeft() {
067                return left;
068        }
069
070        /**
071         * @return the operator
072         */
073        public int getOperator() {
074                return operator;
075        }
076
077        /**
078         * @return the right
079         */
080        public Expression getRight() {
081                return right;
082        }
083}