1738556 Primitive ODBC Driver
[csql.git] / include / SqlStatement.h
blob432b9432257a891057760bdd5f3bb118770ffba0
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 SQLSTATEMENT_H
21 #define SQLSTATEMENT_H
22 #include <AbsSqlStatement.h>
23 #include <SqlConnection.h>
24 #include <SqlFactory.h>
25 #include "Statement.h"
26 //#include<CSql.h>
27 class Statement;
28 class ParsedData;
30 class SqlStatement: public AbsSqlStatement
32 public:
33 SqlStatement();
34 /** sets connection handle to be used for subsequent operations
35 * @param con SqlConnection*
37 void setConnection(AbsSqlConnection *con);
38 void setSqlConnection(SqlConnection *con);
40 /** compiles the sql statement. It calls the parser and tokenizes the statement
41 * into logical plan. This method sets the statement string which needs to be executed.
42 * free method needs to be called, if application wants to use the same handle to compile
43 * another sql statement.
44 * @param stmt sql statement string
45 * @returns DbRetVal
47 DbRetVal prepare(char *stmt);
49 char* getTableName();
51 /** executes the sql statement. For insert, update, delete queries execute performs the
52 * required operation on the table.
53 * For Select queries, application should call execute before they start fetching
54 * the values from the table.This starts scan on the table.
55 * @param rowsAffect number of rows affected by the sql statement
56 * @returns DbRetVal
58 DbRetVal execute(int &rowsAffect);
60 /**fetches the next tuple from the result of the execution of sql select query.
61 * execute should be called before calling this method. Application buffer should be
62 * binded to get the tuple values.
63 * @returns void* NULL if there is no tuple.
65 void* fetch();
68 /**fetches the next tuple from the result of the execution of sql select query
69 * and prints it to stdout.
70 * execute should be called before calling this method.
71 * @returns void* NULL if there is no tuple.
73 void* fetchAndPrint(bool SQL);
76 /** binds application buffer to the specified parameter position in the sql statement.
77 * This method should be called for all the parameters in the sql statement.
78 * Parameters shall be specified for predicate for select, update, delete statements.
79 * Parameters shall be specified for field list value in SET of update statements.
80 * If value is not set for all parameters, execute will return error.
81 * <br/>
82 * @param pos position of the parameter in the statement
83 * @param val address of the application buffer. Memory should be allocated by
84 * the application before binding the buffer.
86 DbRetVal bindParam(int pos, void*);
88 /** binds application buffer to the specified field position of the projection list
89 * in the select query or for fields in the insert statement.
90 * This method should be called for select queries, insert, update statements.
91 * Before executing select queries, required fields must be binded first.
92 * Before executing insert statement, required fields must be binded first.
93 * Before executing update statement, required fields to be updated must be
94 * binded first.
95 * <br/>
96 * @param pos position in the projection list
97 * @param val address of the application buffer. Memory should be allocated by
98 * the application before binding the buffer.
100 DbRetVal bindField(int pos, void* val);
102 /** same as fetch, but does not populate bindFieldValues
103 * @returns address void*
105 void* next();
107 /**Closes the iterator and makes the statement ready for another execution
108 * @returns DbRetVal
110 DbRetVal close();
112 /** get FieldValue->value ptr after fetch is done.
113 * @returns address void*
115 void* getFieldValuePtr( int pos );
117 /**Frees all the resources held for the sql statement. Needs to be called before calling prepare again on the same statement handle.
118 * @returns DbRetVal
120 DbRetVal free();
122 /**Retrieves the total number of projection fields in the statement
123 * @returns int no of projection fields
125 int noOfProjFields();
127 /** get Param value pointer after fetch is done.
128 * @returns address void*
130 void* getParamValuePtr( int pos );
132 /** get FieldValue->type
133 * @returns DataType
135 DataType getFieldType( int pos );
137 /** get FieldValue->length
138 * @returns int
140 int getFieldLength( int pos );
142 /** get FieldName
143 * @returns address char*
145 char* getFieldName ( int pos );
147 /**Retrieves the total number of parameters in the statement
148 * @returns int no of parameters
150 int noOfParamFields();
152 /**Retrieves the field info for the required projection field position in statement
153 * @param projPos int - projection field position
154 * @param info FieldInfo*& - OUT parameter
155 * @returns DbRetVal
157 DbRetVal getProjFldInfo(int projPos, FieldInfo *&info);
159 /**Retrieves the field info for the required parameter position in statement
160 * @param projPos int - parameter position
161 * @param info FieldInfo*& - OUT parameter
162 * @returns DbRetVal
164 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
166 /**Sets the value for the required parameter position in statement
167 * @param paramPos int - parameter position
168 * @param value short - value to be set
170 void setShortParam(int paramPos, short value);
171 /**Sets the value for the required parameter position in statement
172 * @param paramPos int - parameter position
173 * @param value int - value to be set
175 void setIntParam(int paramPos, int value);
176 /**Sets the value for the required parameter position in statement
177 * @param paramPos int - parameter position
178 * @param value long - value to be set
180 void setLongParam(int paramPos, long value);
181 /**Sets the value for the required parameter position in statement
182 * @param paramPos int - parameter position
183 * @param value long long - value to be set
185 void setLongLongParam(int paramPos, long long value);
186 /**Sets the value for the required parameter position in statement
187 * @param paramPos int - parameter position
188 * @param value ByteInt - value to be set
190 void setByteIntParam(int paramPos, ByteInt value);
191 /**Sets the value for the required parameter position in statement
192 * @param paramPos int - parameter position
193 * @param value float - value to be set
195 void setFloatParam(int paramPos, float value);
196 /**Sets the value for the required parameter position in statement
197 * @param paramPos int - parameter position
198 * @param value double - value to be set
200 void setDoubleParam(int paramPos, double value);
201 /**Sets the value for the required parameter position in statement
202 * @param paramPos int - parameter position
203 * @param value char* - value to be set
205 void setStringParam(int paramPos, char *value);
206 /**Sets the value for the required parameter position in statement
207 * @param paramPos int - parameter position
208 * @param value Date - value to be set
210 void setDateParam(int paramPos, Date value);
211 /**Sets the value for the required parameter position in statement
212 * @param paramPos int - parameter position
213 * @param value Time - value to be set
215 void setTimeParam(int paramPos, Time value);
216 /**Sets the value for the required parameter position in statement
217 * @param paramPos int - parameter position
218 * @param value TimeStamp - value to be set
220 void setTimeStampParam(int paramPos, TimeStamp value);
222 /**Returns whether the statement prepared is select statement
223 * @return bool true if it is select stmt, false otherwise
225 bool isSelect();
227 private:
228 SqlConnection *sqlCon;
229 Statement *stmt;
230 ParsedData pData;
231 friend class SqlFactory;
234 #endif