*** empty log message ***
[csql.git] / include / Parser.h
blob81e02318a6ac0f73e94fa8c3471f856df1e4ad1d
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 enum StatementType
29 UnknownStatement,
30 SelectStatement,
31 InsertStatement,
32 UpdateStatement,
33 DeleteStatement,
34 CreateTableStatement,
35 DropTableStatement,
36 CreateIndexStatement,
37 DropIndexStatement
40 struct FieldValue
42 char fldName[IDENTIFIER_LENGTH];
43 char *parsedString;
44 void *value;
45 int paramNo; // 0 ->not a param. It stores the param position
46 DataType type;
47 int length;
48 bool isAllocVal;
52 struct ConditionValue
54 char *parsedString;
55 void *value;
56 int paramNo; // 0 ->not a param. It stores the param position
57 DataType type;
58 int length;
59 bool opLike;
60 char fName[IDENTIFIER_LENGTH];
63 struct FieldName
65 char fldName[IDENTIFIER_LENGTH];
66 AggType aType; //used only in case of select projection
67 FieldName()
69 strcpy(fldName,"");
70 aType = AGG_UNKNOWN;
73 struct TableName
75 char tblName[IDENTIFIER_LENGTH];
76 TableName()
78 strcpy(tblName,"");
82 struct UpdateFieldValue
84 char fldName[IDENTIFIER_LENGTH];
85 char *parsedString;
86 void *value;
87 DataType type;
88 int length;
89 int paramNo;
93 class ParsedData
95 private:
96 char tblName[IDENTIFIER_LENGTH];
97 char idxName[IDENTIFIER_LENGTH];
99 StatementType stmtType;
101 int paramCounter;
103 List tableNameList;
104 //holds pointer to field names. used in insert to store field name list
105 //and for projection list of select
106 //also used to store primary or unique key fields in create statement
107 List fieldNameList;
109 List groupFieldNameList;
111 //holds pointer to condition values.
112 List conditionValueList;
114 //holds pointer to field values. used in insert to store field values
115 //used in update to store the current value returned by fetch().This gets replaced
116 //by value in updFldValList and then update() is called.
117 List fieldValueList;
119 //used to store IN values of SELECT statement
120 //This should be a list of list. so that multiple IN shall be present
121 //in the select statement
122 List inValueList;
124 //update field value list. used to store the values to be updated
125 //value in the SET clause of UPDATE statement is stored here.
126 List updFldValList;
128 //stores the where clause condition for SELECT, UPDATE and DELETE
129 Condition predicate;
131 //stores field information in CREATE TABLE
132 FieldDef fldDef;
134 //stores list of fields for CREATE TABLE
135 FieldList creFldList;
137 //stores index information
138 bool isUnique;
139 bool isPrimary;
140 IndexType indexType;
142 public:
143 ParsedData() { paramCounter = 0; stmtType = UnknownStatement;
144 isUnique = false; isPrimary = false; indexType = hashIndex;}
145 void setStmtType(StatementType type) { stmtType = type; }
146 void setTableName(char *name) { strcpy(tblName, name); }
147 void setIndexName(char *name) { strcpy(idxName, name); }
149 char* getTableName() { return tblName; }
150 char* getIndexName() { return idxName; }
152 void insertValue(char *value);
153 void insertInValue(char *value);
154 // third parameter is to avoid conflict between '?' between like operand and parameterized value in sql statement.
155 // eg: select * from t1 where f1 = ? and f2 like '_ti%';
156 // _ is converted to ? before it is processed
157 void** insertCondValueAndGetPtr(char *fName, char *value, bool opLike=false);
158 void insertUpdateValue(char *fldName, char *value);
160 void insertField(char *fName, AggType aggType= AGG_UNKNOWN);
161 void insertGroupField(char *fName);
162 void clearFieldNameList();
163 void insertTableName(char *value);
166 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
167 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
168 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
169 void setCondition(Predicate *pred)
171 //No body is deleting memory allocated during condition::setTerm for PredicateImpl
172 //have list in this pared data and delete it during reset
173 predicate.setPredicate(pred);
175 Condition* getCondition() { return &predicate; }
177 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
179 List getFieldNameList() { return fieldNameList; }
180 List getGroupFieldNameList() { return groupFieldNameList; }
181 List getConditionValueList() { return conditionValueList; }
182 List getFieldValueList() { return fieldValueList; }
183 List getInValueList() { return inValueList; }
184 List getUpdateFieldValueList() { return updFldValList; }
185 List getTableNameList() { return tableNameList; }
187 void setFldName(char *name);
188 void setFldType(DataType type);
189 void setFldLength(size_t length);
190 void setDefaultValue(char * value);
191 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
192 void setFldNotNull(bool notNull);
194 void setUnique(bool unique){ isUnique = unique; }
195 void setPrimary(bool primary) { isPrimary = primary; }
196 void setIndexType (IndexType type) { indexType = type; }
197 IndexType getIndexType(){ return indexType; }
198 bool getUnique() { return isUnique; }
199 bool getPrimary() { return isPrimary; }
201 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
203 FieldList getCreFldList() { return creFldList; }
205 StatementType getStmtType() { return stmtType; }
207 void reset();
211 #endif
213 //TODO: Aruna
214 //variable and function names suck, change if u want to
215 //setFldDefaultValue
216 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
217 //primary key
218 //foreign key