corrected to accept hostname and connect to network
[csql.git] / include / Statement.h
blob04cbf6cd3fc0fb98fc6a4e899f3be290008c3eb1
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"
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)=0;
51 virtual DbRetVal resolve()=0;
52 virtual bool isFldNull(int pos)=0;
53 virtual int getFldPos(char *name)=0;
54 virtual DbRetVal setNull(int pos)=0;
55 virtual ~Statement(){}
58 class DmlStatement : public Statement
60 protected:
61 Table *table;
63 void **params;
64 //used to store FieldValue* for insert or ConditionValue* for other stmts
66 char **paramValues;
67 int totalParams;
69 public:
70 int noOfParamFields() { return totalParams; }
71 virtual DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info) =0;
73 virtual DbRetVal execute(int &rowsAffected)=0;
74 virtual DbRetVal setParam(int paramNo, void *value)=0;
76 virtual DbRetVal setShortParam(int paramNo, short value)=0;
77 virtual DbRetVal setIntParam(int paramNo, int value)=0;
78 virtual DbRetVal setLongParam(int paramNo, long value)=0;
79 virtual DbRetVal setLongLongParam(int paramNo, long long value)=0;
80 virtual DbRetVal setByteIntParam(int paramNo, ByteInt value)=0;
81 virtual DbRetVal setFloatParam(int paramNo, float value)=0;
82 virtual DbRetVal setDoubleParam(int paramNo, double value)=0;
83 virtual DbRetVal setStringParam(int paramNo, char *value)=0;
84 virtual DbRetVal setDateParam(int paramNo, Date value)=0;
85 virtual DbRetVal setTimeParam(int paramNo, Time value)=0;
86 virtual DbRetVal setTimeStampParam(int paramNo, TimeStamp value)=0;
87 virtual DbRetVal setBinaryParam(int paramNo, void *value)=0;
88 virtual bool isFldNull(int pos)=0;
89 virtual DbRetVal setNull(int pos)=0;
90 virtual DbRetVal resolve()=0;
91 virtual void* getParamValuePtr( int pos )=0;
92 virtual int getFldPos(char *name)=0;
93 virtual ~DmlStatement(){}
96 class InsStatement : public DmlStatement
98 public:
99 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
101 DbRetVal execute(int &rowsAffected);
102 DbRetVal setParam(int paramNo, void *value);
104 DbRetVal setShortParam(int paramNo, short value);
105 DbRetVal setIntParam(int paramNo, int value);
106 DbRetVal setLongParam(int paramNo, long value);
107 DbRetVal setLongLongParam(int paramNo, long long value);
108 DbRetVal setByteIntParam(int paramNo, ByteInt value);
109 DbRetVal setFloatParam(int paramNo, float value);
110 DbRetVal setDoubleParam(int paramNo, double value);
111 DbRetVal setStringParam(int paramNo, char *value);
112 DbRetVal setDateParam(int paramNo, Date value);
113 DbRetVal setTimeParam(int paramNo, Time value);
114 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
115 DbRetVal setBinaryParam(int paramNo, void *value);
116 bool isFldNull(int pos){return table->isFldNull(pos);}
117 void* getParamValuePtr( int );
118 int getFldPos(char *name);
119 DbRetVal setNull(int pos);
120 DbRetVal resolve();
121 InsStatement();
122 ~InsStatement();
125 class SelStatement : public DmlStatement
127 private:
128 DbRetVal resolveStar();
129 DbRetVal setBindFieldAndValues();
130 DbRetVal resolveForCondition();
132 public:
133 FieldValue **bindFields;
134 char **bindFieldValues;
135 int totalFields;
138 DbRetVal execute(int &rowsAffected);
139 DbRetVal setParam(int paramNo, void *value);
141 DbRetVal setShortParam(int paramNo, short value);
142 DbRetVal setIntParam(int paramNo, int value);
143 DbRetVal setLongParam(int paramNo, long value);
144 DbRetVal setLongLongParam(int paramNo, long long value);
145 DbRetVal setByteIntParam(int paramNo, ByteInt value);
146 DbRetVal setFloatParam(int paramNo, float value);
147 DbRetVal setDoubleParam(int paramNo, double value);
148 DbRetVal setStringParam(int paramNo, char *value);
149 DbRetVal setDateParam(int paramNo, Date value);
150 DbRetVal setTimeParam(int paramNo, Time value);
151 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
152 DbRetVal setBinaryParam(int paramNo, void *value);
154 DbRetVal replaceStarWithFirstFldName(FieldName *name);
155 DbRetVal resolveGroupFld(AggTableImpl *impl);
156 bool isFldNull(int pos){return table->isFldNull(pos);}
157 int getFldPos(char *name);
158 DbRetVal setNull(int pos){}
159 DbRetVal close();
160 DbRetVal resolve();
161 SelStatement();
162 ~SelStatement();
164 DbRetVal openTables();
166 DbRetVal setBindField(int pos, void* value);
168 int noOfProjFields();
169 DbRetVal getProjFldInfo (int projpos, FieldInfo *&fInfo);
170 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
172 void *getParamValuePtr( int );
173 DataType getFieldType( int );
174 int getFieldLength( int );
175 char* getFieldName( int );
177 void *fetch();
178 void *fetch(DbRetVal &rv);
179 void *fetchAndPrint(bool SQL);
180 void *next();
181 void *getFieldValuePtr( int );
184 class UpdStatement : public DmlStatement
186 public:
187 DbRetVal execute(int &rowsAffected);
188 DbRetVal setParam(int paramNo, void *value);
190 DbRetVal setShortParam(int paramNo, short value);
191 DbRetVal setIntParam(int paramNo, int value);
192 DbRetVal setLongParam(int paramNo, long value);
193 DbRetVal setLongLongParam(int paramNo, long long value);
194 DbRetVal setByteIntParam(int paramNo, ByteInt value);
195 DbRetVal setFloatParam(int paramNo, float value);
196 DbRetVal setDoubleParam(int paramNo, double value);
197 DbRetVal setStringParam(int paramNo, char *value);
198 DbRetVal setDateParam(int paramNo, Date value);
199 DbRetVal setTimeParam(int paramNo, Time value);
200 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
201 DbRetVal setBinaryParam(int paramNo, void *value);
202 void* getParamValuePtr(int);
203 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
204 bool isFldNull(int pos){return table->isFldNull(pos);}
205 int getFldPos(char *name);
206 DbRetVal setNull(int pos){}
207 DbRetVal resolve();
208 UpdStatement();
209 ~UpdStatement();
211 int totalAssignParams;
212 DbRetVal resolveForAssignment();
215 class DelStatement : public DmlStatement
217 public:
218 DbRetVal execute(int &rowsAffected);
219 DbRetVal setParam(int paramNo, void *value);
221 DbRetVal setShortParam(int paramNo, short value);
222 DbRetVal setIntParam(int paramNo, int value);
223 DbRetVal setLongParam(int paramNo, long value);
224 DbRetVal setLongLongParam(int paramNo, long long value);
225 DbRetVal setByteIntParam(int paramNo, ByteInt value);
226 DbRetVal setFloatParam(int paramNo, float value);
227 DbRetVal setDoubleParam(int paramNo, double value);
228 DbRetVal setStringParam(int paramNo, char *value);
229 DbRetVal setDateParam(int paramNo, Date value);
230 DbRetVal setTimeParam(int paramNo, Time value);
231 DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
232 DbRetVal setBinaryParam(int paramNo, void *value);
233 bool isFldNull(int pos){return table->isFldNull(pos);}
234 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
235 void* getParamValuePtr(int);
236 DbRetVal setNull(int pos){}
237 DbRetVal resolve();
238 DelStatement();
239 ~DelStatement();
240 int getFldPos(char *name);
241 DbRetVal resolveForCondition(); //TODO::put this is Statement class, duplicated from SelStatement.
245 class DdlStatement : public Statement
247 public:
248 DbRetVal execute(int &rowsAffected)=0;
249 //TODO: i think rowsAffected is not part of ddl - gopal said its design decision
250 DbRetVal resolve()=0;
252 DbRetVal setParam(int paramNo, void *value) { }
253 DbRetVal setShortParam(int paramNo, short value) { }
254 DbRetVal setIntParam(int paramNo, int value) { }
255 DbRetVal setLongParam(int paramNo, long value) { }
256 DbRetVal setLongLongParam(int paramNo, long long value) { }
257 DbRetVal setByteIntParam(int paramNo, ByteInt value) { }
258 DbRetVal setFloatParam(int paramNo, float value) { }
259 DbRetVal setDoubleParam(int paramNo, double value) { }
260 DbRetVal setStringParam(int paramNo, char *value) { }
261 DbRetVal setDateParam(int paramNo, Date value) { }
262 DbRetVal setTimeParam(int paramNo, Time value) { }
263 DbRetVal setTimeStampParam(int paramNo, TimeStamp value) { }
264 DbRetVal setBinaryParam(int paramNo, void *value) { }
265 bool isFldNull(int pos){ }
266 int getFldPos(char *name){}
267 DbRetVal setNull(int pos){}
270 class CreateTblStatement : public DdlStatement
272 public:
273 DbRetVal execute(int &rowsAffected);
274 DbRetVal resolve();
275 DbRetVal checkForDot(char *name);
276 CreateTblStatement();
277 ~CreateTblStatement();
279 private:
280 char tblName[IDENTIFIER_LENGTH];
281 TableDef tblDef;
284 class CreateIdxStatement : public DdlStatement
286 public:
287 DbRetVal execute(int &rowsAffected);
288 DbRetVal resolve(){return OK; }
290 CreateIdxStatement();
291 ~CreateIdxStatement();
295 class DropTblStatement : public DdlStatement
297 public:
298 DbRetVal execute(int &rowsAffected);
299 DbRetVal resolve(){return OK; }
301 DropTblStatement(){}
302 ~DropTblStatement(){}
304 class DropIdxStatement : public DdlStatement
306 public:
307 DbRetVal execute(int &rowsAffected);
308 DbRetVal resolve() {return OK; }
310 DropIdxStatement(){}
311 ~DropIdxStatement(){}
314 class StatementFactory
316 public:
317 static Statement* getStatement(ParsedData *pData );
319 #endif