InsStatement Class Reference

#include <Statement.h>

Inheritance diagram for InsStatement:

Inheritance graph
[legend]
Collaboration diagram for InsStatement:

Collaboration graph
[legend]

Public Member Functions

DbRetVal getParamFldInfo (int paramPos, FieldInfo *&info)
DbRetVal execute (int &rowsAffected)
DbRetVal setParam (int paramNo, void *value)
DbRetVal setShortParam (int paramNo, short value)
DbRetVal setIntParam (int paramNo, int value)
DbRetVal setLongParam (int paramNo, long value)
DbRetVal setLongLongParam (int paramNo, long long value)
DbRetVal setByteIntParam (int paramNo, ByteInt value)
DbRetVal setFloatParam (int paramNo, float value)
DbRetVal setDoubleParam (int paramNo, double value)
DbRetVal setStringParam (int paramNo, char *value)
DbRetVal setDateParam (int paramNo, Date value)
DbRetVal setTimeParam (int paramNo, Time value)
DbRetVal setTimeStampParam (int paramNo, TimeStamp value)
DbRetVal resolve ()
 InsStatement ()
 ~InsStatement ()
DbRetVal getParamFldInfo (int paramPos, FieldInfo *&info)
DbRetVal execute (int &rowsAffected)
DbRetVal setParam (int paramNo, void *value)
DbRetVal setShortParam (int paramNo, short value)
DbRetVal setIntParam (int paramNo, int value)
DbRetVal setLongParam (int paramNo, long value)
DbRetVal setLongLongParam (int paramNo, long long value)
DbRetVal setByteIntParam (int paramNo, ByteInt value)
DbRetVal setFloatParam (int paramNo, float value)
DbRetVal setDoubleParam (int paramNo, double value)
DbRetVal setStringParam (int paramNo, char *value)
DbRetVal setDateParam (int paramNo, Date value)
DbRetVal setTimeParam (int paramNo, Time value)
DbRetVal setTimeStampParam (int paramNo, TimeStamp value)
void * getParamValuePtr (int)
DbRetVal resolve ()
 InsStatement ()
 ~InsStatement ()

Detailed Description

Definition at line 90 of file Statement.h.


Constructor & Destructor Documentation

InsStatement::InsStatement (  ) 

Definition at line 19 of file InsStatement.cxx.

References Statement::dbMgr, DmlStatement::params, DmlStatement::paramValues, Statement::parsedData, DmlStatement::table, and DmlStatement::totalParams.

00020 {
00021     parsedData = NULL; 
00022     dbMgr = NULL; 
00023     table = NULL;
00024     params = NULL;
00025     paramValues = NULL;
00026     totalParams = 0;
00027 }

InsStatement::~InsStatement (  ) 

Definition at line 29 of file InsStatement.cxx.

References DatabaseManager::closeTable(), Statement::dbMgr, DmlStatement::params, DmlStatement::paramValues, Table::setCondition(), DmlStatement::table, and DmlStatement::totalParams.

00030 {
00031     if (table) {
00032         table->setCondition(NULL);
00033         if (dbMgr) dbMgr->closeTable(table);
00034     }
00035     if (totalParams) {
00036         free(params);
00037         params =  NULL;
00038         free(paramValues);
00039         paramValues = NULL;
00040     }
00041 }

Here is the call graph for this function:

InsStatement::InsStatement (  ) 

InsStatement::~InsStatement (  ) 


Member Function Documentation

DbRetVal InsStatement::execute ( int &  rowsAffected  )  [virtual]

Implements DmlStatement.

DbRetVal InsStatement::execute ( int &  rowsAffected  )  [virtual]

Implements DmlStatement.

Definition at line 57 of file InsStatement.cxx.

References AllDataType::copyVal(), Table::insertTuple(), FieldValue::length, OK, DmlStatement::params, DmlStatement::paramValues, DmlStatement::table, DmlStatement::totalParams, FieldValue::type, and FieldValue::value.

00058 {
00059     DbRetVal rv = OK;
00060     //copy param values to binded buffer
00061     FieldValue *value;
00062     for (int i = 0; i < totalParams; i ++)
00063     {
00064         value = (FieldValue*) params[i];
00065         if (paramValues[i] == NULL) 
00066         {
00067             //printError(ErrBadCall, "param values not set");
00068             continue;
00069             //return ErrBadCall;
00070         }
00071         AllDataType::copyVal(value->value, paramValues[i], value->type, value->length);
00072     }
00073     rv = table->insertTuple();
00074     if (rv ==OK) rowsAffected = 1;
00075     return rv;
00076 }

Here is the call graph for this function:

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

Implements DmlStatement.

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

Implements DmlStatement.

Definition at line 43 of file InsStatement.cxx.

References ErrBadArg, ErrBadCall, ErrSysFatal, FieldValue::length, FieldInfo::length, OK, DmlStatement::params, printError, DmlStatement::totalParams, FieldValue::type, and FieldInfo::type.

00044 {
00045     if (paramPos >totalParams ) return ErrBadCall;
00046     FieldValue *value = (FieldValue*)params[paramPos-1];
00047     if (value == NULL)
00048     {
00049         printError(ErrSysFatal, "param ptr is null: should never happen\n");
00050         return ErrBadArg;
00051     }
00052     info->type = value->type;
00053     info->length = value->length;
00054     return OK;
00055 }

void * InsStatement::getParamValuePtr ( int   )  [virtual]

Implements DmlStatement.

Definition at line 211 of file InsStatement.cxx.

References DmlStatement::params, and FieldValue::value.

00212  {
00213      FieldValue *p = (FieldValue*) params [pos-1];
00214      return ( (void*) p->value );
00215  }

DbRetVal InsStatement::resolve (  )  [virtual]

Implements DmlStatement.

DbRetVal InsStatement::resolve (  )  [virtual]

Implements DmlStatement.

Definition at line 230 of file InsStatement.cxx.

References AllDataType::alloc(), Table::bindFld(), DatabaseManager::closeTable(), Statement::dbMgr, ErrNoConnection, ErrNotExists, ErrNotFound, ErrSyntaxError, ErrSysFatal, FieldName::fldName, Table::getFieldInfo(), Table::getFieldNameList(), ParsedData::getFieldNameList(), ParsedData::getFieldValueList(), List::getIterator(), ParsedData::getTableName(), ListIterator::hasElement(), FieldInfo::length, FieldValue::length, ListIterator::nextElement(), OK, DatabaseManager::openTable(), FieldValue::paramNo, DmlStatement::params, DmlStatement::paramValues, Statement::parsedData, FieldValue::parsedString, printError, List::reset(), ListIterator::reset(), List::size(), AllDataType::strToValue(), DmlStatement::table, DmlStatement::totalParams, FieldInfo::type, FieldValue::type, and FieldValue::value.

00231 {
00232     if (dbMgr == NULL) return ErrNoConnection;
00233     //check whether the table exists
00234     table = dbMgr->openTable(parsedData->getTableName());
00235     if (table == NULL) 
00236     {
00237         printError(ErrNotExists, "Unable to open the table:Table not exists");
00238         return ErrNotExists;
00239     }
00240 
00241     List fieldNameList;
00242     //check whether filed list is specified
00243     if( 0 == parsedData->getFieldNameList().size() )
00244         fieldNameList = table->getFieldNameList();
00245     else
00246         fieldNameList = parsedData->getFieldNameList();
00247 
00248     //check whether the total number of field name in the list is same as the total 
00249     //number of values provided in the values list.
00250     if ( fieldNameList.size() != 
00251                                parsedData->getFieldValueList().size())
00252     {
00253         dbMgr->closeTable(table);
00254         table = NULL;
00255         printError(ErrSyntaxError, "Field Name list and field values do not match");
00256         return ErrSyntaxError;
00257     }
00258 
00259     //get the fieldname list and validate field names
00260     ListIterator iter = fieldNameList.getIterator();
00261     ListIterator valIter = parsedData->getFieldValueList().getIterator();
00262     FieldName *name; FieldValue *value;
00263     FieldInfo *fInfo = new FieldInfo();
00264     int paramPos =1;
00265     DbRetVal rv = OK;
00266     while (iter.hasElement())
00267     {
00268         name = (FieldName*)iter.nextElement();
00269         value = (FieldValue*) valIter.nextElement();
00270         if (NULL == name || NULL == value) 
00271         {
00272             dbMgr->closeTable(table);
00273             table = NULL;
00274             delete fInfo;
00275             printError(ErrSyntaxError, "Field Name list and field values do not match");
00276             return ErrSyntaxError;
00277         }
00278         rv = table->getFieldInfo(name->fldName, fInfo);
00279         if (ErrNotFound == rv)
00280         {
00281             dbMgr->closeTable(table);
00282             table = NULL;
00283             delete fInfo;
00284             printError(ErrSyntaxError, "Field %s does not exist in table", 
00285                                         name->fldName);
00286             return ErrSyntaxError;
00287         }
00288         value->type = fInfo->type;
00289         value->length = fInfo->length;
00290         value->value = AllDataType::alloc(fInfo->type, fInfo->length);
00291         if (value->parsedString == NULL) continue;
00292         table->bindFld(name->fldName, value->value);
00293         if (value->parsedString[0] == '?')
00294         {
00295             value->paramNo = paramPos++;
00296         }
00297         if (!value->paramNo) 
00298             AllDataType::strToValue(value->value, value->parsedString, fInfo->type, fInfo->length);
00299     }
00300     delete fInfo;
00301     totalParams = paramPos -1;
00302     if (0 == totalParams) {
00303         if( 0 == parsedData->getFieldNameList().size() ) {
00304             iter.reset();
00305             while(iter.hasElement())
00306                 delete (Identifier *) iter.nextElement();
00307             fieldNameList.reset();
00308         }
00309                 return OK;
00310         }       
00311     params = (void**) malloc ( totalParams * sizeof(FieldValue*));
00312     paramValues = (char**) malloc( totalParams * sizeof(char*));
00313     memset(params, 0, totalParams * sizeof(FieldValue*));
00314     memset(paramValues, 0, totalParams * sizeof(char*));
00315     valIter.reset();
00316     while(valIter.hasElement())
00317     {
00318         value = (FieldValue*) valIter.nextElement();
00319         if (value == NULL) 
00320         {
00321             dbMgr->closeTable(table);
00322             table = NULL;
00323             free(params); params = NULL;
00324             free(paramValues); paramValues = NULL;
00325             printError(ErrSysFatal, "Should never happen. value NULL after iteration");
00326             return ErrSysFatal;
00327         }
00328         if (value->paramNo == 0) continue;
00329         params[value->paramNo -1 ] = value;
00330     }
00331    // memory to be deallocated created by table->getFieldNameList
00332     if( 0 == parsedData->getFieldNameList().size() ) {
00333         iter.reset();
00334         while(iter.hasElement())
00335             delete (Identifier *) iter.nextElement();
00336         fieldNameList.reset();
00337     }
00338     return OK;
00339 }

Here is the call graph for this function:

DbRetVal InsStatement::setByteIntParam ( int  paramNo,
ByteInt  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setByteIntParam ( int  paramNo,
ByteInt  value 
) [virtual]

Implements DmlStatement.

Definition at line 137 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00138 {
00139     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00140     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00141     if (NULL == cValue)
00142     {
00143         printError(ErrSysFatal, "condition value is null. Should never happen");
00144         return ErrSysFatal;
00145     }
00146     *(ByteInt*)cValue->value = value; 
00147     return OK;
00148 }

DbRetVal InsStatement::setDateParam ( int  paramNo,
Date  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setDateParam ( int  paramNo,
Date  value 
) [virtual]

Implements DmlStatement.

Definition at line 187 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00188 {
00189     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00190     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00191     if (NULL == cValue)
00192     {
00193         printError(ErrSysFatal, "condition value is null. Should never happen");
00194         return ErrSysFatal;
00195     }
00196     *(Date*)cValue->value = value; 
00197     return OK;
00198 }

DbRetVal InsStatement::setDoubleParam ( int  paramNo,
double  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setDoubleParam ( int  paramNo,
double  value 
) [virtual]

Implements DmlStatement.

Definition at line 161 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00162 {
00163     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00164     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00165     if (NULL == cValue)
00166     {
00167         printError(ErrSysFatal, "condition value is null. Should never happen");
00168         return ErrSysFatal;
00169     }
00170     *(double*)cValue->value = value; 
00171     return OK;
00172 }

DbRetVal InsStatement::setFloatParam ( int  paramNo,
float  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setFloatParam ( int  paramNo,
float  value 
) [virtual]

Implements DmlStatement.

Definition at line 149 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00150 {
00151     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00152     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00153     if (NULL == cValue)
00154     {
00155         printError(ErrSysFatal, "condition value is null. Should never happen");
00156         return ErrSysFatal;
00157     }
00158     *(float*)cValue->value = value; 
00159     return OK;
00160 }

DbRetVal InsStatement::setIntParam ( int  paramNo,
int  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setIntParam ( int  paramNo,
int  value 
) [virtual]

Implements DmlStatement.

Definition at line 99 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00100 {
00101     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00102     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00103     if (NULL == cValue)
00104     {
00105         printError(ErrSysFatal, "condition value is null. Should never happen");
00106         return ErrSysFatal;
00107     }
00108 
00109     *(int*)cValue->value = value; 
00110     return OK;
00111 }

DbRetVal InsStatement::setLongLongParam ( int  paramNo,
long long  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setLongLongParam ( int  paramNo,
long long  value 
) [virtual]

Implements DmlStatement.

Definition at line 125 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00126 {
00127     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00128     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00129     if (NULL == cValue)
00130     {
00131         printError(ErrSysFatal, "condition value is null. Should never happen");
00132         return ErrSysFatal;
00133     }
00134     *(long long*)cValue->value = value; 
00135     return OK;
00136 }

DbRetVal InsStatement::setLongParam ( int  paramNo,
long  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setLongParam ( int  paramNo,
long  value 
) [virtual]

Implements DmlStatement.

Definition at line 112 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00113 {
00114     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00115     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00116     if (NULL == cValue)
00117     {
00118         printError(ErrSysFatal, "condition value is null. Should never happen");
00119         return ErrSysFatal;
00120     }
00121     *(long*)cValue->value = value; 
00122     return OK;
00123 }

DbRetVal InsStatement::setParam ( int  paramNo,
void *  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setParam ( int  paramNo,
void *  value 
) [virtual]

Implements DmlStatement.

Definition at line 78 of file InsStatement.cxx.

References ErrBadArg, OK, DmlStatement::paramValues, and DmlStatement::totalParams.

00079 {
00080     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00081     if (NULL == value) return ErrBadArg;
00082     paramValues[paramNo -1] = (char*) value; 
00083     return OK;
00084 }

DbRetVal InsStatement::setShortParam ( int  paramNo,
short  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setShortParam ( int  paramNo,
short  value 
) [virtual]

Implements DmlStatement.

Definition at line 86 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00087 {
00088     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00089     FieldValue *fValue = (FieldValue*) params [paramNo-1];
00090     if (NULL == fValue)
00091     {
00092         printError(ErrSysFatal, "field value is null. Should never happen");
00093         return ErrSysFatal;
00094     }
00095     *(short*)fValue->value = value; 
00096     return OK;
00097 }

DbRetVal InsStatement::setStringParam ( int  paramNo,
char *  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setStringParam ( int  paramNo,
char *  value 
) [virtual]

Implements DmlStatement.

Definition at line 173 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00174 {
00175     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00176     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00177     if (NULL == cValue)
00178     {
00179         printError(ErrSysFatal, "condition value is null. Should never happen");
00180         return ErrSysFatal;
00181     }
00182     //TODO::check if the strlen(value) is greater than field length
00183     //do in all stmts
00184     strcpy((char*)cValue->value, value);
00185     return OK;
00186 }

DbRetVal InsStatement::setTimeParam ( int  paramNo,
Time  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setTimeParam ( int  paramNo,
Time  value 
) [virtual]

Implements DmlStatement.

Definition at line 199 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00200 {
00201     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00202     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00203     if (NULL == cValue)
00204     {
00205         printError(ErrSysFatal, "condition value is null. Should never happen");
00206         return ErrSysFatal;
00207     }
00208     *(Time*)cValue->value = value; 
00209     return OK;
00210 }

DbRetVal InsStatement::setTimeStampParam ( int  paramNo,
TimeStamp  value 
) [virtual]

Implements DmlStatement.

DbRetVal InsStatement::setTimeStampParam ( int  paramNo,
TimeStamp  value 
) [virtual]

Implements DmlStatement.

Definition at line 217 of file InsStatement.cxx.

References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and FieldValue::value.

00218 {
00219     if (paramNo <=0 || paramNo > totalParams) return ErrBadArg;
00220     FieldValue *cValue = (FieldValue*) params [paramNo-1];
00221     if (NULL == cValue)
00222     {
00223         printError(ErrSysFatal, "condition value is null. Should never happen");
00224         return ErrSysFatal;
00225     }
00226     *(TimeStamp*)cValue->value = value;
00227     return OK;
00228 }


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