00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ocilib_internal.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 OCI_Transaction * OCI_API OCI_TransactionCreate
00046 (
00047 OCI_Connection *con,
00048 unsigned int timeout,
00049 unsigned int mode,
00050 OCI_XID *pxid
00051 )
00052 {
00053 OCI_Item *item = NULL;
00054 OCI_Transaction *trans = NULL;
00055 boolean res = TRUE;
00056
00057 OCI_CHECK_INITIALIZED(NULL);
00058
00059 OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, NULL);
00060
00061
00062
00063 item = OCI_ListAppend(con->trsns, sizeof(*trans));
00064
00065 if (item != NULL)
00066 {
00067 trans = (OCI_Transaction *) item->data;
00068
00069 trans->con = con;
00070 trans->mode = mode;
00071 trans->timeout = timeout;
00072 trans->local = (pxid == NULL);
00073
00074
00075
00076 if (res == TRUE)
00077 res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) OCILib.env,
00078 (dvoid **) (void *) &trans->htr,
00079 (ub4) OCI_HTYPE_TRANS,
00080 (size_t) 0, (dvoid **) NULL));
00081
00082
00083
00084 OCI_CALL2
00085 (
00086 res, con,
00087
00088 OCIAttrSet((dvoid *) trans->con->cxt, (ub4) OCI_HTYPE_SVCCTX,
00089 (dvoid *) trans->htr, (ub4) sizeof(trans->htr),
00090 (ub4) OCI_ATTR_TRANS, trans->con->err)
00091 )
00092
00093
00094
00095 if (pxid != NULL)
00096 {
00097 memcpy(&trans->xid, pxid, sizeof(trans->xid));
00098
00099 OCI_CALL2
00100 (
00101 res, con,
00102
00103 OCIAttrSet((dvoid *) trans->htr, (ub4) OCI_HTYPE_TRANS,
00104 (dvoid *) &trans->xid, (ub4) sizeof(trans->xid),
00105 (ub4) OCI_ATTR_XID, trans->con->err)
00106 )
00107 }
00108 }
00109 else
00110 res = FALSE;
00111
00112
00113
00114 if (res == FALSE)
00115 {
00116 OCI_TransactionFree(trans);
00117 trans = NULL;
00118 }
00119
00120 OCI_RESULT(res);
00121
00122 return trans;
00123 }
00124
00125
00126
00127
00128
00129 boolean OCI_TransactionClose
00130 (
00131 OCI_Transaction * trans
00132 )
00133 {
00134 boolean res = TRUE;
00135
00136 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00137
00138 res = OCI_TransactionStop(trans);
00139
00140
00141
00142 if (trans->htr != NULL)
00143 {
00144 OCI_HandleFree((dvoid *) trans->htr, (ub4) OCI_HTYPE_TRANS);
00145 }
00146
00147 return res;
00148 }
00149
00150
00151
00152
00153
00154 boolean OCI_API OCI_TransactionFree
00155 (
00156 OCI_Transaction * trans
00157 )
00158 {
00159 boolean res = TRUE;
00160
00161 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00162
00163 res = OCI_TransactionClose(trans);
00164
00165
00166
00167 OCI_ListRemove(trans->con->trsns, trans);
00168
00169 OCI_FREE(trans);
00170
00171 OCI_RESULT(res);
00172
00173 return res;
00174 }
00175
00176
00177
00178
00179
00180 boolean OCI_API OCI_TransactionStart
00181 (
00182 OCI_Transaction * trans
00183 )
00184 {
00185 boolean res = TRUE;
00186
00187 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00188
00189 OCI_CALL2
00190 (
00191 res, trans->con,
00192
00193 OCITransStart(trans->con->cxt, trans->con->err, (uword) trans->timeout,
00194 (ub4) trans->mode)
00195 )
00196
00197 OCI_RESULT(res);
00198
00199 return res;
00200 }
00201
00202
00203
00204
00205
00206 boolean OCI_API OCI_TransactionStop
00207 (
00208 OCI_Transaction * trans
00209 )
00210 {
00211 boolean res = TRUE;
00212
00213 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00214
00215
00216
00217 if (trans->con->autocom == TRUE)
00218 res = OCI_Commit(trans->con);
00219 else
00220 res = OCI_Rollback(trans->con);
00221
00222
00223
00224 if (trans->local == FALSE)
00225 {
00226 OCI_CALL2
00227 (
00228 res, trans->con,
00229
00230 OCITransDetach(trans->con->cxt, trans->con->err, (ub4) OCI_DEFAULT)
00231 )
00232 }
00233
00234 OCI_RESULT(res);
00235
00236 return res;
00237 }
00238
00239
00240
00241
00242
00243 boolean OCI_API OCI_TransactionResume
00244 (
00245 OCI_Transaction * trans
00246 )
00247 {
00248 boolean res = TRUE;
00249
00250 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00251
00252 OCI_CALL2
00253 (
00254 res, trans->con,
00255
00256 OCITransStart(trans->con->cxt, trans->con->err,
00257 (uword) trans->timeout, (ub4) OCI_TRANS_RESUME)
00258 )
00259
00260 OCI_RESULT(res);
00261
00262 return res;
00263 }
00264
00265
00266
00267
00268
00269 boolean OCI_API OCI_TransactionPrepare
00270 (
00271 OCI_Transaction * trans
00272 )
00273 {
00274 boolean res = TRUE;
00275
00276 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00277
00278 OCI_CALL2
00279 (
00280 res, trans->con,
00281
00282 OCITransPrepare(trans->con->cxt, trans->con->err, (ub4) OCI_DEFAULT)
00283 )
00284
00285 OCI_RESULT(res);
00286
00287 return res;
00288 }
00289
00290
00291
00292
00293
00294 boolean OCI_API OCI_TransactionForget
00295 (
00296 OCI_Transaction * trans
00297 )
00298 {
00299 boolean res = TRUE;
00300
00301 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, FALSE);
00302
00303 OCI_CALL2
00304 (
00305 res, trans->con,
00306
00307 OCITransForget(trans->con->cxt, trans->con->err, (ub4) OCI_DEFAULT)
00308 )
00309
00310 OCI_RESULT(res);
00311
00312 return res;
00313 }
00314
00315
00316
00317
00318
00319 unsigned int OCI_API OCI_TransactionGetMode
00320 (
00321 OCI_Transaction * trans
00322 )
00323 {
00324 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, OCI_UNKNOWN);
00325
00326 OCI_RESULT(TRUE);
00327
00328 return trans->mode;
00329 }
00330
00331
00332
00333
00334
00335 unsigned int OCI_API OCI_TransactionGetTimeout
00336 (
00337 OCI_Transaction * trans
00338 )
00339 {
00340 OCI_CHECK_PTR(OCI_IPC_TRANSACTION, trans, 0);
00341
00342 OCI_RESULT(TRUE);
00343
00344 return trans->timeout;
00345 }