]> granicus.if.org Git - php/commitdiff
only rollback at script end if there is something to rollback.
authorThies C. Arntzen <thies@php.net>
Sun, 10 Feb 2002 12:41:52 +0000 (12:41 +0000)
committerThies C. Arntzen <thies@php.net>
Sun, 10 Feb 2002 12:41:52 +0000 (12:41 +0000)
ext/oci8/oci8.c
ext/oci8/php_oci8.h

index 0e258b90d39c9827aade781117c4cdbc55a07379..f46bfa4512a11062e4ddb4ed46f48a84786476e4 100644 (file)
@@ -39,7 +39,6 @@
  * - have one ocifree() call.
  * - make it possible to have persistent statements?
  * - implement connection pooling in ZTS mode.
- * - implement automatic commit *OR* rollback on script end
  * - failover
  * - change all the lob stuff to work without classes (optional)! 
  * - make sure that the callbacks terminate the strings with \0
@@ -51,7 +50,6 @@
  * - add Collection iterator object for INDEX BY tables
  * - make auto-rollabck only happen if we have an outstanding transaction
  * - implement ocidisconnect
- * - add bind patch
  */
 
 /* {{{ includes & stuff */
@@ -804,13 +802,20 @@ _oci_conn_list_dtor(oci_connection *connection TSRMLS_DC)
        oci_debug("START _oci_conn_list_dtor: id=%d",connection->id);
 
        if (connection->pServiceContext) {
-               CALL_OCI_RETURN(connection->error,OCITransRollback(
-                                       connection->pServiceContext,
-                                       connection->pError,
-                                       (ub4)0));
-               if (connection->error) {
-                       oci_error(connection->pError, "failed to rollback outstanding transactions!", connection->error);
+
+               if (connection->needs_commit) {
+                       oci_debug("OCITransRollback");
+                       CALL_OCI_RETURN(connection->error,OCITransRollback(
+                                               connection->pServiceContext,
+                                               connection->pError,
+                                               (ub4)0));
+        
+                       if (connection->error) {
+                               oci_error(connection->pError, "failed to rollback outstanding transactions!", connection->error);
+                       }
+                       connection->needs_commit = 0;
+               } else {
+                       oci_debug("nothing to do..");
                }
 
                CALL_OCI(OCIHandleFree(
@@ -1461,6 +1466,7 @@ oci_execute(oci_statement *statement, char *func,ub4 mode)
                                        mode));
 
                statement->error = oci_error(statement->pError, "OCIStmtExecute", error);
+
                if (statement->binds) {
                        zend_hash_apply(statement->binds, (apply_func_t) _oci_bind_post_exec TSRMLS_CC);
                }
@@ -1470,6 +1476,12 @@ oci_execute(oci_statement *statement, char *func,ub4 mode)
                if (statement->error) {
                        return 0;
                }
+
+               if (mode & OCI_COMMIT_ON_SUCCESS) {
+                       statement->conn->needs_commit = 0;
+               } else {
+                       statement->conn->needs_commit = 1;
+               }
        }
 
        if ((statement->stmttype == OCI_STMT_SELECT) && (statement->executed == 0)) {
@@ -3523,11 +3535,17 @@ PHP_FUNCTION(ocirollback)
 
        OCI_GET_CONN(connection,conn);
 
+    oci_debug("<OCITransRollback");
+
        CALL_OCI_RETURN(connection->error, OCITransRollback(
                                connection->pServiceContext, 
                                connection->pError, 
                                (ub4) 0));
 
+       connection->needs_commit = 0;
+
+    oci_debug(">OCITransRollback");
+
        if (connection->error) {
                oci_error(connection->pError, "OCIRollback", connection->error);
                oci_handle_error(connection, connection->error);
@@ -3560,6 +3578,8 @@ PHP_FUNCTION(ocicommit)
                                connection->pError, 
                                (ub4) 0));
 
+       connection->needs_commit = 0;
+
     oci_debug(">OCITransCommit");
 
        if (connection->error) {
index 0f6f657686b4d146cb55cb2f034343aa1a0cf0f6..07fdc8e9dc359ed0356d24bc5721f077723d2656 100644 (file)
@@ -79,6 +79,7 @@ typedef struct {
     OCISvcCtx *pServiceContext;
        sword error;
     OCIError *pError;
+       int needs_commit;
 } oci_connection;
 
 typedef struct {