00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <lOracle.h>
00017
00018
00019 #include <lDefs.h>
00020 #include <lTypes.h>
00021 #include <lTrace.h>
00022
00023
00024 #include <cOracleConnection.h>
00025
00026
00027 #include <cOracleCursor.h>
00028
00029 #ifdef NO_DATABASE_PRESENT
00030 long _OidGenerator = 0;
00031 long _VersionGenerator = 0;
00032
00033
00034 #endif
00035
00036 OracleConnection::OracleConnection(
00037 class Database *DB,
00038 const char *UserName,
00039 const char *Password,
00040 const int LocHandle,
00041 const int GlobHandle
00042 ): Connection(DB,UserName,Password,LocHandle,GlobHandle)
00043
00044 {
00045 #ifdef C_ORACLECONNECTION_TRACE
00046 logmsg("OracleConnection::OracleConnection() invoked");
00047 #endif
00048
00049 int i;
00050 char *addr;
00051
00052 addr = (char *)&_HDA;
00053 for (i = 0; i < HDA_SIZE; i++)
00054 addr[i] = '\0';
00055 addr = (char *)&_LDA;
00056 for (i = 0; i < sizeof(Lda_Def); i++)
00057 addr[i] = '\0';
00058 _DefaultCursor = new OracleCursor(this);
00059
00060 #ifdef C_ORACLECONNECTION_TRACE
00061 logmsg("OracleConnection::OracleConnection() finished");
00062 #endif
00063 };
00064
00065 OracleConnection::~OracleConnection()
00066
00067 {
00068 #ifdef C_ORACLECONNECTION_TRACE
00069 logmsg("OracleConnection::~OracleConnection() invoked and finished");
00070 #endif
00071 }
00072
00073 bool OracleConnection::_Sql(const char * const SqlCommand)
00074 {
00075 #ifdef C_ORACLECONNECTION_TRACE
00076 logmsg(TL_INFO_SQL,"O7DbC::_Sql(\"%s\") invoked",SqlCommand);
00077 #endif
00078
00079 if (_DefaultCursor == NULL)
00080 throw ObjLibException_ConnectionError();
00081 _Open();
00082 _Prepare(SqlCommand);
00083 _Execute();
00084 _Close();
00085 return true;
00086 };
00087
00088 bool OracleConnection::_Commit()
00089 {
00090 #ifdef C_ORACLECONNECTION_TRACE
00091 logmsg(TL_INFO_SQL,"O7DbC::_Commit() invoked");
00092 #endif
00093 if (ocom((Lda_Def *)&_LDA))
00094 throw ObjLibException_ConnectionError();
00095 return true;
00096 };
00097
00098 bool OracleConnection::_Rollback()
00099 {
00100 #ifdef C_ORACLECONNECTION_TRACE
00101 logmsg(TL_INFO_SQL,"O7DbC::_Rollback() invoked");
00102 #endif
00103 if (orol((Lda_Def *)&_LDA))
00104 throw ObjLibException_ConnectionError();
00105 return true;
00106 };
00107
00108 bool OracleConnection::_Savepoint(const char * const Name)
00109 {
00110 #ifdef C_ORACLECONNECTION_TRACE
00111 logmsg(TL_INFO_SQL,"O7DbC::_Savepoint(\"%s\") invoked",Name);
00112 #endif
00113 char *stmt = NULL;
00114 StrCat(stmt,2,"SAVEPOINT ",Name);
00115 _Sql(stmt);
00116 StrFree(stmt);
00117 return true;
00118 };
00119
00120 bool OracleConnection::_RollbackToSavepoint(const char * const Name)
00121 {
00122 #ifdef C_ORACLECONNECTION_TRACE
00123 logmsg(TL_INFO_SQL,"O7DbC::_RollbackToSavepoint(\"%s\") invoked",Name);
00124 #endif
00125 char *stmt = NULL;
00126 StrCat(stmt,2,"ROLLBACK TO SAVEPOINT ",Name);
00127 _Sql(stmt);
00128 StrFree(stmt);
00129 return true;
00130 };
00131
00132 bool OracleConnection::Sql(const char * const SqlCommand)
00133 {
00134 #ifdef C_ORACLECONNECTION_TRACE
00135 logmsg("OracleConnection::Sql(\"%s\") invoked", SqlCommand);
00136 #endif
00137 return Connection::Sql(SqlCommand);
00138 };
00139
00140 bool OracleConnection::Commit()
00141
00142 {
00143 #ifdef C_ORACLECONNECTION_TRACE
00144 logmsg("OracleConnection::Commit() invoked");
00145 #endif
00146 return(Connection::Commit());
00147 };
00148
00149 bool OracleConnection::Rollback()
00150
00151 {
00152 #ifdef C_ORACLECONNECTION_TRACE
00153 logmsg("OracleConnection::Rollback() invoked");
00154 #endif
00155 return(Connection::Rollback());
00156 };
00157
00158 bool OracleConnection::Savepoint(const char * const Name)
00159
00160 {
00161 #ifdef C_ORACLECONNECTION_TRACE
00162 logmsg("OracleConnection::Savepoint(\"%s\") invoked",Name);
00163 #endif
00164 return(Connection::Savepoint(Name));
00165 };
00166
00167 bool OracleConnection::RollbackToSavepoint(const char * const Name)
00168
00169 {
00170 #ifdef C_ORACLECONNECTION_TRACE
00171 logmsg("OracleConnection::RollbackToSavepoint(\"%s\") invoked",Name);
00172 #endif
00173 return(Connection::RollbackToSavepoint(Name));
00174 };
00175
00176 bool OracleConnection::Disconnect()
00177
00178 {
00179 int oci_ret;
00180
00181 #ifdef C_ORACLECONNECTION_TRACE
00182 logmsg("OracleConnection::Disconnect() invoked");
00183 #endif
00184 if (!Commit())
00185 return(false);
00186
00187 oci_ret = ologof((Lda_Def *)&_LDA);
00188 if (oci_ret) {
00189 #ifdef C_ORACLECONNECTION_TRACE
00190 logmsg(TL_ERROR,"Disconnect(): ologof returns %d", oci_ret);
00191 #endif
00192 throw ObjLibException_ConnectionError();
00193 };
00194 return(Connection::Disconnect());
00195 };
00196
00197 bool OracleConnection::Abort()
00198
00199 {
00200 int oci_ret;
00201
00202 #ifdef C_ORACLECONNECTION_TRACE
00203 logmsg("OracleConnection::Abort() invoked");
00204 #endif
00205 if (!Rollback())
00206 return(false);
00207
00208 oci_ret = ologof((Lda_Def *)&_LDA);
00209 if (oci_ret) {
00210 #ifdef C_ORACLECONNECTION_TRACE
00211 logmsg(TL_ERROR,"Abort(): ologof returns %d", oci_ret);
00212 #endif
00213 throw ObjLibException_ConnectionError();
00214 };
00215 return(Connection::Abort());
00216 };
00217
00218 bool OracleConnection::Autocommit(bool ac)
00219 {
00220 int oci_ret;
00221 #ifdef C_ORACLECONNECTION_TRACE
00222 logmsg("bool OracleConnection::Autocommit(bool) invoked");
00223 #endif
00224 if (ac)
00225 oci_ret = ocon((Lda_Def *)&_LDA);
00226 else
00227 oci_ret = ocof((Lda_Def *)&_LDA);
00228 if (oci_ret)
00229 {
00230 #ifdef C_ORACLECONNECTION_TRACE
00231 logmsg(TL_ERROR,"Autocommit(): ocon/ocof returns %d", oci_ret);
00232 #endif
00233 throw ObjLibException_ConnectionError();
00234 };
00235 return true;
00236 };
00237
00238
00239 Cursor *OracleConnection::_GetNewCursor()
00240 {
00241 Cursor *_retval = new OracleCursor(this);
00242 if (_retval == NULL)
00243 throw ObjLibException_NoMemory();
00244 return _retval;
00245 };
00246
00247
00248 bool OracleConnection::_NextOID(long int &nxtoid, long int &nxtsn)
00249
00250 {
00251 bool retval;
00252
00253 retval = _Open();
00254 retval = retval && _Prepare(
00255 "SELECT OID_GENERATOR.NEXTVAL, VERSION_GENERATOR.NEXTVAL FROM DUAL"
00256
00257 );
00258 retval = retval && _Execute();
00259 retval = retval && _PreFetchBind(1,&nxtoid,sizeof(long int),'l');
00260 retval = retval && _PreFetchBind(2,&nxtsn,sizeof(long int),'l');
00261 retval = retval && _FetchNext();
00262 retval = retval && _Close();
00263 #ifdef NO_DATABASE_PRESENT
00264 nxtsn = ++_VersionGenerator;
00265 #endif // NO_DATABASE_PRESENT
00266 return retval;
00267 };
00268
00269 bool OracleConnection::_NextSN(long int curoid, long int &nxtsn)
00270
00271 {
00272 bool retval;
00273
00274 retval = _Open();
00275 retval = retval && _Prepare(
00276 "SELECT VERSION_GENERATOR.NEXTVAL FROM DUAL"
00277
00278 );
00279 retval = retval && _Execute();
00280 retval = retval && _PreFetchBind(1,&nxtsn,sizeof(long int),'l');
00281 retval = retval && _FetchNext();
00282 retval = retval && _Close();
00283 #ifdef NO_DATABASE_PRESENT
00284 nxtsn = ++_VersionGenerator;
00285 #endif // NO_DATABASE_PRESENT
00286 return retval;
00287 };