Remove nwmode in csqlnw.conf file and making UDPClient and UDPServer as
[csql.git] / include / Parser.h
blobb4df7a7e9963ac5c3117d8533e619b9c64677d27
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 <os.h>
24 #include <Util.h>
25 enum StatementType
27 UnknownStatement,
28 SelectStatement,
29 InsertStatement,
30 UpdateStatement,
31 DeleteStatement,
32 CreateTableStatement,
33 DropTableStatement,
34 CreateIndexStatement,
35 DropIndexStatement
38 struct FieldValue
40 char *parsedString;
41 void *value;
42 int paramNo; // 0 ->not a param. It stores the param position
43 DataType type;
44 int length;
48 struct ConditionValue
50 char *parsedString;
51 void *value;
52 int paramNo; // 0 ->not a param. It stores the param position
53 DataType type;
54 int length;
55 char fName[IDENTIFIER_LENGTH];
58 struct FieldName
60 char fldName[IDENTIFIER_LENGTH];
63 struct UpdateFieldValue
65 char fldName[IDENTIFIER_LENGTH];
66 char *parsedString;
67 void *value;
68 DataType type;
69 int length;
70 int paramNo;
74 class ParsedData
76 private:
77 char tblName[IDENTIFIER_LENGTH];
78 char idxName[IDENTIFIER_LENGTH];
80 StatementType stmtType;
82 int paramCounter;
84 //holds pointer to field names. used in insert to store field name list
85 //and for projection list of select
86 //also used to store primary or unique key fields in create statement
87 List fieldNameList;
89 //holds pointer to condition values.
90 List conditionValueList;
92 //holds pointer to field values. used in insert to store field values
93 //used in update to store the current value returned by fetch().This gets replaced
94 //by value in updFldValList and then update() is called.
95 List fieldValueList;
97 //update field value list. used to store the values to be updated
98 //value in the SET clause of UPDATE statement is stored here.
99 List updFldValList;
101 //stores the where clause condition for SELECT, UPDATE and DELETE
102 Condition predicate;
104 //stores field information in CREATE TABLE
105 FieldDef fldDef;
107 //stores list of fields for CREATE TABLE
108 FieldList creFldList;
110 //stores index information
111 bool isUnique;
112 bool isPrimary;
113 IndexType indexType;
115 public:
116 ParsedData() { paramCounter = 0; stmtType = UnknownStatement;
117 isUnique = false; isPrimary = false; indexType = hashIndex;}
118 void setStmtType(StatementType type) { stmtType = type; }
119 void setTableName(char *name) { strcpy(tblName, name); }
120 void setIndexName(char *name) { strcpy(idxName, name); }
122 char* getTableName() { return tblName; }
123 char* getIndexName() { return idxName; }
125 void insertValue(char *value);
126 void** insertCondValueAndGetPtr(char *fName, char *value);
127 void insertUpdateValue(char *fldName, char *value);
129 void insertField(char *fName);
130 void clearFieldNameList();
133 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
134 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
135 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
136 void setCondition(Predicate *pred)
138 //No body is deleting memory allocated during condition::setTerm for PredicateImpl
139 //have list in this pared data and delete it during reset
140 predicate.setPredicate(pred);
142 Condition* getCondition() { return &predicate; }
144 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
146 List getFieldNameList() { return fieldNameList; }
147 List getConditionValueList() { return conditionValueList; }
148 List getFieldValueList() { return fieldValueList; }
149 List getUpdateFieldValueList() { return updFldValList; }
151 void setFldName(char *name);
152 void setFldType(DataType type);
153 void setFldLength(size_t length);
154 //void setFldDefaultValue -- will need two parametersers, check how u want to pass default value.
155 void setFldNotNull(bool notNull);
157 void setUnique(bool unique){ isUnique = unique; }
158 void setPrimary(bool primary) { isPrimary = primary; }
159 void setIndexType (IndexType type) { indexType = type; }
160 IndexType getIndexType(){ return indexType; }
161 bool getUnique() { return isUnique; }
162 bool getPrimary() { return isPrimary; }
164 void insertFldDef(); //check if fldDef needs to be a part of ParsedData
166 FieldList getCreFldList() { return creFldList; }
168 StatementType getStmtType() { return stmtType; }
170 void reset();
174 #endif
176 //TODO: Aruna
177 //variable and function names suck, change if u want to
178 //setFldDefaultValue
179 //finding out if fldDef needs to be part of parsedData, or can allocate memory and pass around
180 //primary key
181 //foreign key