00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <SqlGwStatement.h>
00021 #include <SqlLogStatement.h>
00022
00023 DbRetVal SqlGwStatement::prepare(char *stmtstr)
00024 {
00025 DbRetVal rv = OK;
00026 SqlGwConnection *conn = (SqlGwConnection*) con;
00027
00028
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
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
00053
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 }
00065 bool SqlGwStatement::shouldAdapterHandle()
00066 {
00067 if (stmtHdlr == AdapterHandler ||
00068 stmtHdlr == CSqlAndAdapterHandler) return true;
00069 return false;
00070 }
00071 bool SqlGwStatement::shouldCSqlHandle()
00072 {
00073 SqlGwConnection *conn = (SqlGwConnection*) con;
00074 if (stmtHdlr == CSqlHandler ||
00075 stmtHdlr == CSqlAndAdapterHandler) return true;
00076 return false;
00077 }
00078 bool SqlGwStatement::isSelect()
00079 {
00080 bool retValue;
00081 if (adapter && shouldAdapterHandle()) retValue = adapter->isSelect();
00082 if (innerStmt && shouldCSqlHandle()) retValue = innerStmt->isSelect();
00083 return retValue;
00084 }
00085
00086 DbRetVal SqlGwStatement::execute(int &rowsAffected)
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 }
00094
00095 DbRetVal SqlGwStatement::bindParam(int pos, void* value)
00096 {
00097 DbRetVal rv = OK;
00098 printError(ErrWarning, "Deprecated and does not replicate or cache");
00099 return rv;
00100 }
00101
00102 DbRetVal SqlGwStatement::bindField(int pos, void* value)
00103 {
00104 DbRetVal rv = OK;
00105
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 }
00111 void* SqlGwStatement::fetch()
00112 {
00113
00114 if (adapter && shouldAdapterHandle()) return adapter->fetch();
00115 if (innerStmt && shouldCSqlHandle()) return innerStmt->fetch();
00116 return NULL;
00117 }
00118
00119 void* SqlGwStatement::fetchAndPrint(bool SQL)
00120 {
00121
00122 if (adapter && shouldAdapterHandle()) return adapter->fetchAndPrint(SQL);
00123 if (innerStmt && shouldCSqlHandle()) return innerStmt->fetchAndPrint(SQL);
00124 return NULL;
00125 }
00126
00127 void* SqlGwStatement::next()
00128 {
00129
00130 if (adapter && shouldAdapterHandle()) return adapter->next();
00131 if (innerStmt && shouldCSqlHandle()) return innerStmt->next();
00132 return NULL;
00133 }
00134
00135 DbRetVal SqlGwStatement::close()
00136 {
00137
00138 if (adapter && shouldAdapterHandle()) return adapter->close();
00139 if (innerStmt && shouldCSqlHandle()) return innerStmt->close();
00140 return OK;
00141 }
00142
00143 void* SqlGwStatement::getFieldValuePtr( int pos )
00144 {
00145
00146 if (adapter && shouldAdapterHandle()) return adapter->getFieldValuePtr(pos);
00147 if (innerStmt && shouldCSqlHandle()) return innerStmt->getFieldValuePtr(pos);
00148 return NULL;
00149 }
00150
00151 int SqlGwStatement::noOfProjFields()
00152 {
00153
00154 if (innerStmt && shouldCSqlHandle()) return innerStmt->noOfProjFields();
00155 if (adapter && shouldAdapterHandle()) return adapter->noOfProjFields();
00156 return 0;
00157 }
00158
00159 int SqlGwStatement::noOfParamFields()
00160 {
00161 if (innerStmt && shouldCSqlHandle()) return innerStmt->noOfParamFields();
00162 if (adapter && shouldAdapterHandle()) return adapter->noOfParamFields();
00163 return 0;
00164 }
00165
00166 DbRetVal SqlGwStatement::getProjFldInfo (int projpos, FieldInfo *&fInfo)
00167 {
00168 if (innerStmt && shouldCSqlHandle()) return innerStmt->getProjFldInfo(projpos, fInfo);
00169 if (adapter && shouldAdapterHandle()) return adapter->getProjFldInfo(projpos, fInfo);
00170 return OK;
00171 }
00172
00173 DbRetVal SqlGwStatement::getParamFldInfo (int parampos, FieldInfo *&fInfo)
00174 {
00175 if (innerStmt && shouldCSqlHandle()) return innerStmt->getParamFldInfo(parampos, fInfo);
00176 if (adapter && shouldAdapterHandle()) return adapter->getParamFldInfo(parampos, fInfo);
00177 return OK;
00178 }
00179
00180 DbRetVal SqlGwStatement::free()
00181 {
00182 DbRetVal rv = OK;
00183 if (adapter && shouldAdapterHandle()) rv = adapter->free();
00184 if (innerStmt && shouldCSqlHandle()) rv = innerStmt->free();
00185 return rv;
00186 }
00187 void SqlGwStatement::setShortParam(int paramPos, short value)
00188 {
00189 if (adapter && shouldAdapterHandle()) adapter->setShortParam(paramPos, value);
00190 if (innerStmt && shouldCSqlHandle()) innerStmt->setShortParam(paramPos,value);
00191 return;
00192 }
00193 void SqlGwStatement::setIntParam(int paramPos, int value)
00194 {
00195 if (adapter && shouldAdapterHandle()) adapter->setIntParam(paramPos, value);
00196 if (innerStmt && shouldCSqlHandle()) innerStmt->setIntParam(paramPos,value);
00197 return;
00198
00199 }
00200 void SqlGwStatement::setLongParam(int paramPos, long value)
00201 {
00202 if (adapter && shouldAdapterHandle()) adapter->setLongParam(paramPos, value);
00203 if (innerStmt && shouldCSqlHandle()) innerStmt->setLongParam(paramPos,value);
00204 return;
00205
00206 }
00207 void SqlGwStatement::setLongLongParam(int paramPos, long long value)
00208 {
00209 if (adapter && shouldAdapterHandle()) adapter->setLongLongParam(paramPos, value);
00210 if (innerStmt && shouldCSqlHandle()) innerStmt->setLongLongParam(paramPos,value);
00211 return;
00212 }
00213 void SqlGwStatement::setByteIntParam(int paramPos, ByteInt value)
00214 {
00215 if (adapter && shouldAdapterHandle()) adapter->setByteIntParam(paramPos, value);
00216 if (innerStmt && shouldCSqlHandle()) innerStmt->setByteIntParam(paramPos,value);
00217 return;
00218 }
00219 void SqlGwStatement::setFloatParam(int paramPos, float value)
00220 {
00221 if (adapter && shouldAdapterHandle()) adapter->setFloatParam(paramPos, value);
00222 if (innerStmt && shouldCSqlHandle()) innerStmt->setFloatParam(paramPos,value);
00223 return;
00224 }
00225 void SqlGwStatement::setDoubleParam(int paramPos, double value)
00226 {
00227 if (adapter && shouldAdapterHandle()) adapter->setDoubleParam(paramPos, value);
00228 if (innerStmt && shouldCSqlHandle()) innerStmt->setDoubleParam(paramPos,value);
00229 return;
00230
00231 }
00232 void SqlGwStatement::setStringParam(int paramPos, char *value)
00233 {
00234 if (adapter && shouldAdapterHandle()) adapter->setStringParam(paramPos, value);
00235 if (innerStmt && shouldCSqlHandle()) innerStmt->setStringParam(paramPos,value);
00236 return;
00237 }
00238 void SqlGwStatement::setDateParam(int paramPos, Date value)
00239 {
00240 if (adapter && shouldAdapterHandle()) adapter->setDateParam(paramPos, value);
00241 if (innerStmt && shouldCSqlHandle()) innerStmt->setDateParam(paramPos,value);
00242 return;
00243 }
00244 void SqlGwStatement::setTimeParam(int paramPos, Time value)
00245 {
00246 if (adapter && shouldAdapterHandle()) adapter->setTimeParam(paramPos, value);
00247 if (innerStmt && shouldCSqlHandle()) innerStmt->setTimeParam(paramPos,value);
00248 return;
00249 }
00250 void SqlGwStatement::setTimeStampParam(int paramPos, TimeStamp value)
00251 {
00252 if (adapter && shouldAdapterHandle()) adapter->setTimeStampParam(paramPos, value);
00253 if (innerStmt && shouldCSqlHandle()) innerStmt->setTimeStampParam(paramPos,value);
00254 return;
00255 }