SqlStatement Class Reference

#include <SqlStatement.h>

Inheritance diagram for SqlStatement:

Inheritance graph
[legend]
Collaboration diagram for SqlStatement:

Collaboration graph
[legend]

Public Member Functions

 SqlStatement ()
void setConnection (AbsSqlConnection *con)
 sets connection handle to be used for subsequent operations
void setSqlConnection (SqlConnection *con)
DbRetVal prepare (char *stmt)
 compiles the sql statement.
char * getTableName ()
 Retrieves the tablename of the prepared statement Used internally to get the tablename of the non select DML stmts.
DbRetVal execute (int &rowsAffect)
 executes the sql statement.
void * fetch ()
 fetches the next tuple from the result of the execution of sql select query.
void * fetch (DbRetVal &rv)
void * fetchAndPrint (bool SQL)
 fetches the next tuple from the result of the execution of sql select query and prints it to stdout.
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 * next ()
 same as fetch, but does not populate bindFieldValues
DbRetVal close ()
 Closes the iterator and makes the statement ready for another execution.
void * getFieldValuePtr (int pos)
 get FieldValue->value ptr after fetch is done.
DbRetVal free ()
 Frees all the resources held for the sql statement.
int noOfProjFields ()
 Retrieves the total number of projection fields in the statement.
void * getParamValuePtr (int pos)
 get Param value pointer after fetch is done.
DataType getFieldType (int pos)
 get FieldValue->type
int getFieldLength (int pos)
 get FieldValue->length
char * getFieldName (int pos)
 get FieldName
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.
bool isPrepared ()
 Returns whether the statement is prepared or not.

Friends

class SqlFactory

Detailed Description

Definition at line 30 of file SqlStatement.h.


Constructor & Destructor Documentation

SqlStatement::SqlStatement (  ) 

Definition at line 29 of file SqlStatement.cxx.

00030 {
00031     sqlCon = NULL;
00032     stmt = NULL;
00033     isPrepd = false;
00034 }


Member Function Documentation

DbRetVal SqlStatement::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 161 of file SqlStatement.cxx.

References ErrBadCall, ParsedData::getStmtType(), OK, SelectStatement, and SelStatement::setBindField().

00162 {
00163     DbRetVal rv = OK;
00164     if (pData.getStmtType() != SelectStatement) return ErrBadCall;
00165     SelStatement *selStmt = (SelStatement*) stmt; 
00166     rv = selStmt->setBindField(pos, value);
00167     return rv;
00168 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 154 of file SqlStatement.cxx.

References OK, and Statement::setParam().

00155 {
00156     DbRetVal rv = OK;
00157     rv = stmt->setParam(pos, value);
00158     return rv;
00159 }

Here is the call graph for this function:

DbRetVal SqlStatement::close (  )  [virtual]

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

Returns:
DbRetVal

Implements AbsSqlStatement.

Definition at line 176 of file SqlStatement.cxx.

References SelStatement::close(), ParsedData::getStmtType(), OK, and SelectStatement.

00177 {
00178     if (pData.getStmtType() != SelectStatement) return OK;
00179     SelStatement *selStmt = (SelStatement*) stmt; 
00180     return selStmt->close();
00181 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 94 of file SqlStatement.cxx.

References ErrNotOpen, ErrNotPrepared, Statement::execute(), SqlConnection::isConnectionOpen(), isPrepared(), OK, and printError.

00095 {
00096     DbRetVal rv = OK;
00097     if (! sqlCon->isConnectionOpen()) {
00098         printError(ErrNotOpen, "Connection not open");
00099         return ErrNotOpen;
00100     }
00101     if (! isPrepared()) {
00102         printError(ErrNotPrepared, "Statement Not Prepared");
00103         return ErrNotPrepared;
00104     }
00105     rv = stmt->execute(rowsAffected);
00106     return rv;
00107 }

Here is the call graph for this function:

void * SqlStatement::fetch ( DbRetVal rv  ) 

Definition at line 124 of file SqlStatement.cxx.

References ErrNotOpen, ErrNotPrepared, SelStatement::fetch(), ParsedData::getStmtType(), SqlConnection::isConnectionOpen(), isPrepared(), printError, and SelectStatement.

00125 {
00126     if (! sqlCon->isConnectionOpen()) {
00127         printError(ErrNotOpen, "Connection not open");
00128         return NULL;
00129     }
00130     if (! isPrepared()) {
00131         printError(ErrNotPrepared, "Statement Not Prepared");
00132         return NULL;
00133     }
00134     if (pData.getStmtType() != SelectStatement) return NULL;
00135     SelStatement *selStmt = (SelStatement*) stmt; 
00136     return selStmt->fetch(rv);
00137 }

Here is the call graph for this function:

void * SqlStatement::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 109 of file SqlStatement.cxx.

References ErrNotOpen, ErrNotPrepared, SelStatement::fetch(), ParsedData::getStmtType(), SqlConnection::isConnectionOpen(), isPrepared(), printError, and SelectStatement.

00110 {
00111     if (! sqlCon->isConnectionOpen()) {
00112         printError(ErrNotOpen, "Connection not open");
00113         return NULL;
00114     }
00115     if (! isPrepared()) {
00116         printError(ErrNotPrepared, "Statement Not Prepared");
00117         return NULL;
00118     }
00119     if (pData.getStmtType() != SelectStatement) return NULL;
00120     SelStatement *selStmt = (SelStatement*) stmt; 
00121     return selStmt->fetch();
00122 }

Here is the call graph for this function:

void * SqlStatement::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 139 of file SqlStatement.cxx.

References ErrNotOpen, ErrNotPrepared, SelStatement::fetchAndPrint(), ParsedData::getStmtType(), SqlConnection::isConnectionOpen(), isPrepared(), printError, and SelectStatement.

00140 {
00141     if (! sqlCon->isConnectionOpen()) {
00142         printError(ErrNotOpen, "Connection not open");
00143         return NULL;
00144     }
00145     if (! isPrepared()) {
00146         printError(ErrNotPrepared, "Statement Not Prepared");
00147         return NULL;
00148     }
00149     if (pData.getStmtType() != SelectStatement) return NULL;
00150     SelStatement *selStmt = (SelStatement*) stmt; 
00151     return selStmt->fetchAndPrint(SQL);
00152 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 252 of file SqlStatement.cxx.

References OK, and ParsedData::reset().

Referenced by prepare().

00253 {
00254     delete stmt;
00255     stmt = NULL;
00256     pData.reset();
00257     isPrepd = false;
00258     return OK;
00259 }

Here is the call graph for this function:

Here is the caller graph for this function:

int SqlStatement::getFieldLength ( int  pos  ) 

get FieldValue->length

Returns:
int

Definition at line 202 of file SqlStatement.cxx.

References SelStatement::getFieldLength(), ParsedData::getStmtType(), and SelectStatement.

00203 {
00204     if (pData.getStmtType() != SelectStatement) return 0;
00205     SelStatement *selStmt = (SelStatement*) stmt;
00206     return( (int) selStmt->getFieldLength( pos ) );
00207 }

Here is the call graph for this function:

char * SqlStatement::getFieldName ( int  pos  ) 

get FieldName

Returns:
address char*

Definition at line 189 of file SqlStatement.cxx.

References SelStatement::getFieldName(), ParsedData::getStmtType(), and SelectStatement.

00190 {
00191     if (pData.getStmtType() != SelectStatement) return 0;
00192     SelStatement *selStmt = (SelStatement*) stmt;
00193     return( (char*) selStmt->getFieldName( pos ) );
00194 }

Here is the call graph for this function:

DataType SqlStatement::getFieldType ( int  pos  ) 

get FieldValue->type

Returns:
DataType

Definition at line 196 of file SqlStatement.cxx.

References SelStatement::getFieldType(), ParsedData::getStmtType(), SelectStatement, and typeUnknown.

00197 {
00198     if (pData.getStmtType() != SelectStatement) return typeUnknown;
00199     SelStatement *selStmt = (SelStatement*) stmt;
00200     return( (DataType) selStmt->getFieldType( pos ) );
00201 }

Here is the call graph for this function:

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

get FieldValue->value ptr after fetch is done.

Returns:
address void*

Implements AbsSqlStatement.

Definition at line 209 of file SqlStatement.cxx.

References SelStatement::getFieldValuePtr(), ParsedData::getStmtType(), and SelectStatement.

00210 {
00211     if (pData.getStmtType() != SelectStatement) return 0;
00212     SelStatement *selStmt = (SelStatement*) stmt; 
00213     return( (void*) selStmt->getFieldValuePtr( pos ) );
00214 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 237 of file SqlStatement.cxx.

References DeleteStatement, ParsedData::getStmtType(), InsertStatement, OK, SelectStatement, and UpdateStatement.

00238 {
00239     DbRetVal rv = OK;
00240     if (pData.getStmtType() ==SelectStatement ||
00241         pData.getStmtType() ==InsertStatement ||
00242         pData.getStmtType() ==UpdateStatement ||
00243         pData.getStmtType() ==DeleteStatement)
00244     {
00245  
00246         DmlStatement *dmlStmt = (DmlStatement*) stmt; 
00247         rv = dmlStmt->getParamFldInfo(parampos, fInfo);
00248     }
00249     return rv;
00250 }

Here is the call graph for this function:

void * SqlStatement::getParamValuePtr ( int  pos  ) 

get Param value pointer after fetch is done.

Returns:
address void*

Definition at line 182 of file SqlStatement.cxx.

References DmlStatement::getParamValuePtr().

00183 {
00184     //if (pData.getStmtType() != SelectStatement) return 0;
00185     DmlStatement *dmlStmt = (DmlStatement*) stmt;
00186     return( (void*) dmlStmt->getParamValuePtr( pos ) );
00187 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 228 of file SqlStatement.cxx.

References ErrBadCall, SelStatement::getProjFldInfo(), ParsedData::getStmtType(), OK, and SelectStatement.

00229 {
00230     DbRetVal rv = OK;
00231     if (pData.getStmtType() != SelectStatement) return ErrBadCall;
00232     SelStatement *selStmt = (SelStatement*) stmt; 
00233     rv = selStmt->getProjFldInfo(projpos, fInfo);
00234     return rv;
00235 }

Here is the call graph for this function:

char * SqlStatement::getTableName (  )  [virtual]

Retrieves the tablename of the prepared statement Used internally to get the tablename of the non select DML stmts.

Returns:
char* tablename

Reimplemented from AbsSqlStatement.

Definition at line 81 of file SqlStatement.cxx.

References ParsedData::getTableName().

00082 {
00083     return pData.getTableName();
00084 }

Here is the call graph for this function:

bool SqlStatement::isPrepared (  ) 

Returns whether the statement is prepared or not.

Returns:
bool true if it is prepared, false otherwise

Definition at line 92 of file SqlStatement.cxx.

Referenced by execute(), fetch(), fetchAndPrint(), and prepare().

00092 { return isPrepd; }

Here is the caller graph for this function:

bool SqlStatement::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 86 of file SqlStatement.cxx.

References ParsedData::getStmtType(), and SelectStatement.

00087 {
00088     if (pData.getStmtType() == SelectStatement) return true;
00089     return false;
00090 }

Here is the call graph for this function:

void * SqlStatement::next (  )  [virtual]

same as fetch, but does not populate bindFieldValues

Returns:
address void*

Implements AbsSqlStatement.

Definition at line 169 of file SqlStatement.cxx.

References ParsedData::getStmtType(), SelStatement::next(), and SelectStatement.

00170 {
00171     if (pData.getStmtType() != SelectStatement) return 0;
00172     SelStatement *selStmt = (SelStatement*) stmt; 
00173     return( (void*) selStmt->next() );
00174 }

Here is the call graph for this function:

int SqlStatement::noOfParamFields (  )  [virtual]

Retrieves the total number of parameters in the statement.

Returns:
int no of parameters

Implements AbsSqlStatement.

Definition at line 223 of file SqlStatement.cxx.

References Statement::noOfParamFields().

00224 {
00225     return stmt->noOfParamFields();
00226 }

Here is the call graph for this function:

int SqlStatement::noOfProjFields (  )  [virtual]

Retrieves the total number of projection fields in the statement.

Returns:
int no of projection fields

Implements AbsSqlStatement.

Definition at line 216 of file SqlStatement.cxx.

References ParsedData::getStmtType(), SelStatement::noOfProjFields(), and SelectStatement.

00217 {
00218     if (pData.getStmtType() != SelectStatement) return 0;
00219     SelStatement *selStmt = (SelStatement*) stmt; 
00220     return selStmt->noOfProjFields();
00221 }

Here is the call graph for this function:

DbRetVal SqlStatement::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 46 of file SqlStatement.cxx.

References ErrNotOpen, ErrSyntaxError, free(), SqlConnection::getConnObject(), Connection::getDatabaseManager(), StatementFactory::getStatement(), SqlConnection::isConnectionOpen(), isPrepared(), lexInput, OK, parsedData, printError, Statement::resolve(), Statement::setDbMgr(), yy_scan_string(), yyin, yyparse(), and yyrestart().

00047 {
00048     DbRetVal rv = OK;
00049     if (! sqlCon->isConnectionOpen()) {
00050         printError(ErrNotOpen, "Connection not open");
00051         return ErrNotOpen;
00052     }
00053     if(isPrepared()) free();
00054     lexInput = stmtstr;
00055     parsedData = &pData;
00056     yy_scan_string( stmtstr );
00057     int rc = yyparse();
00058     if (rc != 0) 
00059     {
00060         free();
00061         parsedData = NULL;
00062         yyrestart(yyin);
00063         return ErrSyntaxError;
00064     }
00065     stmt = StatementFactory::getStatement(parsedData);
00066     stmt->setDbMgr(sqlCon->getConnObject().getDatabaseManager());
00067     rv = stmt->resolve();
00068     if (rv != OK)
00069     {
00070         free();
00071         parsedData = NULL;
00072         yyrestart(yyin);
00073         return rv;
00074     }
00075     parsedData = NULL;
00076     yyrestart(yyin);
00077     isPrepd = true;
00078     return OK;
00079 }

Here is the call graph for this function:

void SqlStatement::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 277 of file SqlStatement.cxx.

References Statement::setByteIntParam().

00278 {
00279     stmt->setByteIntParam(paramPos, value);
00280 }

Here is the call graph for this function:

void SqlStatement::setConnection ( AbsSqlConnection con  )  [virtual]

sets connection handle to be used for subsequent operations

Parameters:
con SqlConnection*

Reimplemented from AbsSqlStatement.

Definition at line 35 of file SqlStatement.cxx.

References AbsSqlStatement::con, and conn.

00036 {
00037     sqlCon = (SqlConnection*)conn;
00038     con = conn;
00039 
00040 }

void SqlStatement::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 293 of file SqlStatement.cxx.

References Statement::setDateParam().

00294 {
00295     stmt->setDateParam(paramPos, value);
00296 }

Here is the call graph for this function:

void SqlStatement::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 285 of file SqlStatement.cxx.

References Statement::setDoubleParam().

00286 {
00287     stmt->setDoubleParam(paramPos, value);
00288 }

Here is the call graph for this function:

void SqlStatement::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 281 of file SqlStatement.cxx.

References Statement::setFloatParam().

00282 {
00283     stmt->setFloatParam(paramPos, value);
00284 }

Here is the call graph for this function:

void SqlStatement::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 265 of file SqlStatement.cxx.

References Statement::setIntParam().

00266 {
00267     stmt->setIntParam(paramPos, value);
00268 }

Here is the call graph for this function:

void SqlStatement::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 273 of file SqlStatement.cxx.

References Statement::setLongLongParam().

00274 {
00275     stmt->setLongLongParam(paramPos, value);
00276 }

Here is the call graph for this function:

void SqlStatement::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 269 of file SqlStatement.cxx.

References Statement::setLongParam().

00270 {
00271     stmt->setLongParam(paramPos, value);
00272 }

Here is the call graph for this function:

void SqlStatement::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 261 of file SqlStatement.cxx.

References Statement::setShortParam().

00262 {
00263     stmt->setShortParam(paramPos, value);
00264 }

Here is the call graph for this function:

void SqlStatement::setSqlConnection ( SqlConnection con  ) 

Definition at line 41 of file SqlStatement.cxx.

References conn.

00042 {
00043     sqlCon = conn;
00044 }

void SqlStatement::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 289 of file SqlStatement.cxx.

References Statement::setStringParam().

00290 {
00291     stmt->setStringParam(paramPos, value);
00292 }

Here is the call graph for this function:

void SqlStatement::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 297 of file SqlStatement.cxx.

References Statement::setTimeParam().

00298 {
00299     stmt->setTimeParam(paramPos, value);
00300 }

Here is the call graph for this function:

void SqlStatement::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 301 of file SqlStatement.cxx.

References Statement::setTimeStampParam().

00302 {
00303     stmt->setTimeStampParam(paramPos, value);
00304 }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class SqlFactory [friend]

Definition at line 238 of file SqlStatement.h.


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