#include <Statement.h>
Inheritance diagram for DelStatement:
Public Member Functions | |
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 | getParamFldInfo (int paramPos, FieldInfo *&info) |
DbRetVal | resolve () |
DelStatement () | |
~DelStatement () | |
DbRetVal | resolveForCondition () |
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 | getParamFldInfo (int paramPos, FieldInfo *&info) |
void * | getParamValuePtr (int) |
DbRetVal | resolve () |
DelStatement () | |
~DelStatement () | |
DbRetVal | resolveForCondition () |
Definition at line 191 of file Statement.h.
DelStatement::DelStatement | ( | ) |
Definition at line 18 of file DelStatement.cxx.
References Statement::dbMgr, DmlStatement::params, DmlStatement::paramValues, Statement::parsedData, DmlStatement::table, and DmlStatement::totalParams.
00019 { 00020 parsedData = NULL; 00021 dbMgr = NULL; 00022 table = NULL; 00023 params = NULL; 00024 paramValues = NULL; 00025 totalParams = 0; 00026 }
DelStatement::~DelStatement | ( | ) |
Definition at line 28 of file DelStatement.cxx.
References DatabaseManager::closeTable(), Statement::dbMgr, DmlStatement::params, DmlStatement::paramValues, Table::setCondition(), DmlStatement::table, and DmlStatement::totalParams.
00028 { 00029 if (table) { 00030 table->setCondition(NULL); 00031 if (dbMgr) dbMgr->closeTable(table); 00032 } 00033 if (totalParams) { 00034 free(params); 00035 params = NULL; 00036 free(paramValues); 00037 paramValues = NULL; 00038 } 00039 00040 }
Here is the call graph for this function:
DelStatement::DelStatement | ( | ) |
DelStatement::~DelStatement | ( | ) |
DbRetVal DelStatement::execute | ( | int & | rowsAffected | ) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::execute | ( | int & | rowsAffected | ) | [virtual] |
Implements DmlStatement.
Definition at line 52 of file DelStatement.cxx.
References Table::close(), AllDataType::copyVal(), Table::deleteTuple(), Table::execute(), Table::fetchNoBind(), ConditionValue::length, OK, DmlStatement::params, DmlStatement::paramValues, DmlStatement::table, DmlStatement::totalParams, ConditionValue::type, and ConditionValue::value.
00053 { 00054 DbRetVal rv = OK; 00055 //copy param values to binded buffer 00056 ConditionValue *value; 00057 for (int i = 0; i < totalParams; i ++) 00058 { 00059 value = (ConditionValue*) params[i]; 00060 if (paramValues[i] == NULL) 00061 { 00062 continue; 00063 //printError(ErrBadCall, "param values not set"); 00064 //return ErrBadCall; 00065 } 00066 AllDataType::copyVal(value->value, paramValues[i], value->type, value->length); 00067 } 00068 rv = table->execute(); 00069 if (rv != OK) return rv; 00070 rowsAffected = 0; 00071 void *tuple; 00072 while(true) 00073 { 00074 tuple = (char*)table->fetchNoBind(rv); 00075 if (rv != OK) break; 00076 if (tuple == NULL) {break;} 00077 rv = table->deleteTuple(); 00078 if (rv != OK) break; 00079 rowsAffected++; 00080 } 00081 table->close(); 00082 return rv; 00083 }
Here is the call graph for this function:
Implements DmlStatement.
Implements DmlStatement.
Definition at line 42 of file DelStatement.cxx.
References ErrBadArg, ConditionValue::length, FieldInfo::length, OK, DmlStatement::params, printError, DmlStatement::totalParams, ConditionValue::type, and FieldInfo::type.
00043 { 00044 if (paramPos <=0 || paramPos > totalParams) return ErrBadArg; 00045 ConditionValue *value = (ConditionValue*) params[paramPos-1]; 00046 if (value == NULL) { printError(ErrBadArg, "Should never happen\n"); 00047 return ErrBadArg; } 00048 info->type = value->type; 00049 info->length = value->length; 00050 return OK; 00051 }
void * DelStatement::getParamValuePtr | ( | int | ) | [virtual] |
Implements DmlStatement.
Definition at line 216 of file DelStatement.cxx.
References DmlStatement::params, and ConditionValue::value.
00217 { 00218 ConditionValue *cValue = (ConditionValue*) params [pos-1]; 00219 return ( (void*) cValue->value ); 00220 }
DbRetVal DelStatement::resolve | ( | ) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::resolve | ( | ) | [virtual] |
Implements DmlStatement.
Definition at line 235 of file DelStatement.cxx.
References DatabaseManager::closeTable(), Statement::dbMgr, ErrNoConnection, ErrNotExists, ParsedData::getCondition(), ParsedData::getTableName(), OK, DatabaseManager::openTable(), Statement::parsedData, printError, resolveForCondition(), Table::setCondition(), and DmlStatement::table.
00236 { 00237 if (dbMgr == NULL) return ErrNoConnection; 00238 //check whether the table exists 00239 table = dbMgr->openTable(parsedData->getTableName()); 00240 if (table == NULL) 00241 { 00242 printError(ErrNotExists, "Unable to open the table:Table not exists"); 00243 return ErrNotExists; 00244 } 00245 00246 table->setCondition(parsedData->getCondition()); 00247 00248 DbRetVal rv = resolveForCondition(); 00249 if (rv != OK) 00250 { 00251 //TODO::free memory allocated for params 00252 table->setCondition(NULL); 00253 dbMgr->closeTable(table); 00254 table = NULL; 00255 } 00256 return rv; 00257 }
Here is the call graph for this function:
DbRetVal DelStatement::resolveForCondition | ( | ) |
DbRetVal DelStatement::resolveForCondition | ( | ) |
Definition at line 260 of file DelStatement.cxx.
References AllDataType::alloc(), ErrNotFound, ErrSyntaxError, ErrSysFatal, ConditionValue::fName, ParsedData::getConditionValueList(), Table::getFieldInfo(), List::getIterator(), ListIterator::hasElement(), FieldInfo::length, ConditionValue::length, ListIterator::nextElement(), OK, ConditionValue::paramNo, DmlStatement::params, DmlStatement::paramValues, Statement::parsedData, ConditionValue::parsedString, printError, ListIterator::reset(), AllDataType::strToValue(), DmlStatement::table, DmlStatement::totalParams, FieldInfo::type, ConditionValue::type, and ConditionValue::value.
Referenced by resolve().
00261 { 00262 //get the fieldname list and validate field names 00263 ListIterator iter = parsedData->getConditionValueList().getIterator(); 00264 00265 ConditionValue *value; 00266 FieldInfo *fInfo = new FieldInfo(); 00267 int paramPos =1; 00268 DbRetVal rv = OK; 00269 while (iter.hasElement()) 00270 { 00271 value = (ConditionValue*) iter.nextElement(); 00272 if (NULL == value) 00273 { 00274 delete fInfo; 00275 printError(ErrSysFatal, "Should never happen."); 00276 return ErrSysFatal; 00277 } 00278 rv = table->getFieldInfo(value->fName, fInfo); 00279 if (ErrNotFound == rv) 00280 { 00281 delete fInfo; 00282 printError(ErrSyntaxError, "Field %s does not exist in table", 00283 value->fName); 00284 return ErrSyntaxError; 00285 } 00286 value->type = fInfo->type; 00287 value->length = fInfo->length; 00288 value->value = AllDataType::alloc(fInfo->type, fInfo->length); 00289 if (value->parsedString == NULL) 00290 { 00291 delete fInfo; 00292 printError(ErrSyntaxError, "Condition value should not be NULL"); 00293 return ErrSyntaxError; 00294 } 00295 00296 if (value->parsedString[0] == '?') 00297 { 00298 value->paramNo = paramPos++; 00299 } 00300 if (!value->paramNo) 00301 AllDataType::strToValue(value->value, value->parsedString, fInfo->type, fInfo->length); 00302 } 00303 delete fInfo; 00304 totalParams = paramPos -1; 00305 if (0 == totalParams) return OK; 00306 params = (void**) malloc ( totalParams * sizeof(FieldValue*)); 00307 paramValues = (char**) malloc( totalParams * sizeof(char*)); 00308 memset(params, 0, totalParams * sizeof(FieldValue*)); 00309 memset(paramValues, 0, totalParams * sizeof(char*)); 00310 iter.reset(); 00311 while(iter.hasElement()) 00312 { 00313 value = (ConditionValue*) iter.nextElement(); 00314 if (value == NULL) 00315 { 00316 free(params); params = NULL; 00317 free(paramValues); paramValues = NULL; 00318 printError(ErrSysFatal, "Should never happen. value NULL after iteration"); 00319 return ErrSysFatal; 00320 } 00321 params[value->paramNo -1 ] = value; 00322 } 00323 return OK; 00324 }
Here is the call graph for this function:
Here is the caller graph for this function:
Implements DmlStatement.
Implements DmlStatement.
Definition at line 144 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00145 { 00146 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00147 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00148 if (NULL == cValue) 00149 { 00150 printError(ErrSysFatal, "condition value is null. Should never happen"); 00151 return ErrSysFatal; 00152 } 00153 *(ByteInt*)cValue->value = value; 00154 return OK; 00155 }
Implements DmlStatement.
Implements DmlStatement.
Definition at line 192 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00193 { 00194 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00195 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00196 if (NULL == cValue) 00197 { 00198 printError(ErrSysFatal, "condition value is null. Should never happen"); 00199 return ErrSysFatal; 00200 } 00201 *(Date*)cValue->value = value; 00202 return OK; 00203 }
DbRetVal DelStatement::setDoubleParam | ( | int | paramNo, | |
double | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setDoubleParam | ( | int | paramNo, | |
double | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 168 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00169 { 00170 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00171 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00172 if (NULL == cValue) 00173 { 00174 printError(ErrSysFatal, "condition value is null. Should never happen"); 00175 return ErrSysFatal; 00176 } 00177 *(double*)cValue->value = value; 00178 return OK; 00179 }
DbRetVal DelStatement::setFloatParam | ( | int | paramNo, | |
float | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setFloatParam | ( | int | paramNo, | |
float | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 156 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00157 { 00158 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00159 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00160 if (NULL == cValue) 00161 { 00162 printError(ErrSysFatal, "condition value is null. Should never happen"); 00163 return ErrSysFatal; 00164 } 00165 *(float*)cValue->value = value; 00166 return OK; 00167 }
DbRetVal DelStatement::setIntParam | ( | int | paramNo, | |
int | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setIntParam | ( | int | paramNo, | |
int | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 107 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00108 { 00109 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00110 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00111 if (NULL == cValue) 00112 { 00113 printError(ErrSysFatal, "condition value is null. Should never happen"); 00114 return ErrSysFatal; 00115 } 00116 *(int*)cValue->value = value; 00117 return OK; 00118 }
DbRetVal DelStatement::setLongLongParam | ( | int | paramNo, | |
long long | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setLongLongParam | ( | int | paramNo, | |
long long | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 132 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00133 { 00134 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00135 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00136 if (NULL == cValue) 00137 { 00138 printError(ErrSysFatal, "condition value is null. Should never happen"); 00139 return ErrSysFatal; 00140 } 00141 *(long long*)cValue->value = value; 00142 return OK; 00143 }
DbRetVal DelStatement::setLongParam | ( | int | paramNo, | |
long | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setLongParam | ( | int | paramNo, | |
long | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 119 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00120 { 00121 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00122 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00123 if (NULL == cValue) 00124 { 00125 printError(ErrSysFatal, "condition value is null. Should never happen"); 00126 return ErrSysFatal; 00127 } 00128 *(long*)cValue->value = value; 00129 return OK; 00130 }
DbRetVal DelStatement::setParam | ( | int | paramNo, | |
void * | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setParam | ( | int | paramNo, | |
void * | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 86 of file DelStatement.cxx.
References ErrBadArg, OK, DmlStatement::paramValues, and DmlStatement::totalParams.
00087 { 00088 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00089 if (NULL == value) return ErrBadArg; 00090 paramValues[paramNo -1] = (char*) value; 00091 return OK; 00092 }
DbRetVal DelStatement::setShortParam | ( | int | paramNo, | |
short | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setShortParam | ( | int | paramNo, | |
short | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 94 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00095 { 00096 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00097 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00098 if (NULL == cValue) 00099 { 00100 printError(ErrSysFatal, "condition value is null. Should never happen"); 00101 return ErrSysFatal; 00102 } 00103 *(short*)cValue->value = value; 00104 return OK; 00105 }
DbRetVal DelStatement::setStringParam | ( | int | paramNo, | |
char * | value | |||
) | [virtual] |
Implements DmlStatement.
DbRetVal DelStatement::setStringParam | ( | int | paramNo, | |
char * | value | |||
) | [virtual] |
Implements DmlStatement.
Definition at line 180 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00181 { 00182 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00183 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00184 if (NULL == cValue) 00185 { 00186 printError(ErrSysFatal, "condition value is null. Should never happen"); 00187 return ErrSysFatal; 00188 } 00189 strcpy((char*)cValue->value, value); 00190 return OK; 00191 }
Implements DmlStatement.
Implements DmlStatement.
Definition at line 204 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00205 { 00206 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00207 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00208 if (NULL == cValue) 00209 { 00210 printError(ErrSysFatal, "condition value is null. Should never happen"); 00211 return ErrSysFatal; 00212 } 00213 *(Time*)cValue->value = value; 00214 return OK; 00215 }
Implements DmlStatement.
Implements DmlStatement.
Definition at line 222 of file DelStatement.cxx.
References ErrBadArg, ErrSysFatal, OK, DmlStatement::params, printError, DmlStatement::totalParams, and ConditionValue::value.
00223 { 00224 if (paramNo <=0 || paramNo > totalParams) return ErrBadArg; 00225 ConditionValue *cValue = (ConditionValue*) params [paramNo-1]; 00226 if (NULL == cValue) 00227 { 00228 printError(ErrSysFatal, "condition value is null. Should never happen"); 00229 return ErrSysFatal; 00230 } 00231 *(TimeStamp*)cValue->value = value; 00232 return OK; 00233 }