src/sql/Statement.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Prabakaran Thirumalai   *
00003  *   praba_tuty@yahoo.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef STATEMENT_H
00021 #define STATEMENT_H
00022 #include "Parser.h"
00023 
00024 class Statement
00025 {
00026     protected:
00027     ParsedData *parsedData;
00028     DatabaseManager *dbMgr;
00029 
00030     public:
00031     void setParsedData(ParsedData *pData) {  parsedData = pData; }
00032     void setDbMgr(DatabaseManager *dbmgr) { dbMgr = dbmgr; }
00033 
00034 
00035     virtual int noOfParamFields() { return  0; }
00036     virtual DbRetVal execute(int &rowsAffected)=0;
00037     virtual DbRetVal setParam(int paramNo, void *value)=0;
00038 
00039     virtual DbRetVal setShortParam(int paramNo, short value)=0;
00040     virtual DbRetVal setIntParam(int paramNo, int value)=0;
00041     virtual DbRetVal setLongParam(int paramNo, long value)=0;
00042     virtual DbRetVal setLongLongParam(int paramNo, long long value)=0;
00043     virtual DbRetVal setByteIntParam(int paramNo, ByteInt value)=0;
00044     virtual DbRetVal setFloatParam(int paramNo, float value)=0;
00045     virtual DbRetVal setDoubleParam(int paramNo, double value)=0;
00046     virtual DbRetVal setStringParam(int paramNo, char *value)=0;
00047     virtual DbRetVal setDateParam(int paramNo, Date value)=0;
00048     virtual DbRetVal setTimeParam(int paramNo, Time value)=0;
00049     virtual DbRetVal setTimeStampParam(int paramNo, TimeStamp value)=0;
00050 
00051 
00052     virtual DbRetVal resolve()=0;
00053     virtual ~Statement(){}
00054 };
00055 
00056 class DmlStatement : public Statement
00057 {
00058     protected:
00059     Table *table;
00060 
00061     void **params;
00062     //used to store FieldValue* for insert or ConditionValue* for other stmts
00063 
00064     char **paramValues;
00065     int totalParams;
00066 
00067     public:
00068     int noOfParamFields() { return totalParams; }
00069     virtual DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info) =0;
00070 
00071     virtual DbRetVal execute(int &rowsAffected)=0;
00072     virtual DbRetVal setParam(int paramNo, void *value)=0;
00073 
00074     virtual DbRetVal setShortParam(int paramNo, short value)=0;
00075     virtual DbRetVal setIntParam(int paramNo, int value)=0;
00076     virtual DbRetVal setLongParam(int paramNo, long value)=0;
00077     virtual DbRetVal setLongLongParam(int paramNo, long long value)=0;
00078     virtual DbRetVal setByteIntParam(int paramNo, ByteInt value)=0;
00079     virtual DbRetVal setFloatParam(int paramNo, float value)=0;
00080     virtual DbRetVal setDoubleParam(int paramNo, double value)=0;
00081     virtual DbRetVal setStringParam(int paramNo, char *value)=0;
00082     virtual DbRetVal setDateParam(int paramNo, Date value)=0;
00083     virtual DbRetVal setTimeParam(int paramNo, Time value)=0;
00084     virtual DbRetVal setTimeStampParam(int paramNo, TimeStamp value)=0;
00085 
00086 
00087     virtual DbRetVal resolve()=0;
00088     virtual void* getParamValuePtr( int pos )=0;
00089     virtual ~DmlStatement(){}
00090 };
00091 
00092 class InsStatement : public DmlStatement
00093 {
00094     public:
00095     DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
00096 
00097     DbRetVal execute(int &rowsAffected);
00098     DbRetVal setParam(int paramNo, void *value);
00099 
00100     DbRetVal setShortParam(int paramNo, short value);
00101     DbRetVal setIntParam(int paramNo, int value);
00102     DbRetVal setLongParam(int paramNo, long value);
00103     DbRetVal setLongLongParam(int paramNo, long long value);
00104     DbRetVal setByteIntParam(int paramNo, ByteInt value);
00105     DbRetVal setFloatParam(int paramNo, float value);
00106     DbRetVal setDoubleParam(int paramNo, double value);
00107     DbRetVal setStringParam(int paramNo, char *value);
00108     DbRetVal setDateParam(int paramNo, Date value);
00109     DbRetVal setTimeParam(int paramNo, Time value);
00110     DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
00111     void* getParamValuePtr( int );
00112     DbRetVal resolve();
00113     InsStatement();
00114     ~InsStatement();
00115 };
00116 
00117 class SelStatement : public DmlStatement
00118 {
00119     private:
00120     DbRetVal resolveStar();
00121     DbRetVal setBindFieldAndValues();
00122     DbRetVal resolveForCondition();
00123 
00124     public:
00125     FieldValue **bindFields;
00126     char **bindFieldValues;
00127     int totalFields;
00128 
00129 
00130     DbRetVal execute(int &rowsAffected);
00131     DbRetVal setParam(int paramNo, void *value);
00132 
00133     DbRetVal setShortParam(int paramNo, short value);
00134     DbRetVal setIntParam(int paramNo, int value);
00135     DbRetVal setLongParam(int paramNo, long value);
00136     DbRetVal setLongLongParam(int paramNo, long long value);
00137     DbRetVal setByteIntParam(int paramNo, ByteInt value);
00138     DbRetVal setFloatParam(int paramNo, float value);
00139     DbRetVal setDoubleParam(int paramNo, double value);
00140     DbRetVal setStringParam(int paramNo, char *value);
00141     DbRetVal setDateParam(int paramNo, Date value);
00142     DbRetVal setTimeParam(int paramNo, Time value);
00143     DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
00144 
00145     DbRetVal close();
00146     DbRetVal resolve();
00147     SelStatement();
00148     ~SelStatement();
00149 
00150 
00151     DbRetVal setBindField(int pos, void* value);
00152 
00153     int noOfProjFields();
00154     DbRetVal getProjFldInfo (int projpos, FieldInfo *&fInfo);
00155     DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
00156     
00157     void *getParamValuePtr( int );
00158     DataType getFieldType( int );
00159     int getFieldLength( int );
00160     char* getFieldName( int );
00161 
00162     void *fetch();
00163     void *fetch(DbRetVal &rv);
00164     void *fetchAndPrint(bool SQL);
00165     void *next();
00166     void *getFieldValuePtr( int );
00167 };
00168 
00169 class UpdStatement : public DmlStatement
00170 {
00171     public:
00172     DbRetVal execute(int &rowsAffected);
00173     DbRetVal setParam(int paramNo, void *value);
00174 
00175     DbRetVal setShortParam(int paramNo, short value);
00176     DbRetVal setIntParam(int paramNo, int value);
00177     DbRetVal setLongParam(int paramNo, long value);
00178     DbRetVal setLongLongParam(int paramNo, long long value);
00179     DbRetVal setByteIntParam(int paramNo, ByteInt value);
00180     DbRetVal setFloatParam(int paramNo, float value);
00181     DbRetVal setDoubleParam(int paramNo, double value);
00182     DbRetVal setStringParam(int paramNo, char *value);
00183     DbRetVal setDateParam(int paramNo, Date value);
00184     DbRetVal setTimeParam(int paramNo, Time value);
00185     DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
00186     void* getParamValuePtr(int);
00187     DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
00188 
00189 
00190     DbRetVal resolve();
00191     UpdStatement();
00192     ~UpdStatement();
00193 
00194     int totalAssignParams;
00195     DbRetVal resolveForAssignment();
00196 };
00197 
00198 class DelStatement : public DmlStatement
00199 {
00200     public:
00201     DbRetVal execute(int &rowsAffected);
00202     DbRetVal setParam(int paramNo, void *value);
00203 
00204     DbRetVal setShortParam(int paramNo, short value);
00205     DbRetVal setIntParam(int paramNo, int value);
00206     DbRetVal setLongParam(int paramNo, long value);
00207     DbRetVal setLongLongParam(int paramNo, long long value);
00208     DbRetVal setByteIntParam(int paramNo, ByteInt value);
00209     DbRetVal setFloatParam(int paramNo, float value);
00210     DbRetVal setDoubleParam(int paramNo, double value);
00211     DbRetVal setStringParam(int paramNo, char *value);
00212     DbRetVal setDateParam(int paramNo, Date value);
00213     DbRetVal setTimeParam(int paramNo, Time value);
00214     DbRetVal setTimeStampParam(int paramNo, TimeStamp value);
00215 
00216     DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
00217     void* getParamValuePtr(int);
00218     DbRetVal resolve();
00219     DelStatement();
00220     ~DelStatement();
00221 
00222     DbRetVal resolveForCondition(); //TODO::put this is Statement class, duplicated from SelStatement.
00223 
00224 };
00225 
00226 class DdlStatement : public Statement
00227 {
00228     public:
00229     DbRetVal execute(int &rowsAffected)=0; 
00230     //TODO: i think rowsAffected is not part of ddl - gopal said its design decision
00231     DbRetVal resolve()=0;
00232 
00233     DbRetVal setParam(int paramNo, void *value) { }
00234     DbRetVal setShortParam(int paramNo, short value) { }
00235     DbRetVal setIntParam(int paramNo, int value) { }
00236     DbRetVal setLongParam(int paramNo, long value) { }
00237     DbRetVal setLongLongParam(int paramNo, long long value) { }
00238     DbRetVal setByteIntParam(int paramNo, ByteInt value) { }
00239     DbRetVal setFloatParam(int paramNo, float value) { }
00240     DbRetVal setDoubleParam(int paramNo, double value) { }
00241     DbRetVal setStringParam(int paramNo, char *value) { }
00242     DbRetVal setDateParam(int paramNo, Date value) { }
00243     DbRetVal setTimeParam(int paramNo, Time value) { }
00244     DbRetVal setTimeStampParam(int paramNo, TimeStamp value) { }
00245 };
00246 
00247 class CreateTblStatement : public DdlStatement
00248 {
00249     public:
00250     DbRetVal execute(int &rowsAffected);
00251     DbRetVal resolve();
00252 
00253     CreateTblStatement();
00254     ~CreateTblStatement();
00255    
00256     private:
00257     char tblName[IDENTIFIER_LENGTH];  
00258     TableDef tblDef; 
00259 };
00260 
00261 class CreateIdxStatement : public DdlStatement
00262 {
00263     public:
00264     DbRetVal execute(int &rowsAffected);
00265     DbRetVal resolve(){return OK; }
00266 
00267     CreateIdxStatement();
00268     ~CreateIdxStatement();
00269 
00270 };
00271 
00272 class DropTblStatement : public DdlStatement
00273 {
00274     public:
00275     DbRetVal execute(int &rowsAffected);
00276     DbRetVal resolve(){return OK; }
00277 
00278     DropTblStatement(){}
00279     ~DropTblStatement(){}
00280 };
00281 class DropIdxStatement : public DdlStatement
00282 {
00283     public:
00284     DbRetVal execute(int &rowsAffected);
00285     DbRetVal resolve() {return OK; }
00286 
00287     DropIdxStatement(){}
00288     ~DropIdxStatement(){}
00289 };
00290 
00291 class StatementFactory
00292 {
00293     public:
00294     static Statement* getStatement(ParsedData *pData );
00295 };
00296 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7