changes for join table and parser for aggregates
[csql.git] / src / sql / Parser.h
blob0b7f517cadb246e8b3de82adaf03c4909e532069
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 *parsedString;
42 void *value;
43 int paramNo; // 0 ->not a param. It stores the param position
44 DataType type;
45 int length;
49 struct ConditionValue
51 char *parsedString;
52 void *value;
53 int paramNo; // 0 ->not a param. It stores the param position
54 DataType type;
55 int length;
56 char fName[IDENTIFIER_LENGTH];
59 struct FieldName
61 char fldName[IDENTIFIER_LENGTH];
62 AggType aType; //used only in case of select projection
63 FieldName()
65 strcpy(fldName,"");
66 aType = AGG_UNKNOWN;
70 struct UpdateFieldValue
72 char fldName[IDENTIFIER_LENGTH];
73 char *parsedString;
74 void *value;
75 DataType type;
76 int length;
77 int paramNo;
81 class ParsedData
83 private:
84 char tblName[IDENTIFIER_LENGTH];
85 char idxName[IDENTIFIER_LENGTH];
87 StatementType stmtType;
89 int paramCounter;
91 //holds pointer to field names. used in insert to store field name list
92 //and for projection list of select
93 //also used to store primary or unique key fields in create statement
94 List fieldNameList;
96 List groupFieldNameList;
98 //holds pointer to condition values.
99 List conditionValueList;
101 //holds pointer to field values. used in insert to store field values
102 //used in update to store the current value returned by fetch().This gets replaced
103 //by value in updFldValList and then update() is called.
104 List fieldValueList;
106 //used to store IN values of SELECT statement
107 //This should be a list of list. so that multiple IN shall be present
108 //in the select statement
109 List inValueList;
111 //update field value list. used to store the values to be updated
112 //value in the SET clause of UPDATE statement is stored here.
113 List updFldValList;
115 //stores the where clause condition for SELECT, UPDATE and DELETE
116 Condition predicate;
118 //stores field information in CREATE TABLE
119 FieldDef fldDef;
121 //stores list of fields for CREATE TABLE
122 FieldList creFldList;
124 //stores index information
125 bool isUnique;
126 bool isPrimary;
127 IndexType indexType;
129 public:
130 ParsedData() { paramCounter = 0; stmtType = UnknownStatement;
131 isUnique = false; isPrimary = false; indexType = hashIndex;}
132 void setStmtType(StatementType type) { stmtType = type; }
133 void setTableName(char *name) { strcpy(tblName, name); }
134 void setIndexName(char *name) { strcpy(idxName, name); }
136 char* getTableName() { return tblName; }
137 char* getIndexName() { return idxName; }
139 void insertValue(char *value);
140 void insertInValue(char *value);
141 void** insertCondValueAndGetPtr(char *fName, char *value);
142 void insertUpdateValue(char *fldName, char *value);
144 void insertField(char *fName, AggType aggType= AGG_UNKNOWN);
145 void insertGroupField(char *fName);
146 void clearFieldNameList();
149 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
150 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
151 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
152 void setCondition(Predicate *pred)
154 //No body is deleting memory allocated during condition::setTerm for PredicateImpl
155 //have list in this pared data and delete it during reset
156 predicate.setPredicate(pred);
158 Condition* getCondition() { return &predicate; }
160 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
162 List getFieldNameList() { return fieldNameList; }
163 List getGroupFieldNameList() { return groupFieldNameList; }
164 List getConditionValueList() { return conditionValueList; }
165 List getFieldValueList() { return fieldValueList; }
166 List getInValueList() { return inValueList; }
167 List getUpdateFieldValueList() { return updFldValList; }
169 void setFldName(char *name);
170 void setFldType(DataType type);
171 void setFldLength(size_t length);
172 void setDefaultValue(char * value);
173 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
174 void setFldNotNull(bool notNull);
176 void setUnique(bool unique){ isUnique = unique; }
177 void setPrimary(bool primary) { isPrimary = primary; }
178 void setIndexType (IndexType type) { indexType = type; }
179 IndexType getIndexType(){ return indexType; }
180 bool getUnique() { return isUnique; }
181 bool getPrimary() { return isPrimary; }
183 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
185 FieldList getCreFldList() { return creFldList; }
187 StatementType getStmtType() { return stmtType; }
189 void reset();
193 #endif
195 //TODO: Aruna
196 //variable and function names suck, change if u want to
197 //setFldDefaultValue
198 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
199 //primary key
200 //foreign key