123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985 |
- /*##############################################################################
- HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ############################################################################## */
- #ifndef SQLEXPRESSION_HPP_
- #define SQLEXPRESSION_HPP_
- #include "ws_sql.hpp"
- #include "SQLColumn.hpp"
- #include "ECLFunction.hpp"
- /* undef SOCKET definitions to avoid collision in Antlrdefs.h*/
- #ifdef INVALID_SOCKET
- //#pragma message( "UNDEFINING INVALID_SOCKET - Will be redefined by ANTLRDEFS.h" )
- #undef INVALID_SOCKET
- #endif
- #ifdef SOCKET
- //#pragma message( "UNDEFINING SOCKET - Will be redefined by ANTLRDEFS.h" )
- #undef SOCKET
- #endif
- #include "HPCCSQLLexer.h"
- /* undef SOCKET definitions to avoid collision in Antlrdefs.h*/
- typedef enum _SQLExpressionType
- {
- Unary_ExpressionType,
- FieldValue_ExpressionType,
- Fields_ExpressionType,
- Parenthesis_ExpressionType,
- Value_ExpressionType,
- Binary_ExpressionType,
- ParameterPlaceHolder_ExpressionType,
- Function_ExpressionType,
- List_ExpressionType
- } SQLExpressionType;
- typedef enum _SQLLogicType
- {
- Unknown_LogicType=-1,
- Bool_LogicType,
- String_LogicType,
- QSstring_LogicType,
- Unicode_LogicType,
- Numeric_LogicType,
- Integer_LogicType,
- Decimal_LogicType,
- NestedDS_LogicType
- } SQLLogicType;
- interface ISQLExpression : public CInterface, public IInterface
- {
- public:
- IMPLEMENT_IINTERFACE;
- /*
- * Reports whether this expression contains reference to field 'colname'.
- * @param String name of column
- *
- * @return bool Reports whether this expression contains reference to field 'colname'.
- */
- virtual bool containsKey(const char * colname) = 0;
- /*
- * appends string representation of this SQLExpression, fully qualifies field values
- * depending on input param's value.
- * @param boolean Fully qualify field values.
- *
- * @return appends string Representation of this SQLExpression, fields fully-qualified baed on in param.
- */
- virtual void toString(StringBuffer & targetstr, bool fullOutput) = 0;
- /*
- * Returns number of field value expressions contained within SQL Expression.
- *
- * @return int number of field value expressions contained within SQL Expression.
- */
- virtual int getExpressionsCount() = 0;
- /*
- * Translates SQLExpression to ECL in flat string form.
- * @param map IProperties containing source table names as keys and its translation target
- * @param ignoreMistranslations option to continue translating expression even if
- * current expression contains table.field where table not found in map
- * @param forHaving option to translate for ECL HAVING function
- * @param funcParam option specifying if expression to be translated is a function parameter
- * @param countFuncParam option specifying if expression to be translated is an ECL Count() parameter
- *
- * @return appends string ECL consumable representation of expression.
- */
- virtual void toECLStringTranslateSource(StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam)=0;
- /*
- * Reports if this SQL expression contains an equality condition between table first and second.
- *
- * @param map IProperties containing source table names and their possible ECL translation
- * @param String Name of first table.
- * @param String Name of second table.
- * @return bool True if this expression was found to contain equality condition between
- * table 'first' and table 'second'.
- */
- virtual bool containsEqualityCondition(IProperties * map, const char * first, const char * second)
- {
- return false;
- }
- /*
- * Attempts to label each parameterized expression placeholder, increases the
- * running index value by the number of param placeholder processed.
- *
- * @param int currentindex index used to as postfix for placeholder label
- *
- * @return int running index value. To be used for next param placeholder label.
- */
- virtual int setParameterizedNames(int currentindex)=0;
- virtual bool needsColumnExpansion() { return false;}
- virtual void appendField(ISQLExpression * field){}
- virtual void setECLType(const char * type) {UNIMPLEMENTED;}
- virtual const char * getECLType() {UNIMPLEMENTED; return nullptr;}
- virtual const char * getName() {UNIMPLEMENTED; return nullptr;}
- virtual void setName(const char * name) {UNIMPLEMENTED;}
- virtual const char * getNameOrAlias() {UNIMPLEMENTED; return nullptr;}
- virtual void setAlias(const char * alias) {UNIMPLEMENTED;}
- virtual const char * getAlias() {UNIMPLEMENTED; return nullptr;}
- virtual SQLExpressionType getExpType()=0;
- virtual SQLLogicType getLogicType(){UNIMPLEMENTED; return Unknown_LogicType;};
- virtual void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype){UNIMPLEMENTED;};
- virtual void getUniqueExpressionColumnNames(StringArray & uniquenames)=0;
- virtual void getExpressionFromColumnName(const char * colname, StringBuffer & str)=0;
- /*
- * Instructs this expression to be replaced by a typed place holder.
- *
- * The purpose of this value placeholder replacement (parameterization)
- * could be exploited for query normalization, query caching optimization,
- * query publishing, etc.
- */
- virtual bool setValuePlaceHolderType(const char * ecltype){UNIMPLEMENTED; return false;};
- /*
- * Has this expression been provided a placeholder type?
- *
- * select * from t1 where f1 = 5; <- the right side of the binary expression f1 = 5 can be
- * parameterized as f1 = ${f1.ecltype}
- */
- virtual bool hasPlaceHolder(){return false;}
- /*
- * Get this placeholder inferred type
- *
- * select * from t1 where f1 = 5; <- the right side of the binary expression f1 = 5 can be
- * parameterized as f1 = ${f1.ecltype}
- * This allows caching of query structure
- */
- virtual const char * getPlaceHolderType(){UNIMPLEMENTED; return nullptr;}
- /*
- * Get this placeholder's generated name
- */
- virtual const char * getPlaceHolderName(){UNIMPLEMENTED; return nullptr;}
- static SQLLogicType getLogicTypeFromName(const char * type)
- {
- if (!type || !*type)
- return Unknown_LogicType;
- if (strnicmp(type,"STRING",6)==0)
- return String_LogicType;
- else if (strnicmp(type,"QSTRING",7)==0)
- return QSstring_LogicType;
- else if (strnicmp(type,"UNICODE",7)==0)
- return Unicode_LogicType;
- else if (strnicmp(type,"VARUNICODE",10)==0)
- return Unicode_LogicType;
- else if (strnicmp(type,"VARSTRING",9)==0)
- return String_LogicType;
- else if (strnicmp(type,"BOOLEAN",7)==0)
- return Bool_LogicType;
- else if (strnicmp(type,"UNSIGNED",8)==0)
- return Integer_LogicType;
- else if (strnicmp(type,"REAL",4)==0)
- return Decimal_LogicType;
- else if (strnicmp(type,"DECIMAL",7)==0)
- return Decimal_LogicType;
- else if (strnicmp(type,"DATASET",7)==0)
- return NestedDS_LogicType;
- else
- return Unknown_LogicType;
- }
- };
- /*************************************************************************************************/
- class SQLListExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- SQLListExpression();
- virtual ~SQLListExpression();
- void getExpressionFromColumnName(const char * colname, StringBuffer & str);
- void getUniqueExpressionColumnNames(StringArray & uniquenames);
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype);
- SQLLogicType getLogicType();
- int setParameterizedNames(int currentindex);
- void toECLStringTranslateSource(StringBuffer & eclStr, IProperties * map, bool ignoreMisTranslations, bool forHaving, bool funcParam, bool countFuncParam);
- SQLExpressionType getExpType() { return List_ExpressionType;}
- bool containsKey(const char* colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getExpressionsCount();
- void appendEntry(ISQLExpression * entry);
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- IArrayOf<ISQLExpression> entries;
- };
- /*************************************************************************************************/
- class SQLUnaryExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str);
- void getUniqueExpressionColumnNames(StringArray & uniquenames)
- {
- operand1->getUniqueExpressionColumnNames(uniquenames);
- }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- operand1->eclDeclarePlaceHolders(eclstr, op, sibtype);
- }
- SQLLogicType getLogicType(){ return operand1->getLogicType();}
- int setParameterizedNames(int currentindex)
- {
- return operand1->setParameterizedNames(currentindex);
- }
- void toECLStringTranslateSource(StringBuffer & eclStr, IProperties * map, bool ignoreMisTranslations, bool forHaving, bool funcParam, bool countFuncParam);
- bool containsEqualityCondition(IProperties * map, const char * first, const char * second);
- SQLExpressionType getExpType() { return Unary_ExpressionType;}
- SQLUnaryExpression();
- SQLUnaryExpression(ISQLExpression* operand1, int opname);
- virtual ~SQLUnaryExpression();
- bool containsKey(const char* colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getOp() const
- {
- return op;
- }
- void setOp(int op)
- {
- this->op = op;
- }
- ISQLExpression* getOperand1() const
- {
- return operand1;
- }
- void setOperand1(ISQLExpression* operand1)
- {
- this->operand1 = operand1;
- }
- int getExpressionsCount() { return operand1->getExpressionsCount();}
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- ISQLExpression * operand1;
- int op;
- };
- /*************************************************************************************************/
- class SQLFieldValueExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str)
- {
- if(stricmp(getName(),colname)==0)
- toString(str, false);
- }
- void getUniqueExpressionColumnNames(StringArray & uniquenames)
- {
- uniquenames.appendUniq(getName());
- }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype) {return;}
- SQLLogicType getLogicType();
- virtual int setParameterizedNames(int currentindex)
- {
- return currentindex;
- }
- void toECLStringTranslateSource(StringBuffer & eclStr, IProperties * map, bool ignoreMisTranslations, bool forHaving, bool funcParam, bool countFuncParam);
- SQLExpressionType getExpType() { return FieldValue_ExpressionType;}
- SQLFieldValueExpression();
- SQLFieldValueExpression(const char * parentTableName, const char * fieldName);
- virtual ~SQLFieldValueExpression();
- const char * getParentTableName();
- void setParentTableName(const char * parentTableName);
- const char * getName();
- void setName(const char * name);
- const char * getAlias();
- void setAlias(const char * alias);
- bool isAscending();
- void setAscending(bool ascending);
- bool containsKey(const char * colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getExpressionsCount() { return 1;}
- bool isAliasOrName(const char * possiblenameoralias);
- void setECLType(const char * type);
- const char * getECLType();
- const char * getNameOrAlias();
- SQLColumn * queryField()
- {
- return &field;
- }
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- SQLColumn field;
- };
- /*************************************************************************************************/
- class SQLFieldsExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str){ UNIMPLEMENTED_X("This method should never be accessed for SQLFieldsExpression!");}
- void getUniqueExpressionColumnNames(StringArray & uniquenames){ UNIMPLEMENTED_X("Method SQLFieldsExpression::getUniqueExpressionColumnNames should never be accessed!");}
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype) {return;}
- virtual SQLLogicType getLogicType(){return Unknown_LogicType;}
- virtual int setParameterizedNames(int currentindex)
- {
- return currentindex;
- }
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam) { UNIMPLEMENTED_X("This method should never be accessed for SQLFieldsExpression!");}
- SQLExpressionType getExpType() { return Fields_ExpressionType;}
- SQLFieldsExpression(bool allfiles);
- SQLFieldsExpression(const char * table);
- virtual ~SQLFieldsExpression();
- int getExpressionsCount() { return 1;}
- void toString(StringBuffer & targetstr, bool fullOutput);
- bool containsKey(const char * colname) {return false;}
- bool isAll() const
- {
- return all;
- }
- void setAll(bool all)
- {
- this->all = all;
- }
- const char* getTable() const
- {
- return this->table.str();
- }
- void setTable(const char* table)
- {
- this->table.set(table);
- }
- bool needsColumnExpansion() { return !isExpanded; }
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- StringBuffer table;
- bool all;
- bool isExpanded;
- };
- /*************************************************************************************************/
- class SQLParenthesisExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str)
- {
- StringBuffer result1;
- innerexpression->getExpressionFromColumnName(colname, result1);
- //if (result1.length > 0 )
- str.appendf("( %s )", result1.str());
- }
- void getUniqueExpressionColumnNames(StringArray & uniquenames)
- {
- innerexpression->getUniqueExpressionColumnNames(uniquenames);
- }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- innerexpression->eclDeclarePlaceHolders(eclstr, op, sibtype);
- }
- virtual SQLLogicType getLogicType(){return innerexpression->getLogicType();}
- virtual int setParameterizedNames(int currentindex)
- {
- return innerexpression->setParameterizedNames(currentindex);
- }
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam)
- {
- eclStr.append("( ");
- innerexpression->toECLStringTranslateSource(eclStr, map, ignoreMisTranslations, forHaving, funcParam, countFuncParam);
- eclStr.append(" )");
- }
- ISQLExpression* getInnerExp();
- SQLExpressionType getExpType() { return Parenthesis_ExpressionType;}
- SQLParenthesisExpression(ISQLExpression * exp);
- virtual ~SQLParenthesisExpression();
- bool containsKey(const char * colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getExpressionsCount() { return innerexpression->getExpressionsCount();}
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- ISQLExpression* innerexpression;
- };
- /*************************************************************************************************/
- class SQLValueExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str)
- {
- str.appendf(" %s ", value.str());
- }
- void getUniqueExpressionColumnNames(StringArray & uniquenames) { return; }
- virtual SQLLogicType getLogicType()
- {
- return ISQLExpression::getLogicTypeFromName(field.getColumnType());
- }
- virtual int setParameterizedNames(int currentindex);
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam);
- SQLExpressionType getExpType() { return Value_ExpressionType;}
- SQLValueExpression();
- SQLValueExpression(int type, const char * value);
- virtual ~SQLValueExpression();
- bool containsKey(const char * colname) {return false;}
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getType() const
- {
- return type;
- }
- void setType(int type)
- {
- this->type = type;
- }
- const char * getValue() const
- {
- return value.str();
- }
- void setValue(const char * value)
- {
- this->value.set(value);
- }
- int getExpressionsCount()
- {
- return 0;
- }
- virtual void trimTextQuotes();
- virtual void setECLType(const char * type);
- virtual const char * getECLType();
- virtual const char * getName();
- virtual void setName(const char * name);
- virtual const char * getNameOrAlias();
- virtual void setAlias(const char * alias);
- virtual const char * getAlias();
- bool setValuePlaceHolderType(const char * ecltype)
- {
- if (ecltype && *ecltype)
- {
- placeHolderType.set(ecltype);
- return true;
- }
- return false;
- }
- bool hasPlaceHolder(){ return placeHolderType.length() > 0;}
- const char * getPlaceHolderType() {return placeHolderType.str();}
- const char * getPlaceHolderName() {return placeHolderName.str();}
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- if(hasPlaceHolder())
- eclstr.appendf("%s %s := %s : STORED('%s');\n", placeHolderType.str(), placeHolderName.str(), value.str(), placeHolderName.str());
- if(isAWildCardPattern)
- {
- eclstr.appendf("%sTranslated := STD.Str.Translate( %s , '_%%', '?*');", placeHolderName.str(), placeHolderName.str());
- placeHolderName.append("Translated");
- }
- }
- void setIsWildCardPattern(bool isthisawildcard) {isAWildCardPattern = isthisawildcard;}
- private:
- int type; //As defined in HPCCSQLParser.h
- StringBuffer value;
- SQLColumn field;
- StringBuffer placeHolderName;
- StringBuffer placeHolderType;
- bool isAWildCardPattern;
- };
- /*************************************************************************************************/
- class SQLBinaryExpression : implements ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str)
- {
- StringBuffer result1;
- StringBuffer result2;
- operand1->getExpressionFromColumnName(colname, result1);
- if (!result1.length())
- return; // no need to waste time fetching the right sub-expression
- operand2->getExpressionFromColumnName(colname, result2);
- if (result2.length() > 0)
- str.appendf(" %s %s %s ", result1.str(), getOpStr(),result2.str());
- /* this was meant to provide sub-expressions based on the colname provided,
- * however providing the OR'ed sub-expression can be misleading and the logic
- * arithmetic can be flawed, therefore this else is taken out, but will keep within
- * comment block for reference:
- * else if (op == OR_SYM)
- {
- if (result1.length() > 0)
- str.appendf(" %s ", result1.str());
- else if (result2.length() > 0)
- str.appendf(" %s ", result2.str());
- }*/
- }
- void getUniqueExpressionColumnNames(StringArray & uniquenames)
- {
- operand1->getUniqueExpressionColumnNames(uniquenames);
- operand2->getUniqueExpressionColumnNames(uniquenames);
- }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- operand1->eclDeclarePlaceHolders(eclstr, this->op, operand2->getLogicType());
- operand2->eclDeclarePlaceHolders(eclstr, this->op, operand1->getLogicType());
- }
- virtual SQLLogicType getLogicType()
- {
- switch (op)
- {
- case AND_SYM:
- case OR_SYM:
- return Bool_LogicType;
- case DIVIDE:
- case GTH:
- case GET:
- case LTH:
- case LET:
- case MINUS:
- case MOD:
- case ASTERISK:
- case PLUS:
- return Numeric_LogicType;
- case EQ_SYM:
- case NOT_EQ:
- case IN_SYM:
- case NOT_IN:
- {
- SQLLogicType op1type =operand1->getLogicType();
- SQLLogicType op2type =operand2->getLogicType();
- if (op1type != Unknown_LogicType)
- return op1type;
- else if (op2type != Unknown_LogicType)
- return op2type;
- else
- return Unknown_LogicType;
- }
- default:
- return Unknown_LogicType;
- }
- }
- virtual int setParameterizedNames(int currentindex);
- bool isEqualityCondition(IProperties * map, const char * first, const char * second);
- virtual bool containsEqualityCondition(IProperties * map, const char * first, const char * second);
- static bool containsEqualityCondition(ISQLExpression* operand, IProperties * map, const char * first, const char * second);
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam);
- SQLExpressionType getExpType() { return Binary_ExpressionType;}
- SQLBinaryExpression(int op,ISQLExpression* operand1,ISQLExpression* operand2);
- virtual ~SQLBinaryExpression();
- bool containsKey(const char * colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getExpressionsCount();
- int getOp() const
- {
- return op;
- }
- void setOp(int op)
- {
- this->op = op;
- }
- ISQLExpression* getOperand1() const
- {
- return operand1;
- }
- void setOperand1(ISQLExpression* operand1)
- {
- this->operand1 = operand1;
- }
- ISQLExpression* getOperand2() const
- {
- return operand2;
- }
- void setOperand2(ISQLExpression* operand2)
- {
- this->operand2 = operand2;
- }
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- const char * getOpStr();
- ISQLExpression* operand1;
- ISQLExpression* operand2;
- int op;
- };
- /*************************************************************************************************/
- class SQLParameterPlaceHolderExpression : implements ISQLExpression
- {
- public:
- static const char * PARAMPREFIX;
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str) { return; }
- void getUniqueExpressionColumnNames(StringArray & uniquenames) { return; }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- StringBuffer defaulteclvalue;
- switch (op)
- {
- case AND_SYM:
- case OR_SYM:
- eclstr.append( "BOOLEAN ");
- defaulteclvalue.set(" FALSE ");
- break;
- case DIVIDE:
- case MINUS:
- case MOD:
- case ASTERISK:
- case GTH:
- case GET:
- case LTH:
- case LET:
- case PLUS:
- case EQ_SYM:
- case NOT_EQ:
- case IN_SYM:
- case NOT_IN:
- {
- switch (sibtype)
- {
- case Bool_LogicType:
- eclstr.append( "BOOLEAN ");
- defaulteclvalue.set(" FALSE ");
- break;
- case Numeric_LogicType:
- case Integer_LogicType:
- eclstr.append( "INTEGER ");
- defaulteclvalue.set(" 0 ");
- break;
- case Decimal_LogicType:
- eclstr.append( "DECIMAL ");
- defaulteclvalue.set(" 0.0 ");
- break;
- case QSstring_LogicType:
- eclstr.append( "QSTRING ");
- defaulteclvalue.set(" '' ");
- break;
- case Unicode_LogicType:
- eclstr.append( "UNICODE");
- defaulteclvalue.set(" '' ");
- break;
- case String_LogicType:
- default:
- eclstr.append( "STRING ");
- defaulteclvalue.set(" '' ");
- break;
- }
- break;
- }
- default:
- eclstr.append( "STRING ");
- defaulteclvalue.set(" '' ");
- break;
- }
- eclstr.append(value.str());
- eclstr.append(" := ");
- eclstr.append(defaulteclvalue.str());
- eclstr.append(" : STORED('");
- eclstr.append(value.str());
- eclstr.append("');\n");
- }
- virtual SQLLogicType getLogicType(){return Unknown_LogicType;}
- virtual int setParameterizedNames(int currentindex);
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam)
- {
- eclStr.append( value.str() );
- }
- SQLExpressionType getExpType()
- {
- return ParameterPlaceHolder_ExpressionType;
- }
- SQLParameterPlaceHolderExpression();
- virtual ~SQLParameterPlaceHolderExpression ();
- bool containsKey(const char * colname) {return false;}
- void toString(StringBuffer & targetstr, bool fullOutput);
- int getExpressionsCount() {return 0;}
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- int index;
- StringBuffer value;
- };
- /*************************************************************************************************/
- class SQLFunctionExpression : public ISQLExpression
- {
- public:
- IMPLEMENT_IINTERFACE;
- void getExpressionFromColumnName(const char * colname, StringBuffer & str)
- {
- StringBuffer paramlist;
- StringBuffer paramresult;
- for (int i = 0; i < params.length(); i++)
- {
- params.item(i).getExpressionFromColumnName(colname, paramresult.clear());
- if (paramresult.length() <= 0)
- return;
- if ( i > 0 )
- paramlist.append(", ");
- paramlist.append(paramresult);
- }
- if (paramlist.length()>0)
- str.appendf(" %s( %s ) ", function.eclFunctionName, paramlist.str());
- }
- void getUniqueExpressionColumnNames(StringArray & uniquenames)
- {
- ForEachItemIn(paramidx , params)
- {
- ISQLExpression & param = params.item(paramidx);
- param.getUniqueExpressionColumnNames(uniquenames);
- }
- }
- void eclDeclarePlaceHolders(StringBuffer & eclstr, int op, int sibtype)
- {
- ForEachItemIn(paramidx , params)
- {
- ISQLExpression & param = params.item(paramidx);
- param.eclDeclarePlaceHolders(eclstr, op, sibtype);
- }
- }
- SQLLogicType getLogicType()
- {
- if (strcmp(function.returnType,"NUMERIC")==0)
- {
- if (params.length()>0)
- return params.item(0).getLogicType();
- else
- return Numeric_LogicType;
- }
- else if (strcmp(function.returnType,"INTEGER")==0)
- return Integer_LogicType;
- else
- return String_LogicType;
- }
- int setParameterizedNames(int currentindex);
- void toECLStringTranslateSource(
- StringBuffer & eclStr,
- IProperties * map,
- bool ignoreMisTranslations,
- bool forHaving,
- bool funcParam,
- bool countFuncParam);
- SQLExpressionType getExpType() { return Function_ExpressionType;}
- SQLFunctionExpression(const char* funcname);
- SQLFunctionExpression(const char* funcname, const IArrayOf<ISQLExpression> ¶ms);
- virtual ~SQLFunctionExpression();
- bool containsKey(const char* colname);
- void toString(StringBuffer & targetstr, bool fullOutput);
- void setName(const char * funcname)
- {
- name.set(funcname);
- }
- void setNameAndDefaultAlias(const char * funcname)
- {
- name.set(funcname);
- alias.set(funcname);
- alias.append("Out");
- }
- const char * getName()
- {
- return name.str();
- }
- ECLFunctionDefCfg getFunction() const
- {
- return function;
- }
- void setFunction(const char * funcname)
- {
- this->function = ECLFunctions::getEclFuntionDef(funcname);
- }
- IArrayOf<ISQLExpression> * getParams()
- {
- return ¶ms;
- }
- virtual const char * getAlias();
- virtual void setAlias(const char * alias);
- virtual const char * getNameOrAlias();
- void addParams(ISQLExpression * param)
- {
- this->params.append(*param);
- }
- int getExpressionsCount();
- bool isDistinct() {return distinct;}
- void setDistinct(bool d) {distinct = d;}
- bool setValuePlaceHolderType(const char * ecltype){return false;}
- bool hasPlaceHolder(){ return false;}
- const char * getPlaceHolderType() {return nullptr;}
- private:
- bool distinct;
- StringBuffer name;
- StringBuffer alias;
- ECLFunctionDefCfg function;
- IArrayOf<ISQLExpression> params;
- void getParamsString(StringBuffer & targetstr, bool fullOutput);
- };
- #endif /* SQLEXPRESSION_HPP_ */
|