00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <lDefs.h>
00017 #include <lTypes.h>
00018 #include <lTrace.h>
00019
00020
00021 #include <cOracleCursor.h>
00022
00023
00024 #include <cOracleConnection.h>
00025
00026 #define ORA_NOT_FOUND 4 //Not Found
00027 #define ORA_RESOURCE_BUSY -54 //Database Lock
00028
00029 OracleCursor::OracleCursor(
00030 class Connection *DbC
00031 ) : Cursor(DbC)
00032 {
00033 #ifdef C_ORACLECURSOR_TRACE
00034 logmsg("OracleCursor::OracleCursor() invoked");
00035 #endif
00036
00037 int i;
00038 char *addr;
00039
00040 addr = (char *)&_CDA;
00041 for (i = 0; i < sizeof(Cda_Def); i++)
00042 addr[i] = '\0';
00043
00044 #ifdef C_ORACLECURSOR_TRACE
00045 logmsg("OracleCursor::OracleCursor() finished");
00046 #endif
00047 };
00048
00049 OracleCursor::~OracleCursor()
00050 {
00051 #ifdef C_ORACLECURSOR_TRACE
00052 logmsg("OracleCursor::~OracleCursor() invoked");
00053 #endif
00054
00055 #ifdef C_ORACLECURSOR_TRACE
00056 logmsg("OracleCursor::~OracleCursor() finished");
00057 #endif
00058 };
00059
00060 bool OracleCursor::_Open()
00061 {
00062 int oci_ret;
00063
00064 #ifdef C_ORACLECURSOR_TRACE
00065 logmsg(TL_INFO_SQL,"OracleCursor::_Open() invoked");
00066 #endif
00067
00068 if (_DatabaseConnection == NULL)
00069 throw ObjLibException_ConnectionError();
00070 if (!Cursor::_Open())
00071 throw ObjLibException_ConnectionError();
00072 char *uid = NULL;
00073 StrCat(uid,3,
00074 _GetUserName(),
00075 "/",
00076 _GetPassword()
00077 );
00078 oci_ret = oopen(
00079 (Cda_Def *)&_CDA,
00080 (Lda_Def *)(&((OracleConnection *)_DatabaseConnection)->_LDA),
00081 (OraText *)0,
00082 (sword)-1,
00083 (sword)0,
00084 (OraText *)uid,
00085 (sword)-1
00086 );
00087 if (oci_ret) {
00088 #ifdef C_ORACLECURSOR_TRACE
00089 logmsg(TL_ERROR,"_Open(): oopen returns %d", oci_ret);
00090 #endif
00091 throw ObjLibException_ConnectionError();
00092 };
00093 StrFree(uid);
00094 return TRUE;
00095 };
00096
00097 bool OracleCursor::_Prepare(const char * const SqlCommand)
00098 {
00099 int oci_ret;
00100
00101 #ifdef C_ORACLECURSOR_TRACE
00102 logmsg(TL_INFO_SQL,"OracleCursor::_Prepare(\"%s\") invoked",SqlCommand);
00103 #endif
00104
00105 if (_DatabaseConnection == NULL)
00106 throw ObjLibException_ConnectionError();
00107 if (!_Opened)
00108 throw ObjLibException_ConnectionError();
00109 oci_ret = oparse(
00110 (Cda_Def *)&_CDA,
00111 (OraText *)SqlCommand,
00112 (sb4)-1,
00113 (sword)0,
00114 (ub4)SQL_EXECUTION_MODE
00115 );
00116 if (oci_ret) {
00117 #ifdef C_ORACLECURSOR_TRACE
00118 logmsg(TL_ERROR,"_Prepare(): oparse returns %d", oci_ret);
00119 #endif
00120 throw ObjLibException_SqlError();
00121 };
00122 return TRUE;
00123 };
00124
00125 bool OracleCursor::_PreExecBind(
00126 const char *const VarName,
00127 const void *VarAddr,
00128 const int VarLen,
00129 const char VarType,
00130 const short *VarInd
00131 )
00132 {
00133 int oci_ret;
00134 int CppVarType;
00135 #ifdef C_ORACLECURSOR_TRACE
00136 logmsg(TL_INFO_SQL,"OracleCursor::_PreExecBind(\"%s\") invoked",VarName);
00137 #endif
00138
00139 if (_DatabaseConnection == NULL)
00140 throw ObjLibException_ConnectionError();
00141 if (!_Opened)
00142 throw ObjLibException_ConnectionError();
00143 sword len = (sword)VarLen;
00144 if (len == 0)
00145 switch (VarType) {
00146 case 'p': len = sizeof(long); break;
00147 case 'i': len = sizeof(int); break;
00148 case 'u': len = sizeof(unsigned int); break;
00149 case 'l': len = sizeof(long); break;
00150 case 'f': len = sizeof(float); break;
00151 case 'd': len = sizeof(double); break;
00152 case 'c': len = sizeof(char); break;
00153 case 's': len = strlen((char *)VarAddr); break;
00154 };
00155 switch (VarType) {
00156 case 'p': CppVarType = 3; break;
00157 case 'i': CppVarType = 3; break;
00158 case 'u': CppVarType = 68; break;
00159 case 'l': CppVarType = 3; break;
00160 case 'f': CppVarType = 4; break;
00161 case 'd': CppVarType = 4; break;
00162 case 'c': CppVarType = 3; break;
00163 case 's': CppVarType = 5; len++; break;
00164 };
00165 oci_ret = obndrv(
00166 (Cda_Def *)&_CDA,
00167 (OraText *)VarName,
00168 (sword)-1,
00169 (ub1 *)VarAddr,
00170 (sword)len,
00171 (sword)CppVarType,
00172 (sword)-1,
00173 (sb2 *)VarInd,
00174 (OraText *)0,
00175 (sword)-1,
00176 (sword)-1
00177 );
00178 if (oci_ret) {
00179 #ifdef C_ORACLECURSOR_TRACE
00180 logmsg(TL_ERROR,"_PreExecBind(): obndrv returns %d", oci_ret);
00181 #endif
00182 throw ObjLibException_ConnectionError();
00183 };
00184 return TRUE;
00185 };
00186
00187 bool OracleCursor::_Execute()
00188 {
00189 int oci_ret;
00190
00191 #ifdef C_ORACLECURSOR_TRACE
00192 logmsg(TL_INFO_SQL,"OracleCursor::_Execute() invoked");
00193 #endif
00194
00195 if (_DatabaseConnection == NULL)
00196 throw ObjLibException_ConnectionError();
00197 if (!_Opened)
00198 throw ObjLibException_ConnectionError();
00199 oci_ret = oexec((Cda_Def *)&_CDA);
00200 if (oci_ret) {
00201 #ifdef C_ORACLECURSOR_TRACE
00202 logmsg(TL_ERROR,"_Execute(): oexec returns %d", oci_ret);
00203 #endif
00204 if (oci_ret == ORA_RESOURCE_BUSY)
00205 throw ObjLibException_DatabaseLock();
00206 throw ObjLibException_SqlError();
00207 };
00208 return TRUE;
00209 };
00210
00211 bool OracleCursor::_PreFetchBind(
00212 const int Position,
00213 const void *VarAddr,
00214 const int VarLen,
00215 const char VarType,
00216 const short *VarInd
00217 )
00218 {
00219 int oci_ret;
00220 int CppVarType;
00221
00222 #ifdef C_ORACLECURSOR_TRACE
00223 logmsg(TL_INFO_SQL,"OracleCursor::_PreFetchBind(%ld) invoked",Position);
00224 logmsg(TL_INFO_SQL,"len = %ld",VarLen);
00225 logmsg(TL_INFO_SQL,"type = \'%c\'",VarType);
00226 #endif
00227
00228 if (_DatabaseConnection == NULL)
00229 throw ObjLibException_ConnectionError();
00230 if (!_Opened)
00231 throw ObjLibException_ConnectionError();
00232 sword len = (sword)VarLen;
00233 if (len == 0)
00234 switch (VarType) {
00235 case 'p': len = sizeof(long); break;
00236 case 'i': len = sizeof(int); break;
00237 case 'u': len = sizeof(unsigned int); break;
00238 case 'l': len = sizeof(long); break;
00239 case 'f': len = sizeof(float); break;
00240 case 'd': len = sizeof(double); break;
00241 case 'c': len = sizeof(char); break;
00242 case 's': len = strlen((char *)VarAddr); break;
00243 };
00244 switch (VarType) {
00245 case 'p': CppVarType = 3; break;
00246 case 'i': CppVarType = 3; break;
00247 case 'u': CppVarType = 68; break;
00248 case 'l': CppVarType = 3; break;
00249 case 'f': CppVarType = 4; break;
00250 case 'd': CppVarType = 4; break;
00251 case 'c': CppVarType = 3; break;
00252 case 's': CppVarType = 5; len++; break;
00253 };
00254 oci_ret = odefin(
00255 (Cda_Def *)&_CDA,
00256 (sword)Position,
00257 (ub1 *)VarAddr,
00258 (sword)len,
00259 (sword)CppVarType,
00260 (sword)-1,
00261 (sb2 *)VarInd,
00262 (OraText *)0,
00263 (sword)-1,
00264 (sword)-1,
00265 (ub2 *)0,
00266 (ub2 *)0
00267 );
00268 if (oci_ret) {
00269 #ifdef C_ORACLECURSOR_TRACE
00270 logmsg(TL_ERROR,"_PreFetchBind(): odefin returns %d", oci_ret);
00271 #endif
00272 throw ObjLibException_ConnectionError();
00273 };
00274 return TRUE;
00275 };
00276
00277 bool OracleCursor::_FetchNext()
00278 {
00279 int oci_ret;
00280
00281 #ifdef C_ORACLECURSOR_TRACE
00282 logmsg(TL_INFO_SQL,"OracleCursor::_FetchNext() invoked");
00283 #endif
00284
00285 if (_DatabaseConnection == NULL)
00286 throw ObjLibException_ConnectionError();
00287 if (!_Opened)
00288 throw ObjLibException_ConnectionError();
00289 oci_ret = ofetch((Cda_Def *)&_CDA);
00290 if (oci_ret) {
00291 #ifdef C_ORACLECURSOR_TRACE
00292 logmsg(TL_ERROR,"_FetchNext(): ofetch returns %d", oci_ret);
00293 #endif
00294 if (oci_ret > 0)
00295 {
00296 if (oci_ret == ORA_NOT_FOUND)
00297 return FALSE;
00298 }
00299 else
00300 throw ObjLibException_ConnectionError();
00301 };
00302 return TRUE;
00303 };
00304
00305 bool OracleCursor::_FetchPrev()
00306 {
00307 #ifdef C_ORACLECURSOR_TRACE
00308 logmsg(TL_INFO_SQL,"OracleCursor::_FetchPrev() invoked");
00309 #endif
00310
00311 if (_DatabaseConnection == NULL)
00312 throw ObjLibException_ConnectionError();
00313 if (!_Opened)
00314 throw ObjLibException_ConnectionError();
00315 throw ObjLibException_NotSupported();
00316 };
00317
00318 long OracleCursor::_Position()
00319 {
00320 #ifdef C_ORACLECURSOR_TRACE
00321 logmsg(TL_INFO_SQL,"OracleCursor::_Position() invoked");
00322 #endif
00323
00324 if (_DatabaseConnection == NULL)
00325 throw ObjLibException_ConnectionError();
00326 return (long)_CDA.rpc;
00327 };
00328
00329 bool OracleCursor::_Close()
00330 {
00331 int oci_ret;
00332
00333 #ifdef C_ORACLECURSOR_TRACE
00334 logmsg(TL_INFO_SQL,"OracleCursor::_Close() invoked");
00335 #endif
00336
00337 if (!_Opened)
00338 return TRUE;
00339 if (_DatabaseConnection == NULL)
00340 throw ObjLibException_ConnectionError();
00341 oci_ret = oclose((Cda_Def *)&_CDA);
00342 if (oci_ret) {
00343 #ifdef C_ORACLECURSOR_TRACE
00344 logmsg(TL_ERROR,"_Close(): oclose returns %d", oci_ret);
00345 #endif
00346 throw ObjLibException_ConnectionError();
00347 };
00348 return Cursor::_Close();
00349 };
00350