only rollback if transaction status indicates need of action
[m6w6/ext-pq] / src / php_pq.c
index 2ac9b196edcd996c3bd72925de4ffd3414f9c477..a465eeddb99db1f52d0b133162a9d1d3bf6709eb 100644 (file)
@@ -1803,8 +1803,9 @@ static void php_pqconn_persistent_resource_factory_dtor(void *opaque, void *hand
 {
        PGresult *res;
 
+
        /* clean up */
-       if ((res = PQexec(handle, "ROLLBACK; RESET ALL;"))) {
+       if ((res = PQexec(handle, PQtransactionStatus(handle) == PQTRANS_IDLE ? "RESET ALL" : "ROLLBACK; RESET ALL"))) {
                PHP_PQclear(res);
        }
 
@@ -3592,12 +3593,44 @@ static PHP_METHOD(pqstm, desc) {
        zend_restore_error_handling(&zeh TSRMLS_CC);
 }
 
+ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc_async, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqstm, descAsync) {
+       zend_error_handling zeh;
+
+       zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC);
+       if (SUCCESS == zend_parse_parameters_none()) {
+               php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+               if (obj->intern) {
+
+                       obj->intern->conn->intern->poller = PQconsumeInput;
+
+                       if (PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
+                               RETVAL_TRUE;
+                       } else {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               RETVAL_FALSE;
+                       }
+
+                       php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+
+               } else {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Statement not initialized");
+                       RETVAL_FALSE;
+               }
+       }
+       zend_restore_error_handling(&zeh TSRMLS_CC);
+}
+
+
 static zend_function_entry php_pqstm_methods[] = {
        PHP_ME(pqstm, __construct, ai_pqstm_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_ME(pqstm, bind, ai_pqstm_bind, ZEND_ACC_PUBLIC)
        PHP_ME(pqstm, exec, ai_pqstm_exec, ZEND_ACC_PUBLIC)
        PHP_ME(pqstm, desc, ai_pqstm_desc, ZEND_ACC_PUBLIC)
        PHP_ME(pqstm, execAsync, ai_pqstm_exec_async, ZEND_ACC_PUBLIC)
+       PHP_ME(pqstm, descAsync, ai_pqstm_desc_async, ZEND_ACC_PUBLIC)
        {0}
 };