CSQL_CONFIG_FILE could not be fetched from apache
[csql.git] / include / Parser.h
blob6ada73b1ef952975f591ac2b41b61046010f2e57
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 <JoinTableImpl.h>
25 #include <os.h>
26 #include <Util.h>
27 #ifndef STMT_TYPE
28 #define STMT_TYPE
29 enum StatementType
31 UnknownStatement,
32 SelectStatement,
33 InsertStatement,
34 UpdateStatement,
35 DeleteStatement,
36 CreateTableStatement,
37 DropTableStatement,
38 CreateIndexStatement,
39 DropIndexStatement,
40 CacheTableStatement,
41 CompactTableStatement,
42 CopyTableStatement,
43 MetaStatement,
44 UserStatement,
45 MgmtStatement
47 #endif
49 struct FieldValue
51 char fldName[IDENTIFIER_LENGTH];
52 char defValBuf[DEFAULT_VALUE_BUF_LENGTH];
53 char *parsedString;
54 void *value;
55 int paramNo; // 0 ->not a param. It stores the param position
56 DataType type;
57 AggType aType;
58 int length;
59 size_t offset;
60 bool isNullable;
61 bool isAllocVal;
62 bool isInResSet;
63 bool isPrimary;
64 bool isUnique;
65 bool isAutoIncrement;
66 bool isDefault;
70 struct ConditionValue
72 char *parsedString;
73 void *value;
74 int paramNo; // 0 ->not a param. It stores the param position
75 DataType type;
76 AggType aType;
77 int length;
78 bool opLike;
79 bool isNullable;
80 char fName[IDENTIFIER_LENGTH];
83 struct FieldName
85 char fldName[IDENTIFIER_LENGTH];
86 AggType aType; //used only in case of select projection
87 char aliasFldName[IDENTIFIER_LENGTH];
88 FieldName()
90 strcpy(fldName,"");
91 strcpy(aliasFldName,"");
92 aType = AGG_UNKNOWN;
95 struct TableName
97 char tblName[IDENTIFIER_LENGTH];
98 char aliasName[IDENTIFIER_LENGTH];
99 TableName()
101 strcpy(tblName,"");
102 strcpy(aliasName,"");
105 #ifndef JOINTYPE
106 #define JOINTYPE
107 enum JoinType
109 INNER_JOIN = 1,
110 RIGHT_JOIN,
111 LEFT_JOIN,
112 FULL_JOIN,
113 UNKNOWN_JOIN
115 #endif
117 struct JoinTypeNode
119 JoinType jType;
120 JoinTypeNode(){ jType = INNER_JOIN; }
123 struct UpdateFieldValue
125 char fldName[IDENTIFIER_LENGTH];
126 char *parsedString;
127 void *value;
128 Expression *expre;
129 DataType type;
130 int length;
131 bool isNullable;
132 int paramNo;
135 enum UserNodeType
137 CREATEUSER=0,
138 DROPUSER,
139 ALTERUSER
141 class UserNode
143 public:
144 char userName[IDENTIFIER_LENGTH];
145 char passName[IDENTIFIER_LENGTH];
146 UserNodeType type;
149 class ParsedData
151 private:
152 char tblName[IDENTIFIER_LENGTH];
153 char idxName[IDENTIFIER_LENGTH];
154 char pkTblName[IDENTIFIER_LENGTH];//This is also used as DSN name when cachestatement executed and copy table statemnet
155 StatementType stmtType;
156 bool isDistinct;
157 bool isExplain;
159 int paramCounter;
161 List tableNameList;
162 List joinTypeList;
163 //holds pointer to field names. used in insert to store field name list
164 //and for projection list of select
165 //also used to store primary or unique key fields in create statement
166 List fieldNameList;
168 List groupFieldNameList;
170 List havingFieldNameList;
172 List orderFieldNameList;
174 //holds pointer to condition values.
175 List conditionValueList;
177 List secondaryIndexFieldList;
178 //holds pointer to field values. used in insert to store field values
179 //used in update to store the current value returned by fetch().This gets replaced
180 //by value in updFldValList and then update() is called.
181 List fieldValueList;
183 //used to store IN values of SELECT statement
184 //This should be a list of list. so that multiple IN shall be present
185 //in the select statement
186 List inValueList;
188 //update field value list. used to store the values to be updated
189 //value in the SET clause of UPDATE statement is stored here.
190 List updFldValList;
192 //stores the where clause condition for SELECT, UPDATE and DELETE
193 Condition predicate;
194 Condition havingPredicate;
195 List predList;
197 //stores field information in CREATE TABLE
198 FieldDef fldDef;
199 //User Management
200 UserNode *userNode;
201 //stores list of fields for CREATE TABLE
202 FieldList creFldList;
203 //Foreign Key storage
205 List fkFieldNameList;
206 List pkFieldNameList;
207 List foreignKeyList;
208 bool isForeign;
209 bool shouldCreateTbl;
210 //stores index information
211 bool isUnique;
212 bool isPrimary;
213 bool isAutoIncrement;
214 IndexType indexType;
215 ResultSetPlan plan;
216 int bucketSize;
217 //Cache table
218 char hcondition[IDENTIFIER_LENGTH];
219 char vcondition[IDENTIFIER_LENGTH];
220 bool hCondFld;
221 bool vCondFld;
222 bool pkFld;
223 bool forceOption;
224 bool direct;
225 bool uncache;
226 bool noschema;
227 bool dsn;
228 int limit;
229 int offset;
230 bool isWorthyToCache;
231 public:
232 ParsedData() { limit = 0; offset= 0; paramCounter = 0; stmtType = UnknownStatement; isDistinct = false; isExplain=false;
233 isUnique = false; isPrimary = false; isAutoIncrement=false ;indexType = hashIndex; plan = Normal; bucketSize=0; isForeign=false; hCondFld=false; vCondFld=false;pkFld=false;forceOption=false; direct=false; uncache=false; noschema=false; dsn=false;
234 shouldCreateTbl=false; userNode = NULL; isWorthyToCache=false;
236 void createUserNode(char *name, char *password);
237 char *getUserName() { return userNode->userName; }
238 char *getPassWord() { return userNode->passName; }
239 UserNodeType getUserType() { return userNode->type; }
240 void dropUserNode(char *name);
241 void alterUserNode(char *name, char *password);
243 void setCreateTbl(){ shouldCreateTbl=true; }
244 bool getCreateTbl(){ return shouldCreateTbl; }
246 void setDSN(bool flag){ dsn = flag;}
247 bool getDSN(){ return dsn; }
248 void setNoSchema(bool flag){ noschema = flag; }
249 bool getNoSchema(){return noschema;}
250 char *getHCondition(){return hcondition;}
251 char *getVCondition(){return vcondition;}
252 void setHCondition(char *fld){ strcpy(hcondition,fld);}
253 void setVCondition(char *fld){ strcpy(vcondition,fld);}
254 void setHCondFld(bool flag){hCondFld = flag;}
255 bool getHCondFld(){return hCondFld;}
256 void setVCondFld(bool flag){vCondFld = flag;}
257 bool getVCondFld(){return vCondFld;}
258 void setPkFld(bool flag){pkFld = flag;}
259 bool getPkFld(){return pkFld;}
260 void setDirect(bool flag){direct=flag;}
261 bool getDirect(){return direct;}
262 void setUnCache(bool flag){uncache=flag;}
263 bool getUnCache(){return uncache;}
264 void setLimit(int l, int o) { limit =l; offset=o; }
265 int getLimit(){ return limit; }
266 int getOffset(){ return offset; }
269 int getBucketSize(){return bucketSize; };
270 void setBucketSize(int bucket){ bucketSize = bucket; };
271 void setStmtType(StatementType type) { stmtType = type; }
272 void setTableName(char *name) { strcpy(tblName, name); }
273 void setIndexName(char *name) { strcpy(idxName, name); }
274 void setPKTableName(char *name){strcpy(pkTblName, name); }
275 void setResultSetPlan(ResultSetPlan pl){plan = pl;}
276 ResultSetPlan getResultSetPlan(){return plan;}
277 char* getTableName() { return tblName; }
278 char* getIndexName() { return idxName; }
279 char* getPKTableName(){ return pkTblName;}
280 DbRetVal setAutoIncreament(bool flag);
281 bool getAutoIncreament();
282 void insertValue(char *value);
283 void insertInValue(char *value);
284 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
285 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
286 // _ is converted to ? before it is processed
287 void** insertCondValueAndGetPtr(char *fName, char *value, bool opLike=false, AggType atp=AGG_UNKNOWN, bool isInHaving=false);
288 void insertCondValue(char *fldName); //For Predecate t1.f1=t2.f1
289 void insertUpdateValue(char *fldName, char *value);
291 void insertField(char *fName, AggType aggType= AGG_UNKNOWN);
292 void insertFieldAlias(char *name);
293 void insertGroupField(char *fName);
294 void insertOrderByField(char *fName, bool isDesc= false);
295 void clearFieldNameList();
296 void insertTableName(char *value);
297 void insertJoinType(JoinType jType);
298 void insertTableName(char *value, char *alias);
299 void insertFKField(char *fkName);
300 void insertPKField(char *pkName);
301 void insertForeignKeyList();
302 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value, AggType aggType = AGG_UNKNOWN);
303 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName1);
304 Predicate* insertBetPredicate(char *fldName, ComparisionOp op1, void **value1, ComparisionOp op2, void **value2);
305 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
306 Predicate* insertNullPredicate(char *fName, ComparisionOp op,bool nullFlag);
307 void setCondition(Predicate *pred)
309 predicate.setPredicate(pred);
311 void setHavingCondition(Predicate *pred)
313 havingPredicate.setPredicate(pred);
315 Condition* getCondition() { return &predicate; }
316 Condition* getHavingCondition() { return &havingPredicate; }
318 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
320 List getFieldNameList() { return fieldNameList; }
321 List getGroupFieldNameList() { return groupFieldNameList; }
322 List getHavingFieldNameList() { return havingFieldNameList; }
323 List getOrderFieldNameList() { return orderFieldNameList; }
324 List getConditionValueList() { return conditionValueList; }
325 List getFieldValueList() { return fieldValueList; }
326 List getInValueList() { return inValueList; }
327 List getUpdateFieldValueList() { return updFldValList; }
328 List getTableNameList() { return tableNameList; }
329 List getJoinTypeList() { return joinTypeList; }
330 List getSecondaryIndexFieldList() { return secondaryIndexFieldList; }
331 List getForeignKeyList(){ return foreignKeyList;}
332 List getPkFieldNameList(){return pkFieldNameList;}
333 List getFkFieldNameList(){return fkFieldNameList;}
335 void setDistinct() { isDistinct = true;}
336 bool getDistinct() { return isDistinct; }
337 void setExplain() { isExplain=true; }
338 bool getExplain() { return isExplain; }
339 bool getCacheWorthy() { return isWorthyToCache; }
340 void setCacheWorthy(bool flag) { isWorthyToCache = flag;}
343 void setFldName(char *name);
344 void setFldType(DataType type);
345 DataType getFldType();
346 DbRetVal setFldLength(size_t length);
347 void setDefaultValue(char * value);
348 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
349 void setFldNotNull(bool notNull);
350 void setForeign(bool foreign){ isForeign = foreign; }
351 void setUnique(bool unique){ isUnique = unique; }
352 void setPrimary(bool primary) { isPrimary = primary; }
353 void setIndexType (IndexType type) { indexType = type; }
354 IndexType getIndexType(){ return indexType; }
355 bool getUnique() { return isUnique; }
356 bool getPrimary() { return isPrimary; }
357 Expression* insertExpression(char *fldName);
358 Expression* insertExpression(char *value, bool flag);
359 Expression* insertExpression(Expression* exp1, ArithOperator op ,Expression* exp2);
360 void insertUpdateExpression(char *fName, Expression *exp);
362 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
364 FieldList getCreFldList() { return creFldList; }
366 StatementType getStmtType() { return stmtType; }
367 char *getFldName();
368 void setAutoFldName(char *fldName);
369 void reset();
370 void init();
374 #endif
376 //TODO: Aruna
377 //variable and function names suck, change if u want to
378 //setFldDefaultValue
379 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
380 //primary key
381 //foreign key