using tree index
[csql.git] / include / Parser.h
blobc196b11daf99f8afe5317c2f93bec07c33b77c90
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef PARSER_H
21 #define PARSER_H
22 #include <CSql.h>
23 #include <AggTableImpl.h>
24 #include <os.h>
25 #include <Util.h>
26 enum StatementType
28 UnknownStatement,
29 SelectStatement,
30 InsertStatement,
31 UpdateStatement,
32 DeleteStatement,
33 CreateTableStatement,
34 DropTableStatement,
35 CreateIndexStatement,
36 DropIndexStatement
39 struct FieldValue
41 char fldName[IDENTIFIER_LENGTH];
42 char *parsedString;
43 void *value;
44 int paramNo; // 0 ->not a param. It stores the param position
45 DataType type;
46 int length;
47 bool isAllocVal;
51 struct ConditionValue
53 char *parsedString;
54 void *value;
55 int paramNo; // 0 ->not a param. It stores the param position
56 DataType type;
57 int length;
58 bool opLike;
59 char fName[IDENTIFIER_LENGTH];
62 struct FieldName
64 char fldName[IDENTIFIER_LENGTH];
65 AggType aType; //used only in case of select projection
66 FieldName()
68 strcpy(fldName,"");
69 aType = AGG_UNKNOWN;
73 struct UpdateFieldValue
75 char fldName[IDENTIFIER_LENGTH];
76 char *parsedString;
77 void *value;
78 DataType type;
79 int length;
80 int paramNo;
84 class ParsedData
86 private:
87 char tblName[IDENTIFIER_LENGTH];
88 char idxName[IDENTIFIER_LENGTH];
90 StatementType stmtType;
92 int paramCounter;
94 //holds pointer to field names. used in insert to store field name list
95 //and for projection list of select
96 //also used to store primary or unique key fields in create statement
97 List fieldNameList;
99 List groupFieldNameList;
101 //holds pointer to condition values.
102 List conditionValueList;
104 //holds pointer to field values. used in insert to store field values
105 //used in update to store the current value returned by fetch().This gets replaced
106 //by value in updFldValList and then update() is called.
107 List fieldValueList;
109 //used to store IN values of SELECT statement
110 //This should be a list of list. so that multiple IN shall be present
111 //in the select statement
112 List inValueList;
114 //update field value list. used to store the values to be updated
115 //value in the SET clause of UPDATE statement is stored here.
116 List updFldValList;
118 //stores the where clause condition for SELECT, UPDATE and DELETE
119 Condition predicate;
121 //stores field information in CREATE TABLE
122 FieldDef fldDef;
124 //stores list of fields for CREATE TABLE
125 FieldList creFldList;
127 //stores index information
128 bool isUnique;
129 bool isPrimary;
130 IndexType indexType;
132 public:
133 ParsedData() { paramCounter = 0; stmtType = UnknownStatement;
134 isUnique = false; isPrimary = false; indexType = hashIndex;}
135 void setStmtType(StatementType type) { stmtType = type; }
136 void setTableName(char *name) { strcpy(tblName, name); }
137 void setIndexName(char *name) { strcpy(idxName, name); }
139 char* getTableName() { return tblName; }
140 char* getIndexName() { return idxName; }
142 void insertValue(char *value);
143 void insertInValue(char *value);
144 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
145 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
146 // _ is converted to ? before it is processed
147 void** insertCondValueAndGetPtr(char *fName, char *value, bool opLike=false);
148 void insertUpdateValue(char *fldName, char *value);
150 void insertField(char *fName, AggType aggType= AGG_UNKNOWN);
151 void insertGroupField(char *fName);
152 void clearFieldNameList();
155 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
156 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
157 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
158 void setCondition(Predicate *pred)
160 //No body is deleting memory allocated during condition::setTerm for PredicateImpl
161 //have list in this pared data and delete it during reset
162 predicate.setPredicate(pred);
164 Condition* getCondition() { return &predicate; }
166 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
168 List getFieldNameList() { return fieldNameList; }
169 List getGroupFieldNameList() { return groupFieldNameList; }
170 List getConditionValueList() { return conditionValueList; }
171 List getFieldValueList() { return fieldValueList; }
172 List getInValueList() { return inValueList; }
173 List getUpdateFieldValueList() { return updFldValList; }
175 void setFldName(char *name);
176 void setFldType(DataType type);
177 void setFldLength(size_t length);
178 void setDefaultValue(char * value);
179 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
180 void setFldNotNull(bool notNull);
182 void setUnique(bool unique){ isUnique = unique; }
183 void setPrimary(bool primary) { isPrimary = primary; }
184 void setIndexType (IndexType type) { indexType = type; }
185 IndexType getIndexType(){ return indexType; }
186 bool getUnique() { return isUnique; }
187 bool getPrimary() { return isPrimary; }
189 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
191 FieldList getCreFldList() { return creFldList; }
193 StatementType getStmtType() { return stmtType; }
195 void reset();
199 #endif
201 //TODO: Aruna
202 //variable and function names suck, change if u want to
203 //setFldDefaultValue
204 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
205 //primary key
206 //foreign key