SqlGwStatement Class Reference

#include <SqlGwStatement.h>

Inheritance diagram for SqlGwStatement:

Inheritance graph
[legend]
Collaboration diagram for SqlGwStatement:

Collaboration graph
[legend]

Public Member Functions

 SqlGwStatement ()
void setAdapter (AbsSqlStatement *stmt)
void setConnection (AbsSqlConnection *conn)
 sets connection handle to be used for subsequent operations
DbRetVal prepare (char *stmt)
 compiles the sql statement.
DbRetVal execute (int &rowsAffect)
 executes the sql statement.
DbRetVal bindParam (int pos, void *)
 binds application buffer to the specified parameter position in the sql statement.
DbRetVal bindField (int pos, void *val)
 binds application buffer to the specified field position of the projection list in the select query or for fields in the insert statement.
void * fetch ()
 fetches the next tuple from the result of the execution of sql select query.
void * fetchAndPrint (bool SQL)
 fetches the next tuple from the result of the execution of sql select query and prints it to stdout.
void * next ()
 same as fetch, but does not populate bindFieldValues
DbRetVal close ()
 Closes the iterator and makes the statement ready for another execution.
int noOfProjFields ()
 Retrieves the total number of projection fields in the statement.
void * getFieldValuePtr (int pos)
 get FieldValue->value ptr after fetch is done.
DbRetVal free ()
 Frees all the resources held for the sql statement.
int noOfParamFields ()
 Retrieves the total number of parameters in the statement.
DbRetVal getProjFldInfo (int projPos, FieldInfo *&info)
 Retrieves the field info for the required projection field position in statement.
DbRetVal getParamFldInfo (int paramPos, FieldInfo *&info)
 Retrieves the field info for the required parameter position in statement.
void setShortParam (int paramPos, short value)
 Sets the value for the required parameter position in statement.
void setIntParam (int paramPos, int value)
 Sets the value for the required parameter position in statement.
void setLongParam (int paramPos, long value)
 Sets the value for the required parameter position in statement.
void setLongLongParam (int paramPos, long long value)
 Sets the value for the required parameter position in statement.
void setByteIntParam (int paramPos, ByteInt value)
 Sets the value for the required parameter position in statement.
void setFloatParam (int paramPos, float value)
 Sets the value for the required parameter position in statement.
void setDoubleParam (int paramPos, double value)
 Sets the value for the required parameter position in statement.
void setStringParam (int paramPos, char *value)
 Sets the value for the required parameter position in statement.
void setDateParam (int paramPos, Date value)
 Sets the value for the required parameter position in statement.
void setTimeParam (int paramPos, Time value)
 Sets the value for the required parameter position in statement.
void setTimeStampParam (int paramPos, TimeStamp value)
 Sets the value for the required parameter position in statement.
bool isSelect ()
 Returns whether the statement prepared is select statement.

Friends

class SqlFactory

Detailed Description

Definition at line 26 of file SqlGwStatement.h.


Constructor & Destructor Documentation

SqlGwStatement::SqlGwStatement (  )  [inline]

Definition at line 31 of file SqlGwStatement.h.

References AbsSqlStatement::con, and AbsSqlStatement::innerStmt.

00031 {innerStmt = NULL; adapter = NULL; con = NULL;}


Member Function Documentation

DbRetVal SqlGwStatement::bindField ( int  pos,
void *  val 
) [virtual]

binds application buffer to the specified field position of the projection list in the select query or for fields in the insert statement.

This method should be called for select queries, insert, update statements. Before executing select queries, required fields must be binded first. Before executing insert statement, required fields must be binded first. Before executing update statement, required fields to be updated must be binded first.

Parameters:
pos position in the projection list
val address of the application buffer. Memory should be allocated by the application before binding the buffer.

Implements AbsSqlStatement.

Definition at line 102 of file SqlGwStatement.cxx.

References AbsSqlStatement::bindField(), AbsSqlStatement::innerStmt, and OK.

00103 {
00104     DbRetVal rv = OK;
00105     //TODO::this will never be handled by both. check the flag for this
00106     if (adapter && shouldAdapterHandle()) rv = adapter->bindField(pos, value);
00107     if (rv != OK) return rv;
00108     if (innerStmt && shouldCSqlHandle()) rv = innerStmt->bindField(pos,value);
00109     return rv;
00110 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::bindParam ( int  pos,
void *   
) [virtual]

binds application buffer to the specified parameter position in the sql statement.

This method should be called for all the parameters in the sql statement. Parameters shall be specified for predicate for select, update, delete statements. Parameters shall be specified for field list value in SET of update statements. If value is not set for all parameters, execute will return error.

Parameters:
pos position of the parameter in the statement
val address of the application buffer. Memory should be allocated by the application before binding the buffer.

Implements AbsSqlStatement.

Definition at line 95 of file SqlGwStatement.cxx.

References ErrWarning, OK, and printError.

00096 {
00097     DbRetVal rv = OK;
00098     printError(ErrWarning, "Deprecated and does not replicate or cache");
00099     return rv;
00100 }

DbRetVal SqlGwStatement::close (  )  [virtual]

Closes the iterator and makes the statement ready for another execution.

Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 135 of file SqlGwStatement.cxx.

References AbsSqlStatement::close(), AbsSqlStatement::innerStmt, and OK.

00136 {
00137     //TODO::this will never be handled by both. check the flag for this
00138     if (adapter && shouldAdapterHandle()) return adapter->close();
00139     if (innerStmt && shouldCSqlHandle()) return innerStmt->close();
00140     return OK;
00141 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::execute ( int &  rowsAffect  )  [virtual]

executes the sql statement.

For insert, update, delete queries execute performs the required operation on the table. For Select queries, application should call execute before they start fetching the values from the table.This starts scan on the table.

Parameters:
rowsAffect number of rows affected by the sql statement
Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 86 of file SqlGwStatement.cxx.

References AbsSqlStatement::execute(), AbsSqlStatement::innerStmt, and OK.

00087 {
00088     DbRetVal rv = OK;
00089     if (adapter && shouldAdapterHandle()) rv = adapter->execute(rowsAffected);
00090     if (rv != OK) return rv;
00091     if (innerStmt && shouldCSqlHandle()) rv = innerStmt->execute(rowsAffected);
00092     return rv;
00093 }

Here is the call graph for this function:

void * SqlGwStatement::fetch (  )  [virtual]

fetches the next tuple from the result of the execution of sql select query.

execute should be called before calling this method. Application buffer should be binded to get the tuple values.

Returns:
void* NULL if there is no tuple.

Implements AbsSqlStatement.

Definition at line 111 of file SqlGwStatement.cxx.

References AbsSqlStatement::fetch(), and AbsSqlStatement::innerStmt.

00112 {
00113     //TODO::this will never be handled by both. check the flag for this
00114     if (adapter && shouldAdapterHandle()) return adapter->fetch();
00115     if (innerStmt && shouldCSqlHandle()) return innerStmt->fetch();
00116     return NULL;
00117 }

Here is the call graph for this function:

void * SqlGwStatement::fetchAndPrint ( bool  SQL  )  [virtual]

fetches the next tuple from the result of the execution of sql select query and prints it to stdout.

execute should be called before calling this method.

Returns:
void* NULL if there is no tuple.

Implements AbsSqlStatement.

Definition at line 119 of file SqlGwStatement.cxx.

References AbsSqlStatement::fetchAndPrint(), and AbsSqlStatement::innerStmt.

00120 {
00121     //TODO::this will never be handled by both. check the flag for this
00122     if (adapter && shouldAdapterHandle()) return adapter->fetchAndPrint(SQL);
00123     if (innerStmt && shouldCSqlHandle()) return innerStmt->fetchAndPrint(SQL);
00124     return NULL;
00125 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::free (  )  [virtual]

Frees all the resources held for the sql statement.

Needs to be called before calling prepare again on the same statement handle.

Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 180 of file SqlGwStatement.cxx.

References AbsSqlStatement::free(), AbsSqlStatement::innerStmt, and OK.

00181 {
00182     DbRetVal rv = OK;
00183     if (adapter && shouldAdapterHandle()) rv = adapter->free(); 
00184     if (innerStmt && shouldCSqlHandle()) rv = innerStmt->free();
00185     return rv;
00186 }

Here is the call graph for this function:

void * SqlGwStatement::getFieldValuePtr ( int  pos  )  [virtual]

get FieldValue->value ptr after fetch is done.

Returns:
address void*

Implements AbsSqlStatement.

Definition at line 143 of file SqlGwStatement.cxx.

References AbsSqlStatement::getFieldValuePtr(), and AbsSqlStatement::innerStmt.

00144 {
00145     //TODO::this will never be handled by both. check the flag for this
00146     if (adapter && shouldAdapterHandle()) return adapter->getFieldValuePtr(pos);
00147     if (innerStmt && shouldCSqlHandle()) return innerStmt->getFieldValuePtr(pos);
00148     return NULL;
00149 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::getParamFldInfo ( int  paramPos,
FieldInfo *&  info 
) [virtual]

Retrieves the field info for the required parameter position in statement.

Parameters:
projPos int - parameter position
info FieldInfo*& - OUT parameter
Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 173 of file SqlGwStatement.cxx.

References AbsSqlStatement::getParamFldInfo(), AbsSqlStatement::innerStmt, and OK.

00174 {
00175     if (innerStmt && shouldCSqlHandle()) return innerStmt->getParamFldInfo(parampos, fInfo);
00176     if (adapter && shouldAdapterHandle()) return adapter->getParamFldInfo(parampos, fInfo);
00177     return OK;
00178 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::getProjFldInfo ( int  projPos,
FieldInfo *&  info 
) [virtual]

Retrieves the field info for the required projection field position in statement.

Parameters:
projPos int - projection field position
info FieldInfo*& - OUT parameter
Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 166 of file SqlGwStatement.cxx.

References AbsSqlStatement::getProjFldInfo(), AbsSqlStatement::innerStmt, and OK.

00167 {
00168     if (innerStmt && shouldCSqlHandle()) return innerStmt->getProjFldInfo(projpos, fInfo);
00169     if (adapter && shouldAdapterHandle()) return adapter->getProjFldInfo(projpos, fInfo);
00170     return OK;
00171 }

Here is the call graph for this function:

bool SqlGwStatement::isSelect (  )  [virtual]

Returns whether the statement prepared is select statement.

Returns:
bool true if it is select stmt, false otherwise

Implements AbsSqlStatement.

Definition at line 78 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::isSelect().

00079 {
00080     bool retValue;
00081     if (adapter && shouldAdapterHandle()) retValue =  adapter->isSelect();
00082     if (innerStmt && shouldCSqlHandle()) retValue =  innerStmt->isSelect();
00083     return retValue;
00084 }

Here is the call graph for this function:

void * SqlGwStatement::next (  )  [virtual]

same as fetch, but does not populate bindFieldValues

Returns:
address void*

Implements AbsSqlStatement.

Definition at line 127 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::next().

00128 {
00129     //TODO::this will never be handled by both. check the flag for this
00130     if (adapter && shouldAdapterHandle()) return adapter->next();
00131     if (innerStmt && shouldCSqlHandle()) return innerStmt->next();
00132     return NULL;
00133 }

Here is the call graph for this function:

int SqlGwStatement::noOfParamFields (  )  [virtual]

Retrieves the total number of parameters in the statement.

Returns:
int no of parameters

Implements AbsSqlStatement.

Definition at line 159 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::noOfParamFields().

00160 {
00161     if (innerStmt && shouldCSqlHandle()) return innerStmt->noOfParamFields();
00162     if (adapter && shouldAdapterHandle()) return adapter->noOfParamFields();
00163     return 0;
00164 }

Here is the call graph for this function:

int SqlGwStatement::noOfProjFields (  )  [virtual]

Retrieves the total number of projection fields in the statement.

Returns:
int no of projection fields

Implements AbsSqlStatement.

Definition at line 151 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::noOfProjFields().

00152 {
00153     //TODO::this will never be handled by both. check the flag for this
00154     if (innerStmt && shouldCSqlHandle()) return innerStmt->noOfProjFields();
00155     if (adapter && shouldAdapterHandle()) return adapter->noOfProjFields();
00156     return 0;
00157 }

Here is the call graph for this function:

DbRetVal SqlGwStatement::prepare ( char *  stmt  )  [virtual]

compiles the sql statement.

It calls the parser and tokenizes the statement into logical plan. This method sets the statement string which needs to be executed. free method needs to be called, if application wants to use the same handle to compile another sql statement.

Parameters:
stmt sql statement string
Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 23 of file SqlGwStatement.cxx.

References AdapterHandler, AbsSqlStatement::con, conn, CSqlAndAdapterHandler, CSqlHandler, DM_Gateway, ErrSysInit, AbsSqlStatement::innerStmt, NoHandler, OK, AbsSqlStatement::prepare(), printDebug, printError, stmt, and TABLE_OSYNC.

00024 {
00025     DbRetVal rv = OK;
00026     SqlGwConnection *conn = (SqlGwConnection*) con;
00027     //conn->connectCSqlIfNotConnected();
00028     //conn->connectAdapterIfNotConnected();
00029     stmtHdlr = NoHandler;
00030     if (innerStmt) rv = innerStmt->prepare(stmtstr);
00031     SqlLogStatement *stmt = (SqlLogStatement*) innerStmt;
00032     if (rv == OK) {
00033         if (!stmt->isCached) { 
00034             stmtHdlr = CSqlHandler;
00035             return rv;  
00036         }else {
00037             if (stmt->mode != TABLE_OSYNC) {
00038                 stmtHdlr = CSqlHandler;
00039                 return rv;
00040             }else {
00041                 stmtHdlr = CSqlAndAdapterHandler;
00042             }
00043         }
00044     }
00045 
00046     //TODO::add procedures also in the below checking
00047     if (!strncasecmp(stmtstr,"INSERT", 6) == 0 &&
00048         !strncasecmp(stmtstr, "UPDATE", 6) ==0 &&
00049         !strncasecmp(stmtstr, "SELECT", 6) ==0 &&
00050         !strncasecmp(stmtstr, "DELETE", 6) ==0) return rv;
00051 
00052     //prepare failed. means table not there in csql->uncached table
00053     //or sql statement is complex and csql parser failed
00054     if (adapter) rv = adapter->prepare(stmtstr);
00055     if (rv == OK) { 
00056         printDebug(DM_Gateway, "Handled by csql %d\n", shouldCSqlHandle());
00057         if (!shouldCSqlHandle()) stmtHdlr = AdapterHandler;
00058         else stmtHdlr = CSqlAndAdapterHandler;
00059         printDebug(DM_Gateway, "Handled  %d\n", stmtHdlr);
00060     }
00061     else
00062         printError(ErrSysInit, "Both csql and adapter could not prepare\n");
00063     return rv;
00064 }

Here is the call graph for this function:

void SqlGwStatement::setAdapter ( AbsSqlStatement stmt  )  [inline]

Definition at line 32 of file SqlGwStatement.h.

References stmt.

Referenced by SqlFactory::createStatement().

00032 { adapter = stmt; }

Here is the caller graph for this function:

void SqlGwStatement::setByteIntParam ( int  paramPos,
ByteInt  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value ByteInt - value to be set

Implements AbsSqlStatement.

Definition at line 213 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setByteIntParam().

00214 {
00215     if (adapter && shouldAdapterHandle()) adapter->setByteIntParam(paramPos, value);
00216     if (innerStmt && shouldCSqlHandle()) innerStmt->setByteIntParam(paramPos,value);
00217     return;
00218 }

Here is the call graph for this function:

void SqlGwStatement::setConnection ( AbsSqlConnection conn  )  [inline, virtual]

sets connection handle to be used for subsequent operations

Parameters:
con SqlConnection*

Reimplemented from AbsSqlStatement.

Definition at line 34 of file SqlGwStatement.h.

References AbsSqlStatement::con, conn, SqlGwConnection::getAdapterConnection(), AbsSqlStatement::innerStmt, and AbsSqlStatement::setConnection().

00035     {
00036         if (innerStmt) innerStmt->setConnection(conn->getInnerConnection());
00037         SqlGwConnection *cn = (SqlGwConnection*) conn;
00038         if (adapter) adapter->setConnection(cn->getAdapterConnection());
00039         con = conn;
00040     }

Here is the call graph for this function:

void SqlGwStatement::setDateParam ( int  paramPos,
Date  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value Date - value to be set

Implements AbsSqlStatement.

Definition at line 238 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setDateParam().

00239 {
00240     if (adapter && shouldAdapterHandle()) adapter->setDateParam(paramPos, value);
00241     if (innerStmt && shouldCSqlHandle()) innerStmt->setDateParam(paramPos,value);
00242     return;
00243 }

Here is the call graph for this function:

void SqlGwStatement::setDoubleParam ( int  paramPos,
double  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value double - value to be set

Implements AbsSqlStatement.

Definition at line 225 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setDoubleParam().

00226 {
00227     if (adapter && shouldAdapterHandle()) adapter->setDoubleParam(paramPos, value);
00228     if (innerStmt && shouldCSqlHandle()) innerStmt->setDoubleParam(paramPos,value);
00229     return;
00230 
00231 }

Here is the call graph for this function:

void SqlGwStatement::setFloatParam ( int  paramPos,
float  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value float - value to be set

Implements AbsSqlStatement.

Definition at line 219 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setFloatParam().

00220 {
00221     if (adapter && shouldAdapterHandle()) adapter->setFloatParam(paramPos, value);
00222     if (innerStmt && shouldCSqlHandle()) innerStmt->setFloatParam(paramPos,value);
00223     return;
00224 }

Here is the call graph for this function:

void SqlGwStatement::setIntParam ( int  paramPos,
int  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value int - value to be set

Implements AbsSqlStatement.

Definition at line 193 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setIntParam().

00194 {
00195     if (adapter && shouldAdapterHandle()) adapter->setIntParam(paramPos, value);
00196     if (innerStmt && shouldCSqlHandle()) innerStmt->setIntParam(paramPos,value);
00197     return;
00198 
00199 }

Here is the call graph for this function:

void SqlGwStatement::setLongLongParam ( int  paramPos,
long long  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value long long - value to be set

Implements AbsSqlStatement.

Definition at line 207 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setLongLongParam().

00208 {
00209     if (adapter && shouldAdapterHandle()) adapter->setLongLongParam(paramPos, value);
00210     if (innerStmt && shouldCSqlHandle()) innerStmt->setLongLongParam(paramPos,value);
00211     return;
00212 }

Here is the call graph for this function:

void SqlGwStatement::setLongParam ( int  paramPos,
long  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value long - value to be set

Implements AbsSqlStatement.

Definition at line 200 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setLongParam().

00201 {
00202     if (adapter && shouldAdapterHandle()) adapter->setLongParam(paramPos, value);
00203     if (innerStmt && shouldCSqlHandle()) innerStmt->setLongParam(paramPos,value);
00204     return;
00205 
00206 }

Here is the call graph for this function:

void SqlGwStatement::setShortParam ( int  paramPos,
short  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value short - value to be set

Implements AbsSqlStatement.

Definition at line 187 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setShortParam().

00188 {
00189     if (adapter && shouldAdapterHandle()) adapter->setShortParam(paramPos, value);
00190     if (innerStmt && shouldCSqlHandle()) innerStmt->setShortParam(paramPos,value);
00191     return;
00192 }

Here is the call graph for this function:

void SqlGwStatement::setStringParam ( int  paramPos,
char *  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value char* - value to be set

Implements AbsSqlStatement.

Definition at line 232 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setStringParam().

00233 {
00234     if (adapter && shouldAdapterHandle()) adapter->setStringParam(paramPos, value);
00235     if (innerStmt && shouldCSqlHandle()) innerStmt->setStringParam(paramPos,value);
00236     return;
00237 }

Here is the call graph for this function:

void SqlGwStatement::setTimeParam ( int  paramPos,
Time  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value Time - value to be set

Implements AbsSqlStatement.

Definition at line 244 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setTimeParam().

00245 {
00246     if (adapter && shouldAdapterHandle()) adapter->setTimeParam(paramPos, value);
00247     if (innerStmt && shouldCSqlHandle()) innerStmt->setTimeParam(paramPos,value);
00248     return;
00249 }

Here is the call graph for this function:

void SqlGwStatement::setTimeStampParam ( int  paramPos,
TimeStamp  value 
) [virtual]

Sets the value for the required parameter position in statement.

Parameters:
paramPos int - parameter position
value TimeStamp - value to be set

Implements AbsSqlStatement.

Definition at line 250 of file SqlGwStatement.cxx.

References AbsSqlStatement::innerStmt, and AbsSqlStatement::setTimeStampParam().

00251 {
00252     if (adapter && shouldAdapterHandle()) adapter->setTimeStampParam(paramPos, value);
00253     if (innerStmt && shouldCSqlHandle()) innerStmt->setTimeStampParam(paramPos,value);
00254     return;
00255 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class SqlFactory [friend]

Definition at line 81 of file SqlGwStatement.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 22:51:39 2008 for csql by  doxygen 1.4.7