Trie Index changes for retreiving metadata through catalog tool and
[csql.git] / include / Statement.h
blob0674763f1905fe6abb1069cb5e1e6ff7f3e2e037
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 STATEMENT_H
21 #define STATEMENT_H
22 #include "Parser.h"
23 #include "CacheTableLoader.h"
24 class Statement
26 protected:
27 ParsedData *parsedData;
28 DatabaseManager *dbMgr;
30 public:
31 void setParsedData(ParsedData *pData) { parsedData = pData; }
32 void setDbMgr(DatabaseManager *dbmgr) { dbMgr = dbmgr; }
35 virtual int noOfParamFields() { return 0; }
36 virtual DbRetVal execute(int &rowsAffected)=0;
37 virtual DbRetVal setParam(int paramNo, void *value)=0;
39 virtual DbRetVal setShortParam(int paramNo, short value)=0;
40 virtual DbRetVal setIntParam(int paramNo, int value)=0;
41 virtual DbRetVal setLongParam(int paramNo, long value)=0;
42 virtual DbRetVal setLongLongParam(int paramNo, long long value)=0;
43 virtual DbRetVal setByteIntParam(int paramNo, ByteInt value)=0;
44 virtual DbRetVal setFloatParam(int paramNo, float value)=0;
45 virtual DbRetVal setDoubleParam(int paramNo, double value)=0;
46 virtual DbRetVal setStringParam(int paramNo, char *value)=0;
47 virtual DbRetVal setDateParam(int paramNo, Date value)=0;
48 virtual DbRetVal setTimeParam(int paramNo, Time value)=0;
49 virtual DbRetVal setTimeStampParam(int paramNo, TimeStamp value)=0;
50 virtual DbRetVal setBinaryParam(int paramNo, void *value, int length)=0;
51 virtual DbRetVal getFieldInfo(const char *tblName, const char *fldName, FieldInfo *&info) = 0;
52 virtual List getFieldNameList(const char *tblName, DbRetVal &rv)=0;
53 virtual DbRetVal resolve()=0;
54 virtual bool isFldNull(int pos)=0;
55 virtual bool isFldNull(char *name)=0;
56 virtual int getFldPos(char *name)=0;
57 virtual DbRetVal setNull(int pos)=0;
58 virtual ResultSetPlan getResultSetPlan()=0;
59 virtual long long getLastInsertedVal(DbRetVal &rv)=0;
60 virtual ~Statement(){}
63 class DmlStatement : public Statement
65 protected:
66 Table *table;
68 void **params;
69 //used to store FieldValue* for insert or ConditionValue* for other stmts
71 char **paramValues;
72 int totalParams;
74 public:
75 int noOfParamFields() { return totalParams; }
76 virtual DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info) =0;
78 virtual DbRetVal execute(int &rowsAffected)=0;
79 virtual DbRetVal setParam(int paramNo, void *value)=0;
81 virtual DbRetVal setShortParam(int paramNo, short value)=0;
82 virtual DbRetVal setIntParam(int paramNo, int value)=0;
83 virtual DbRetVal setLongParam(int paramNo, long value)=0;
84 virtual DbRetVal setLongLongParam(int paramNo, long long value)=0;
85 virtual DbRetVal setByteIntParam(int paramNo, ByteInt value)=0;
86 virtual DbRetVal setFloatParam(int paramNo, float value)=0;
87 virtual DbRetVal setDoubleParam(int paramNo, double value)=0;
88 virtual DbRetVal setStringParam(int paramNo, char *value)=0;
89 virtual DbRetVal setDateParam(int paramNo, Date value)=0;
90 virtual DbRetVal setTimeParam(int paramNo, Time value)=0;
91 virtual DbRetVal setTimeStampParam(int paramNo, TimeStamp value)=0;
92 virtual DbRetVal setBinaryParam(int paramNo, void *value, int length)=0;
93 virtual bool isFldNull(int pos)=0;
94 virtual bool isFldNull(char *fldName)=0;
95 virtual DbRetVal setNull(int pos)=0;
96 virtual DbRetVal resolve()=0;
97 virtual void* getParamValuePtr( int pos )=0;
98 virtual int getFldPos(char *name)=0;
99 virtual ~DmlStatement(){}
100 virtual ResultSetPlan getResultSetPlan()=0;
101 virtual long long getLastInsertedVal(DbRetVal &rv)=0;
102 void setLoading(bool flag) { table->setLoading(flag); }
103 DbRetVal getFieldInfo(const char *tblName, const char *fldName,
104 FieldInfo *&info);
105 List getFieldNameList(const char *tblName, DbRetVal &rv);
108 class InsStatement : public DmlStatement
110 public:
111 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
113 DbRetVal execute(int &rowsAffected);
114 DbRetVal setParam(int paramNo, void *value);
116 DbRetVal setShortParam(int paramNo, short value);
117 DbRetVal setIntParam(int paramNo, int value);
118 DbRetVal setLongParam(int paramNo, long value);
119 DbRetVal setLongLongParam(int paramNo, long long value);
120 DbRetVal setByteIntParam(int paramNo, ByteInt value);
121 DbRetVal setFloatParam(int paramNo, float value);
122 DbRetVal setDoubleParam(int paramNo, double value);
123 DbRetVal setStringParam(int paramNo, char *value);
124 DbRetVal setDateParam(int paramNo, Date value);
125 DbRetVal setTimeParam(int paramNo, Time value);
126 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
127 DbRetVal setBinaryParam(int paramNo, void *value, int length);
128 bool isFldNull(int pos){return table->isFldNull(pos);}
129 bool isFldNull(char *fldName){return table->isFldNull(fldName);}
130 void* getParamValuePtr( int );
131 int getFldPos(char *name);
132 DbRetVal setNull(int pos);
133 long long getLastInsertedVal(DbRetVal &rv);
134 DbRetVal resolve();
135 ResultSetPlan getResultSetPlan(){return Normal;}
136 InsStatement();
137 ~InsStatement();
140 class SelStatement : public DmlStatement
142 private:
143 DbRetVal resolveStar();
144 DbRetVal setBindFieldAndValues();
145 DbRetVal resolveForCondition();
146 DbRetVal resolveDistinct();
148 public:
149 FieldValue **bindFields;
150 char **bindFieldValues;
151 int totalFields;
153 bool isPointReturned;
154 bool handleAggWithTbl;
155 bool isRecLimitReached;
156 bool isOffsetReached;
157 int numRecords;
158 bool isExplain;
159 bool isJoin;
161 DbRetVal execute(int &rowsAffected);
162 DbRetVal setParam(int paramNo, void *value);
164 DbRetVal setShortParam(int paramNo, short value);
165 DbRetVal setIntParam(int paramNo, int value);
166 DbRetVal setLongParam(int paramNo, long value);
167 DbRetVal setLongLongParam(int paramNo, long long value);
168 DbRetVal setByteIntParam(int paramNo, ByteInt value);
169 DbRetVal setFloatParam(int paramNo, float value);
170 DbRetVal setDoubleParam(int paramNo, double value);
171 DbRetVal setStringParam(int paramNo, char *value);
172 DbRetVal setDateParam(int paramNo, Date value);
173 DbRetVal setTimeParam(int paramNo, Time value);
174 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
175 DbRetVal setBinaryParam(int paramNo, void *value, int length);
177 DbRetVal replaceStarWithFirstFldName(FieldName *name);
178 DbRetVal resolveGroupFld(AggTableImpl *impl, bool &isGrpFld);
179 DbRetVal resolveOrderByFld();
180 bool isInProjectionList(char *name, AggType aType);
181 bool isFldNull(int pos){return table->isFldNull(pos);}
182 bool isFldNull(char *fldName){ return table->isFldNull(fldName); }
183 int getFldPos(char *name);
184 DbRetVal setNull(int pos){ return ErrBadCall;}
185 DbRetVal close();
186 DbRetVal resolve();
187 long long getLastInsertedVal(DbRetVal &rv){rv = ErrBadCall;return 0;}
189 void* handleSingleTableAggWithoutGroup();
190 bool isGroupFld(char *fName);
191 bool isJoinStmt() { return isJoin; }
193 SelStatement();
194 ~SelStatement();
196 bool isTableAlreadyPresent(char* tblName, char* aliasName);
197 DbRetVal openTables();
198 // DbRetVal resolveGroupFld(AggTableImpl *impl);
200 DbRetVal setBindField(int pos, void* value);
202 int noOfProjFields();
203 DbRetVal getProjFldInfo (int projpos, FieldInfo *&fInfo);
204 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
206 void *getParamValuePtr( int );
207 DataType getFieldType( int );
208 int getFieldLength( int );
209 char* getFieldName( int );
211 void *fetch();
212 void *fetch(DbRetVal &rv);
213 void *fetchAndPrint(bool SQL);
214 void *next();
215 void *getFieldValuePtr( int );
216 void *getFieldValuePtr( char *name );
217 void getProjFieldType(int *data);
218 ResultSetPlan getResultSetPlan(){ return Normal; }
221 class UpdStatement : public DmlStatement
223 public:
224 DbRetVal execute(int &rowsAffected);
225 DbRetVal setParam(int paramNo, void *value);
227 DbRetVal setShortParam(int paramNo, short value);
228 DbRetVal setIntParam(int paramNo, int value);
229 DbRetVal setLongParam(int paramNo, long value);
230 DbRetVal setLongLongParam(int paramNo, long long value);
231 DbRetVal setByteIntParam(int paramNo, ByteInt value);
232 DbRetVal setFloatParam(int paramNo, float value);
233 DbRetVal setDoubleParam(int paramNo, double value);
234 DbRetVal setStringParam(int paramNo, char *value);
235 DbRetVal setDateParam(int paramNo, Date value);
236 DbRetVal setTimeParam(int paramNo, Time value);
237 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
238 DbRetVal setBinaryParam(int paramNo, void *value, int length);
239 void* getParamValuePtr(int);
240 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
241 bool isFldNull(int pos){return table->isFldNull(pos);}
242 bool isFldNull(char *fldName){return table->isFldNull(fldName);}
243 int getFldPos(char *name);
244 DbRetVal setNull(int pos);
245 DbRetVal resolve();
246 long long getLastInsertedVal(DbRetVal &rv){ rv=ErrBadCall; return 0;}
247 UpdStatement();
248 ~UpdStatement();
249 ResultSetPlan getResultSetPlan() {return Normal;}
250 int totalAssignParams;
251 DbRetVal resolveForAssignment();
252 ResultSetPlan plan;
255 class DelStatement : public DmlStatement
257 public:
258 DbRetVal execute(int &rowsAffected);
259 DbRetVal setParam(int paramNo, void *value);
261 DbRetVal setShortParam(int paramNo, short value);
262 DbRetVal setIntParam(int paramNo, int value);
263 DbRetVal setLongParam(int paramNo, long value);
264 DbRetVal setLongLongParam(int paramNo, long long value);
265 DbRetVal setByteIntParam(int paramNo, ByteInt value);
266 DbRetVal setFloatParam(int paramNo, float value);
267 DbRetVal setDoubleParam(int paramNo, double value);
268 DbRetVal setStringParam(int paramNo, char *value);
269 DbRetVal setDateParam(int paramNo, Date value);
270 DbRetVal setTimeParam(int paramNo, Time value);
271 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
272 DbRetVal setBinaryParam(int paramNo, void *value, int length);
273 bool isFldNull(int pos){return table->isFldNull(pos);}
274 bool isFldNull(char *fldName){return table->isFldNull(fldName);}
275 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
276 void* getParamValuePtr(int);
277 DbRetVal setNull(int pos){ return ErrBadCall;}
278 DbRetVal resolve();
279 long long getLastInsertedVal(DbRetVal &rv){ rv = ErrBadCall;return 0;}
280 DelStatement();
281 ~DelStatement();
282 int getFldPos(char *name);
283 DbRetVal resolveForCondition(); //TODO::put this is Statement class, duplicated from SelStatement.
284 ResultSetPlan getResultSetPlan(){return Normal;}
287 class MetadataStatement : public DmlStatement
289 public:
290 FieldValue **bindFields;
291 char **bindFieldValues;
292 int totalFields;
293 ListIterator dataListIter;
295 int numRecords;
296 bool isPlanFreed;
297 bool isSecondFetch;
298 ResultSetPlan plan;
299 DbRetVal execute(int &rowsAffected);
300 DbRetVal setParam(int paramNo, void *value){return OK;};
302 DbRetVal setShortParam(int paramNo, short value){ return OK;};
303 DbRetVal setIntParam(int paramNo, int value){ return OK;};
304 DbRetVal setLongParam(int paramNo, long value){ return OK;};
305 DbRetVal setLongLongParam(int paramNo, long long value){ return OK;};
306 DbRetVal setByteIntParam(int paramNo, ByteInt value){ return OK;};
307 DbRetVal setFloatParam(int paramNo, float value){ return OK;};
308 DbRetVal setDoubleParam(int paramNo, double value){ return OK;};
309 DbRetVal setStringParam(int paramNo, char *value){ return OK;};
310 DbRetVal setDateParam(int paramNo, Date value){ return OK;};
311 DbRetVal setTimeParam(int paramNo, Time value){ return OK;};
312 DbRetVal setTimeStampParam(int paramNo, TimeStamp value){ return OK;};
313 DbRetVal setBinaryParam(int paramNo, void *value, int length){ return OK;};
315 DbRetVal replaceStarWithFirstFldName(FieldName *name){ return OK;};
316 DbRetVal resolveGroupFld(AggTableImpl *impl){ return OK;};
317 DbRetVal resolveOrderByFld(){ return OK;};
318 bool isFldNull(int pos){return table->isFldNull(pos);}
319 bool isFldNull(char *fldName){
320 if(plan != Normal) return false;
321 return table->isFldNull(fldName); }
322 int getFldPos(char *name);
323 DbRetVal setNull(int pos){ return ErrBadCall;}
324 DbRetVal close();
325 DbRetVal resolve();
327 MetadataStatement();
328 ~MetadataStatement();
329 long long getLastInsertedVal(DbRetVal &rv){rv=ErrBadCall; return 0;}
330 void *getParamValuePtr( int ){ return NULL;}
331 DbRetVal openTables();
332 DbRetVal setBindField(int pos, void* value);
333 int noOfProjFields();
334 DbRetVal getProjFldInfo (int projpos, FieldInfo *&fInfo);
335 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
336 DataType getFieldType( int );
337 int getFieldLength( int );
338 char* getFieldName( int );
340 void *fetch();
341 void *fetch(DbRetVal &rv);
342 void *fetchAndPrint(bool SQL);
343 void *next();
344 void *getFieldValuePtr( int );
345 void *getFieldValuePtr( char *name );
346 void getProjFieldType(int *data);
347 void *fetchMetaData();
348 void freeMetadata();
349 ResultSetPlan getResultSetPlan(){return plan;}
350 ListIterator getExportKeyIterator();
351 ListIterator getImportKeyIterator();
352 ListIterator getDataTypeInfoIterator();
354 class CopyTblStatement : public DmlStatement
356 public:
357 DbRetVal execute(int &rowsAffected);
358 DbRetVal resolve();
359 DbRetVal setParam(int paramNo, void *value);
360 DbRetVal setShortParam(int paramNo, short value);
361 DbRetVal setIntParam(int paramNo, int value);
362 DbRetVal setLongParam(int paramNo, long value);
363 DbRetVal setLongLongParam(int paramNo, long long value);
364 DbRetVal setByteIntParam(int paramNo, ByteInt value);
365 DbRetVal setFloatParam(int paramNo, float value);
366 DbRetVal setDoubleParam(int paramNo, double value);
367 DbRetVal setStringParam(int paramNo, char *value);
368 DbRetVal setDateParam(int paramNo, Date value);
369 DbRetVal setTimeParam(int paramNo, Time value);
370 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
371 DbRetVal setBinaryParam(int paramNo, void *value, int length);
372 bool isFldNull(int pos){return table->isFldNull(pos);}
373 bool isFldNull(char *fldName){return table->isFldNull(fldName);}
374 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
375 void* getParamValuePtr(int);
376 DbRetVal setNull(int pos){ return ErrBadCall;}
377 int getFldPos(char *name);
378 ResultSetPlan getResultSetPlan(){return Normal;}
379 DbRetVal resolveForInsert();
380 DbRetVal resolveForCreate();
381 long long getLastInsertedVal(DbRetVal &rv){ rv = ErrBadCall; return 0;}
382 CopyTblStatement();
383 ~CopyTblStatement();
384 private:
385 void **bindFieldValues;
386 int totalFields;
387 Statement *innerSelStmt;
388 char tblName[IDENTIFIER_LENGTH];
393 class DdlStatement : public Statement
395 public:
396 DbRetVal execute(int &rowsAffected)=0;
397 //TODO: i think rowsAffected is not part of ddl - gopal said its design decision
398 DbRetVal resolve()=0;
400 DbRetVal setParam(int paramNo, void *value) { return ErrBadCall; }
401 DbRetVal setShortParam(int paramNo, short value) { return ErrBadCall; }
402 DbRetVal setIntParam(int paramNo, int value) { return ErrBadCall; }
403 DbRetVal setLongParam(int paramNo, long value) { return ErrBadCall; }
404 DbRetVal setLongLongParam(int paramNo, long long value) { return ErrBadCall; }
405 DbRetVal setByteIntParam(int paramNo, ByteInt value) { return ErrBadCall; }
406 DbRetVal setFloatParam(int paramNo, float value) { return ErrBadCall; }
407 DbRetVal setDoubleParam(int paramNo, double value) { return ErrBadCall; }
408 DbRetVal setStringParam(int paramNo, char *value) { return ErrBadCall; }
409 DbRetVal setDateParam(int paramNo, Date value) { return ErrBadCall; }
410 DbRetVal setTimeParam(int paramNo, Time value) { return ErrBadCall; }
411 DbRetVal setTimeStampParam(int paramNo, TimeStamp value) { return ErrBadCall;}
412 DbRetVal setBinaryParam(int paramNo, void *value, int length) { return ErrBadCall;}
413 DbRetVal getFieldInfo(const char *tblName, const char *fldName, FieldInfo *&info){return ErrBadCall; }
414 List getFieldNameList(const char *tblName, DbRetVal &rv) {
415 List dummylist; rv = ErrBadCall; return dummylist;
417 bool isFldNull(int pos){ return false;}
418 bool isFldNull(char *fldName ){ return false;}
419 int getFldPos(char *name){ return -1;}
420 long long getLastInsertedVal(DbRetVal &rv){ rv = ErrBadCall; return 0;}
421 DbRetVal setNull(int pos){ return ErrBadCall;}
422 ResultSetPlan getResultSetPlan(){ ResultSetPlan dummy; return dummy;}
425 class CreateTblStatement : public DdlStatement
427 public:
428 DbRetVal execute(int &rowsAffected);
429 DbRetVal resolve();
430 DbRetVal checkForDot(char *name);
431 CreateTblStatement();
432 ~CreateTblStatement();
434 private:
435 char tblName[IDENTIFIER_LENGTH];
436 TableDef tblDef;
439 class CreateIdxStatement : public DdlStatement
441 public:
442 DbRetVal execute(int &rowsAffected);
443 DbRetVal resolve(){return OK; }
445 CreateIdxStatement();
446 ~CreateIdxStatement();
450 class DropTblStatement : public DdlStatement
452 public:
453 DbRetVal execute(int &rowsAffected);
454 DbRetVal resolve(){return OK; }
456 DropTblStatement(){}
457 ~DropTblStatement(){}
459 class TruncateTblStatement : public DdlStatement
461 Table *table;
462 public:
463 DbRetVal execute(int &rowsAffected);
464 DbRetVal resolve();
466 TruncateTblStatement(){}
467 ~TruncateTblStatement(){}
471 class CacheTblStatement : public DdlStatement
473 public:
474 DbRetVal execute(int &rowsAffected);
475 DbRetVal resolve();
476 CacheTableLoader cacheLoader;
477 CacheTblStatement(){}
481 class UserTblStatement : public DdlStatement
483 public:
484 char userName[IDENTIFIER_LENGTH];
485 UserManager *usrMgr;
486 UserNodeType uType;
487 DbRetVal execute(int &rowsAffected);
488 DbRetVal resolve();
489 void setUserManager(UserManager *mgr,char *user){ usrMgr = mgr; strcpy(userName,user);}
490 UserTblStatement(){ usrMgr = NULL;}
491 //~UserTblStatement(){ delete usrMgr;}
494 class AlterTblStatement : public DdlStatement
496 public:
497 DbRetVal execute(int &rowsAffected);
498 DbRetVal resolve();
499 DbRetVal resolveForModifyColumn();
500 DbRetVal resolveForAddDropColumn();
501 DbRetVal executeForAddDropColumn(int &rowsAffected);
502 DbRetVal executeForModifyColumn(int &rowsAffected){}
503 DbRetVal createIndex(const char *oldName,const char *newName);
504 AlterTblStatement();
505 ~AlterTblStatement();
506 AlterTableType altType;
507 void **bindFieldValues;
508 int totalFields;
509 int noOfOldTabFld;
510 Table *table;
511 TableDef tblDef;
515 class DropIdxStatement : public DdlStatement
517 public:
518 DbRetVal execute(int &rowsAffected);
519 DbRetVal resolve() {return OK; }
520 DropIdxStatement(){}
521 ~DropIdxStatement(){}
523 class CompactTblStatement : public DdlStatement
525 Table *table;
526 public:
527 DbRetVal execute(int &rowsAffected);
528 DbRetVal resolve();
529 CompactTblStatement(){ table=NULL;}
530 ~CompactTblStatement(){}
533 class StatementFactory
535 public:
536 static Statement* getStatement(ParsedData *pData );
538 #endif