00001
00002
00003
00004
00005
00006 #include "SQLtoSQLPredicateTree.h"
00007
00008 using namespace LcgInfo;
00009 using namespace std;
00010
00011
00012
00013
00014
00015
00016 SQLtoSQLPredicateTree::SQLtoSQLPredicateTree()
00017 :SQLPredicateTree(){
00018 }
00019
00020 SQLtoSQLPredicateTree::~SQLtoSQLPredicateTree(){
00021 }
00022
00023
00024 SQLtoSQLPredicateTree* SQLtoSQLPredicateTree::create(){
00025 return new SQLtoSQLPredicateTree();
00026 }
00027
00028 SQLtoSQLPredicateTree * SQLtoSQLPredicateTree::clone(){
00029 SQLtoSQLPredicateTree * aux=create();
00030
00031
00032 aux->setValue(value());
00033 aux->setType(type());
00034 aux->setDepth(depth());
00035
00036
00037 if(left()!=NULL)
00038 aux->setLeft(left()->clone());
00039 else
00040 aux->setLeft(NULL);
00041 if(right()!=NULL)
00042 aux->setRight(right()->clone());
00043 else
00044 aux->setRight(NULL);
00045
00046 return aux;
00047 }
00048
00049 string SQLtoSQLPredicateTree::evaluate(vector<string> & pQueries){
00050 vector<string> result;
00051 string aux;
00052 switch (this->type()){
00053 case COMPARISON:
00054 aux=left()->evaluate(pQueries) + ' ' + this->value() + ' ' + right()->evaluate(pQueries);
00055 break;
00056
00057 case BOOLEAN:
00058 if (nocaseCompare(this->value(),"NOT"))
00059 aux="NOT " + right()->evaluate(pQueries);
00060 else{
00061
00062 if((right()==0)&&(left()==0)) return "";
00063 if(right()==0) aux = left()->evaluate(pQueries);
00064 else if(left()==0) aux = right()->evaluate(pQueries);
00065 else{
00066 aux=left()->evaluate(pQueries) + ' ';
00067 aux += this->value() + ' ' + right()->evaluate(pQueries);
00068 }
00069 }
00070 break;
00071
00072 case LEAF:
00073 return this->value();
00074 }
00075
00076 if(aux.empty()){
00077 string msg="Parsing error. The node could not be evaluated.";
00078 msg += "\nThis node's value: " + value() + "\nThis node's depth: " + int2str(depth());
00079 throw QueryTranslationException(msg,__FILE__,__LINE__);
00080 }
00081
00082 if(depth()>0) aux='('+aux+')';
00083 return aux;
00084 };