include/Parser.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Prabakaran Thirumalai   *
00003  *   praba_tuty@yahoo.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef PARSER_H
00021 #define PARSER_H
00022 #include <CSql.h>
00023 #include <os.h>
00024 #include <Util.h>
00025 enum StatementType
00026 {
00027     UnknownStatement,
00028     SelectStatement,
00029     InsertStatement,
00030     UpdateStatement,
00031     DeleteStatement,
00032     CreateTableStatement,
00033     DropTableStatement,
00034     CreateIndexStatement,
00035     DropIndexStatement
00036 };
00037 
00038 struct FieldValue
00039 {
00040     char *parsedString;
00041     void *value;
00042     int paramNo; // 0 ->not a param. It stores the param position
00043     DataType type;
00044     int length;
00045 };
00046 
00047 
00048 struct ConditionValue
00049 {
00050     char *parsedString;
00051     void *value;
00052     int paramNo; // 0 ->not a param. It stores the param position
00053     DataType type;
00054     int length;
00055     char fName[IDENTIFIER_LENGTH];
00056 };
00057 
00058 struct FieldName
00059 {
00060     char fldName[IDENTIFIER_LENGTH];
00061 };
00062 
00063 struct UpdateFieldValue
00064 {
00065     char fldName[IDENTIFIER_LENGTH];
00066     char *parsedString;
00067     void *value;
00068     DataType type;
00069     int length;
00070     int paramNo;
00071 };
00072 
00073 
00074 class ParsedData
00075 {
00076     private:
00077     char tblName[IDENTIFIER_LENGTH];
00078     char idxName[IDENTIFIER_LENGTH];
00079 
00080     StatementType stmtType;
00081   
00082     int paramCounter;
00083 
00084     //holds pointer to field names. used in insert to store field name list
00085     //and for projection list of select
00086     //also used to store primary or unique key fields in create statement
00087     List fieldNameList;
00088 
00089     //holds pointer to condition values.
00090     List conditionValueList;
00091 
00092     //holds pointer to field values. used in insert to store field values
00093     //used in update to store the current value returned by fetch().This gets replaced 
00094     //by value in updFldValList and then update() is called.
00095     List fieldValueList;
00096 
00097     //used to store IN values of SELECT statement
00098     //This should be a list of list. so that multiple IN shall be present
00099     //in the select statement
00100     List inValueList;
00101 
00102     //update field value list. used to store the values to be updated
00103     //value in the SET clause of UPDATE statement is stored here.
00104     List updFldValList;
00105 
00106     //stores the where clause condition for SELECT, UPDATE and DELETE
00107     Condition predicate;
00108     
00109     //stores field information in CREATE TABLE
00110     FieldDef fldDef;
00111 
00112     //stores list of fields for CREATE TABLE
00113     FieldList creFldList;
00114 
00115     //stores index information
00116     bool isUnique;
00117     bool isPrimary;
00118     IndexType indexType;
00119 
00120     public:
00121     ParsedData() { paramCounter = 0; stmtType = UnknownStatement; 
00122                  isUnique = false; isPrimary = false; indexType = hashIndex;} 
00123     void setStmtType(StatementType type) { stmtType = type; }
00124     void setTableName(char *name) { strcpy(tblName, name); }
00125     void setIndexName(char *name) { strcpy(idxName, name); }
00126 
00127     char* getTableName() { return tblName; }
00128     char* getIndexName() { return idxName; }
00129 
00130     void insertValue(char *value);
00131     void insertInValue(char *value);
00132     void** insertCondValueAndGetPtr(char *fName, char *value);
00133     void insertUpdateValue(char *fldName, char *value);
00134 
00135     void insertField(char *fName);
00136     void clearFieldNameList();
00137 
00138 
00139     Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
00140     Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
00141     Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
00142     void setCondition(Predicate *pred) 
00143     { 
00144         //No body is deleting memory allocated during condition::setTerm for PredicateImpl 
00145         //have list in this pared data and delete it during reset
00146         predicate.setPredicate(pred); 
00147     }
00148     Condition* getCondition() { return &predicate; }
00149 
00150     void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
00151 
00152     List getFieldNameList() { return fieldNameList; }
00153     List getConditionValueList() { return conditionValueList; }
00154     List getFieldValueList() { return fieldValueList; }
00155     List getInValueList() { return inValueList; }
00156     List getUpdateFieldValueList() { return updFldValList; }
00157 
00158     void setFldName(char *name);
00159     void setFldType(DataType type);
00160     void setFldLength(size_t length);
00161     void setDefaultValue(char * value);
00162     //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
00163     void setFldNotNull(bool notNull);
00164 
00165     void setUnique(bool unique){ isUnique = unique; }
00166     void setPrimary(bool primary) { isPrimary = primary; }
00167     void setIndexType (IndexType type) { indexType = type; }
00168     IndexType getIndexType(){ return indexType; }
00169     bool getUnique() { return isUnique; }
00170     bool getPrimary() { return isPrimary; }
00171 
00172     void insertFldDef(); //check if fldDef needs to be a part of ParsedData 
00173     
00174     FieldList getCreFldList() { return creFldList; }
00175 
00176     StatementType getStmtType() { return stmtType; }
00177 
00178     void reset();
00179 
00180 };
00181 
00182 #endif
00183 
00184 //TODO: Aruna
00185 //variable and function names suck, change if u want to
00186 //setFldDefaultValue
00187 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
00188 //primary key
00189 //foreign key

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7