1912116 remove getMaxTrans and getMaxThreads from Config
[csql.git] / include / SqlStatement.h
blobbc9f22b06ef902f3c6b1ad44bb836e938901b3e4
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();
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 /**Retrieves the total number of parameters in the statement
128 * @returns int no of parameters
130 int noOfParamFields();
132 /**Retrieves the field info for the required projection field position in statement
133 * @param projPos int - projection field position
134 * @param info FieldInfo*& - OUT parameter
135 * @returns DbRetVal
137 DbRetVal getProjFldInfo(int projPos, FieldInfo *&info);
139 /**Retrieves the field info for the required parameter position in statement
140 * @param projPos int - parameter position
141 * @param info FieldInfo*& - OUT parameter
142 * @returns DbRetVal
144 DbRetVal getParamFldInfo(int paramPos, FieldInfo *&info);
146 /**Sets the value for the required parameter position in statement
147 * @param paramPos int - parameter position
148 * @param value short - value to be set
150 void setShortParam(int paramPos, short value);
151 /**Sets the value for the required parameter position in statement
152 * @param paramPos int - parameter position
153 * @param value int - value to be set
155 void setIntParam(int paramPos, int value);
156 /**Sets the value for the required parameter position in statement
157 * @param paramPos int - parameter position
158 * @param value long - value to be set
160 void setLongParam(int paramPos, long value);
161 /**Sets the value for the required parameter position in statement
162 * @param paramPos int - parameter position
163 * @param value long long - value to be set
165 void setLongLongParam(int paramPos, long long value);
166 /**Sets the value for the required parameter position in statement
167 * @param paramPos int - parameter position
168 * @param value ByteInt - value to be set
170 void setByteIntParam(int paramPos, ByteInt value);
171 /**Sets the value for the required parameter position in statement
172 * @param paramPos int - parameter position
173 * @param value float - value to be set
175 void setFloatParam(int paramPos, float value);
176 /**Sets the value for the required parameter position in statement
177 * @param paramPos int - parameter position
178 * @param value double - value to be set
180 void setDoubleParam(int paramPos, double value);
181 /**Sets the value for the required parameter position in statement
182 * @param paramPos int - parameter position
183 * @param value char* - value to be set
185 void setStringParam(int paramPos, char *value);
186 /**Sets the value for the required parameter position in statement
187 * @param paramPos int - parameter position
188 * @param value Date - value to be set
190 void setDateParam(int paramPos, Date value);
191 /**Sets the value for the required parameter position in statement
192 * @param paramPos int - parameter position
193 * @param value Time - value to be set
195 void setTimeParam(int paramPos, Time value);
196 /**Sets the value for the required parameter position in statement
197 * @param paramPos int - parameter position
198 * @param value TimeStamp - value to be set
200 void setTimeStampParam(int paramPos, TimeStamp value);
202 /**Returns whether the statement prepared is select statement
203 * @return bool true if it is select stmt, false otherwise
205 bool isSelect();
207 private:
208 SqlConnection *sqlCon;
209 Statement *stmt;
210 ParsedData pData;
211 friend class SqlFactory;
214 #endif