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