fixing build warning messages
[csql.git] / include / Parser.h
blobee95ae3f116735837b03cc464ae09a2ea6dddfdd
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 public:
231 ParsedData() { limit = 0; offset= 0; paramCounter = 0; stmtType = UnknownStatement; isDistinct = false; isExplain=false;
232 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;
233 shouldCreateTbl=false; userNode = NULL;
235 void createUserNode(char *name, char *password);
236 char *getUserName() { return userNode->userName; }
237 char *getPassWord() { return userNode->passName; }
238 UserNodeType getUserType() { return userNode->type; }
239 void dropUserNode(char *name);
240 void alterUserNode(char *name, char *password);
242 void setCreateTbl(){ shouldCreateTbl=true; }
243 bool getCreateTbl(){ return shouldCreateTbl; }
245 void setDSN(bool flag){ dsn = flag;}
246 bool getDSN(){ return dsn; }
247 void setNoSchema(bool flag){ noschema = flag; }
248 bool getNoSchema(){return noschema;}
249 char *getHCondition(){return hcondition;}
250 char *getVCondition(){return vcondition;}
251 void setHCondition(char *fld){ strcpy(hcondition,fld);}
252 void setVCondition(char *fld){ strcpy(vcondition,fld);}
253 void setHCondFld(bool flag){hCondFld = flag;}
254 bool getHCondFld(){return hCondFld;}
255 void setVCondFld(bool flag){vCondFld = flag;}
256 bool getVCondFld(){return vCondFld;}
257 void setPkFld(bool flag){pkFld = flag;}
258 bool getPkFld(){return pkFld;}
259 void setDirect(bool flag){direct=flag;}
260 bool getDirect(){return direct;}
261 void setUnCache(bool flag){uncache=flag;}
262 bool getUnCache(){return uncache;}
263 void setLimit(int l, int o) { limit =l; offset=o; }
264 int getLimit(){ return limit; }
265 int getOffset(){ return offset; }
268 int getBucketSize(){return bucketSize; };
269 void setBucketSize(int bucket){ bucketSize = bucket; };
270 void setStmtType(StatementType type) { stmtType = type; }
271 void setTableName(char *name) { strcpy(tblName, name); }
272 void setIndexName(char *name) { strcpy(idxName, name); }
273 void setPKTableName(char *name){strcpy(pkTblName, name); }
274 void setResultSetPlan(ResultSetPlan pl){plan = pl;}
275 ResultSetPlan getResultSetPlan(){return plan;}
276 char* getTableName() { return tblName; }
277 char* getIndexName() { return idxName; }
278 char* getPKTableName(){ return pkTblName;}
279 DbRetVal setAutoIncreament(bool flag);
280 bool getAutoIncreament();
281 void insertValue(char *value);
282 void insertInValue(char *value);
283 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
284 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
285 // _ is converted to ? before it is processed
286 void** insertCondValueAndGetPtr(char *fName, char *value, bool opLike=false, AggType atp=AGG_UNKNOWN, bool isInHaving=false);
287 void insertCondValue(char *fldName); //For Predecate t1.f1=t2.f1
288 void insertUpdateValue(char *fldName, char *value);
290 void insertField(char *fName, AggType aggType= AGG_UNKNOWN);
291 void insertFieldAlias(char *name);
292 void insertGroupField(char *fName);
293 void insertOrderByField(char *fName, bool isDesc= false);
294 void clearFieldNameList();
295 void insertTableName(char *value);
296 void insertJoinType(JoinType jType);
297 void insertTableName(char *value, char *alias);
298 void insertFKField(char *fkName);
299 void insertPKField(char *pkName);
300 void insertForeignKeyList();
301 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value, AggType aggType = AGG_UNKNOWN);
302 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName1);
303 Predicate* insertBetPredicate(char *fldName, ComparisionOp op1, void **value1, ComparisionOp op2, void **value2);
304 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
305 Predicate* insertNullPredicate(char *fName, ComparisionOp op,bool nullFlag);
306 void setCondition(Predicate *pred)
308 predicate.setPredicate(pred);
310 void setHavingCondition(Predicate *pred)
312 havingPredicate.setPredicate(pred);
314 Condition* getCondition() { return &predicate; }
315 Condition* getHavingCondition() { return &havingPredicate; }
317 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
319 List getFieldNameList() { return fieldNameList; }
320 List getGroupFieldNameList() { return groupFieldNameList; }
321 List getHavingFieldNameList() { return havingFieldNameList; }
322 List getOrderFieldNameList() { return orderFieldNameList; }
323 List getConditionValueList() { return conditionValueList; }
324 List getFieldValueList() { return fieldValueList; }
325 List getInValueList() { return inValueList; }
326 List getUpdateFieldValueList() { return updFldValList; }
327 List getTableNameList() { return tableNameList; }
328 List getJoinTypeList() { return joinTypeList; }
329 List getSecondaryIndexFieldList() { return secondaryIndexFieldList; }
330 List getForeignKeyList(){ return foreignKeyList;}
331 List getPkFieldNameList(){return pkFieldNameList;}
332 List getFkFieldNameList(){return fkFieldNameList;}
334 void setDistinct() { isDistinct = true;}
335 bool getDistinct() { return isDistinct; }
336 void setExplain() { isExplain=true; }
337 bool getExplain() { return isExplain; }
340 void setFldName(char *name);
341 void setFldType(DataType type);
342 DataType getFldType();
343 DbRetVal setFldLength(size_t length);
344 void setDefaultValue(char * value);
345 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
346 void setFldNotNull(bool notNull);
347 void setForeign(bool foreign){ isForeign = foreign; }
348 void setUnique(bool unique){ isUnique = unique; }
349 void setPrimary(bool primary) { isPrimary = primary; }
350 void setIndexType (IndexType type) { indexType = type; }
351 IndexType getIndexType(){ return indexType; }
352 bool getUnique() { return isUnique; }
353 bool getPrimary() { return isPrimary; }
354 Expression* insertExpression(char *fldName);
355 Expression* insertExpression(char *value, bool flag);
356 Expression* insertExpression(Expression* exp1, ArithOperator op ,Expression* exp2);
357 void insertUpdateExpression(char *fName, Expression *exp);
359 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
361 FieldList getCreFldList() { return creFldList; }
363 StatementType getStmtType() { return stmtType; }
364 char *getFldName();
365 void setAutoFldName(char *fldName);
366 void reset();
367 void init();
371 #endif
373 //TODO: Aruna
374 //variable and function names suck, change if u want to
375 //setFldDefaultValue
376 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
377 //primary key
378 //foreign key