1 /***************************************************************************
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
5 ***************************************************************************/
7 #ifndef ABSSQLSTATEMENT_H
8 #define ABSSQLSTATEMENT_H
9 #include<AbsSqlConnection.h>
28 CompactTableStatement
,
38 * @class AbsSqlStatement
40 * @brief Handle to the sql statement.
41 * It is used to execute queries and return the values from the database<br>
42 * Sql Statement is fed to the prepare method first and then it should be executed. <br/>
43 * Functionality: <br/>
44 * 1.Input values for insert statement <br/>
45 * 2.Iterator for retrieving rows from the table <br/>
46 * 3.Parameter support for performance.<br/>
50 class DllExport AbsSqlStatement
54 AbsSqlStatement
*innerStmt
;
55 AbsSqlConnection
*con
;
57 void setInnerStatement(AbsSqlStatement
*stmt
) { innerStmt
= stmt
; }
58 AbsSqlStatement
*getInnerStatement() { return innerStmt
; }
59 /** sets connection handle to be used for subsequent operations
60 * @param con SqlConnection*
62 virtual void setConnection(AbsSqlConnection
*conn
) { con
= conn
; }
64 /** compiles the sql statement. It calls the parser and tokenizes the statement
65 * into logical plan. This method sets the statement string which needs to be executed.
66 * free method needs to be called, if application wants to use the same handle to compile
67 * another sql statement.
68 * @param stmt sql statement string
71 virtual DbRetVal
prepare(char *stmt
) = 0;
73 /** Executes directly for non parameterized statements **/
74 virtual DbRetVal
executeDirect(char *stmt
) = 0;
76 /** Retrieves the tablename of the prepared statement
77 * Used internally to get the tablename of the non select DML stmts
78 * @returns char* tablename
80 virtual char* getTableName()=0;
82 /** executes the sql statement. For insert, update, delete queries execute performs the
83 * required operation on the table.
84 * For Select queries, application should call execute before they start fetching
85 * the values from the table.This starts scan on the table.
86 * @param rowsAffect number of rows affected by the sql statement
89 virtual DbRetVal
execute(int &rowsAffect
)=0;
91 /**fetches the next tuple from the result of the execution of sql select query.
92 * execute should be called before calling this method. Application buffer should be
93 * binded to get the tuple values.
94 * @returns void* NULL if there is no tuple.
96 virtual void* fetch() = 0;
97 virtual void* fetch(DbRetVal
&rv
) = 0;
99 /**fetches the next tuple from the result of the execution of sql select query
100 * and prints it to stdout.
101 * execute should be called before calling this method.
102 * @returns void* NULL if there is no tuple.
104 virtual void* fetchAndPrint(bool SQL
) = 0;
107 /** binds application buffer to the specified parameter position in the sql statement.
108 * This method should be called for all the parameters in the sql statement.
109 * Parameters shall be specified for predicate for select, update, delete statements.
110 * Parameters shall be specified for field list value in SET of update statements.
111 * If value is not set for all parameters, execute will return error.
113 * @param pos position of the parameter in the statement
114 * @param val address of the application buffer. Memory should be allocated by
115 * the application before binding the buffer.
117 virtual DbRetVal
bindParam(int pos
, void*) = 0;
119 /** binds application buffer to the specified field position of the projection list
120 * in the select query or for fields in the insert statement.
121 * This method should be called for select queries, insert, update statements.
122 * Before executing select queries, required fields must be binded first.
123 * Before executing insert statement, required fields must be binded first.
124 * Before executing update statement, required fields to be updated must be
127 * @param pos position in the projection list
128 * @param val address of the application buffer. Memory should be allocated by
129 * the application before binding the buffer.
131 virtual DbRetVal
bindField(int pos
, void* val
) = 0;
133 /** same as fetch, but does not populate bindFieldValues
134 * @returns address void*
136 virtual void* next() = 0;
138 /**Closes the iterator and makes the statement ready for another execution
141 virtual DbRetVal
close() = 0;
143 /** get FieldValue->value ptr after fetch is done.
144 * @returns address void*
146 virtual void* getFieldValuePtr( int pos
) = 0;
147 virtual void* getFieldValuePtr( char *name
) = 0;
149 /**Frees all the resources held for the sql statement. Needs to be called before calling prepare again on the same statement handle.
152 virtual DbRetVal
free() = 0;
154 /**Retrieves the total number of projection fields in the statement
155 * @returns int no of projection fields
157 virtual int noOfProjFields() = 0;
159 /**Retrieves the total number of parameters in the statement
160 * @returns int no of parameters
162 virtual int noOfParamFields() = 0;
164 /**Retrieves the field info for the required projection field position in statement
165 * @param projPos int - projection field position
166 * @param info FieldInfo*& - OUT parameter
169 virtual DbRetVal
getProjFldInfo(int projPos
, FieldInfo
*&info
) = 0;
171 /**Retrieves the field info for the required parameter position in statement
172 * @param projPos int - parameter position
173 * @param info FieldInfo*& - OUT parameter
176 virtual DbRetVal
getParamFldInfo(int paramPos
, FieldInfo
*&info
) = 0;
178 /**Sets the value for the required parameter position in statement
179 * @param paramPos int - parameter position
180 * @param value short - value to be set
182 virtual void setShortParam(int paramPos
, short value
) = 0;
183 /**Sets the value for the required parameter position in statement
184 * @param paramPos int - parameter position
185 * @param value int - value to be set
187 virtual void setIntParam(int paramPos
, int value
) = 0;
188 /**Sets the value for the required parameter position in statement
189 * @param paramPos int - parameter position
190 * @param value long - value to be set
192 virtual void setLongParam(int paramPos
, long value
) =0;
193 /**Sets the value for the required parameter position in statement
194 * @param paramPos int - parameter position
195 * @param value long long - value to be set
197 virtual void setLongLongParam(int paramPos
, long long value
) =0;
198 /**Sets the value for the required parameter position in statement
199 * @param paramPos int - parameter position
200 * @param value ByteInt - value to be set
202 virtual void setByteIntParam(int paramPos
, ByteInt value
) = 0;
203 /**Sets the value for the required parameter position in statement
204 * @param paramPos int - parameter position
205 * @param value float - value to be set
207 virtual void setFloatParam(int paramPos
, float value
) = 0;
208 /**Sets the value for the required parameter position in statement
209 * @param paramPos int - parameter position
210 * @param value double - value to be set
212 virtual void setDoubleParam(int paramPos
, double value
) = 0;
213 /**Sets the value for the required parameter position in statement
214 * @param paramPos int - parameter position
215 * @param value char* - value to be set
217 virtual void setStringParam(int paramPos
, char *value
) = 0;
218 /**Sets the value for the required parameter position in statement
219 * @param paramPos int - parameter position
220 * @param value Date - value to be set
222 virtual void setDateParam(int paramPos
, Date value
) = 0;
223 /**Sets the value for the required parameter position in statement
224 * @param paramPos int - parameter position
225 * @param value Time - value to be set
227 virtual void setTimeParam(int paramPos
, Time value
) = 0;
228 /**Sets the value for the required parameter position in statement
229 * @param paramPos int - parameter position
230 * @param value TimeStamp - value to be set
232 virtual void setTimeStampParam(int paramPos
, TimeStamp value
) = 0;
233 /**Sets the value for the required parameter position in statement
234 * @param paramPos int - parameter position
235 * @param value Binary - value to be set
237 virtual void setBinaryParam(int paramPos
, void *value
, int length
) = 0;
239 /**Returns whether the statement prepared is select statement
240 * @return bool true if it is select stmt, false otherwise
242 virtual List
getTableNameList(){ List dummy
; return dummy
;}
243 virtual int getNoOfPagesForTable(char *tblName
)=0;
244 virtual DbRetVal
loadRecords(char *tblName
, void *buf
)=0;
245 virtual ResultSetPlan
getResultSetPlan()=0;
246 virtual bool isSelect() = 0;
247 virtual bool isFldNull(int pos
)=0;
248 virtual bool isFldNull(char *name
)=0;
249 virtual void setNull(int pos
)=0;
250 virtual int getFldPos(char *name
)=0;
251 virtual List
getAllTableNames(DbRetVal
&ret
)=0;
252 virtual List
getAllUserNames(DbRetVal
&ret
)=0;
253 virtual StatementType
getStmtType()=0;
254 virtual void getProjFieldType( int *data
)=0;
255 virtual long long getLastInsertedVal(DbRetVal
&ret
)=0;
256 virtual ~AbsSqlStatement()
258 if (innerStmt
) { delete innerStmt
; innerStmt
= NULL
; }
262 //used to store the binded field values and parameters from derived clases of
263 //AbsSqlStatement class
264 class DllExport BindSqlField
267 char fName
[IDENTIFIER_LENGTH
];
271 char defaultValueBuf
[DEFAULT_VALUE_BUF_LENGTH
];
278 BindSqlField(){ value
= NULL
; targetvalue
= NULL
; }
281 class DllExport BindSqlProjectField
284 char fName
[IDENTIFIER_LENGTH
];
288 char defaultValueBuf
[DEFAULT_VALUE_BUF_LENGTH
];
297 void *jdbcBindValue
; //For DATE ,TIME, TIMESTAMP
298 BindSqlProjectField()
300 value
= NULL
; targetvalue
= NULL
; jdbcBindValue
= NULL
; isFreed
= false; aType
= AGG_UNKNOWN
;
304 class DllExport StmtBucket
310 class DllExport StmtNode
314 AbsSqlStatement
*stmt
;