00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PARSER_H
00021 #define PARSER_H
00022 #include <CSql.h>
00023 #include <os.h>
00024 #include <Util.h>
00025 enum StatementType
00026 {
00027 UnknownStatement,
00028 SelectStatement,
00029 InsertStatement,
00030 UpdateStatement,
00031 DeleteStatement,
00032 CreateTableStatement,
00033 DropTableStatement,
00034 CreateIndexStatement,
00035 DropIndexStatement
00036 };
00037
00038 struct FieldValue
00039 {
00040 char *parsedString;
00041 void *value;
00042 int paramNo;
00043 DataType type;
00044 int length;
00045 };
00046
00047
00048 struct ConditionValue
00049 {
00050 char *parsedString;
00051 void *value;
00052 int paramNo;
00053 DataType type;
00054 int length;
00055 char fName[IDENTIFIER_LENGTH];
00056 };
00057
00058 struct FieldName
00059 {
00060 char fldName[IDENTIFIER_LENGTH];
00061 };
00062
00063 struct UpdateFieldValue
00064 {
00065 char fldName[IDENTIFIER_LENGTH];
00066 char *parsedString;
00067 void *value;
00068 DataType type;
00069 int length;
00070 int paramNo;
00071 };
00072
00073
00074 class ParsedData
00075 {
00076 private:
00077 char tblName[IDENTIFIER_LENGTH];
00078 char idxName[IDENTIFIER_LENGTH];
00079
00080 StatementType stmtType;
00081
00082 int paramCounter;
00083
00084
00085
00086
00087 List fieldNameList;
00088
00089
00090 List conditionValueList;
00091
00092
00093
00094
00095 List fieldValueList;
00096
00097
00098
00099
00100 List inValueList;
00101
00102
00103
00104 List updFldValList;
00105
00106
00107 Condition predicate;
00108
00109
00110 FieldDef fldDef;
00111
00112
00113 FieldList creFldList;
00114
00115
00116 bool isUnique;
00117 bool isPrimary;
00118 IndexType indexType;
00119
00120 public:
00121 ParsedData() { paramCounter = 0; stmtType = UnknownStatement;
00122 isUnique = false; isPrimary = false; indexType = hashIndex;}
00123 void setStmtType(StatementType type) { stmtType = type; }
00124 void setTableName(char *name) { strcpy(tblName, name); }
00125 void setIndexName(char *name) { strcpy(idxName, name); }
00126
00127 char* getTableName() { return tblName; }
00128 char* getIndexName() { return idxName; }
00129
00130 void insertValue(char *value);
00131 void insertInValue(char *value);
00132 void** insertCondValueAndGetPtr(char *fName, char *value);
00133 void insertUpdateValue(char *fldName, char *value);
00134
00135 void insertField(char *fName);
00136 void clearFieldNameList();
00137
00138
00139 Predicate* insertPredicate(char *fldName, ComparisionOp op, void** value);
00140 Predicate* insertPredicate(char *fldName, ComparisionOp op, char *fldName);
00141 Predicate* insertPredicate(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
00142 void setCondition(Predicate *pred)
00143 {
00144
00145
00146 predicate.setPredicate(pred);
00147 }
00148 Condition* getCondition() { return &predicate; }
00149
00150 void insertFieldValue(FieldValue *newVal) { fieldValueList.append(newVal); }
00151
00152 List getFieldNameList() { return fieldNameList; }
00153 List getConditionValueList() { return conditionValueList; }
00154 List getFieldValueList() { return fieldValueList; }
00155 List getInValueList() { return inValueList; }
00156 List getUpdateFieldValueList() { return updFldValList; }
00157
00158 void setFldName(char *name);
00159 void setFldType(DataType type);
00160 void setFldLength(size_t length);
00161 void setDefaultValue(char * value);
00162
00163 void setFldNotNull(bool notNull);
00164
00165 void setUnique(bool unique){ isUnique = unique; }
00166 void setPrimary(bool primary) { isPrimary = primary; }
00167 void setIndexType (IndexType type) { indexType = type; }
00168 IndexType getIndexType(){ return indexType; }
00169 bool getUnique() { return isUnique; }
00170 bool getPrimary() { return isPrimary; }
00171
00172 void insertFldDef();
00173
00174 FieldList getCreFldList() { return creFldList; }
00175
00176 StatementType getStmtType() { return stmtType; }
00177
00178 void reset();
00179
00180 };
00181
00182 #endif
00183
00184
00185
00186
00187
00188
00189