rename php_pq_clear_res -> php_pqres_clear
[m6w6/ext-pq] / src / php_pqtxn.c
index fcf7a4bad5f6ee2f46b34687b20f366dd0a4024d..e90a2d8738313c6e4214eb808ab5c948c7d36d1b 100644 (file)
@@ -32,7 +32,7 @@ zend_class_entry *php_pqtxn_class_entry;
 static zend_object_handlers php_pqtxn_object_handlers;
 static HashTable php_pqtxn_object_prophandlers;
 
-const char *isolation_level(long *isolation)
+const char *php_pq_isolation_level(long *isolation)
 {
        switch (*isolation) {
        case PHP_PQTXN_SERIALIZABLE:
@@ -54,11 +54,11 @@ static void php_pqtxn_object_free(void *o TSRMLS_DC)
        fprintf(stderr, "FREE txn(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 #endif
        if (obj->intern) {
-               if (obj->intern->open) {
-                       PGresult *res = PQexec(obj->intern->conn->intern->conn, "ROLLBACK");
+               if (obj->intern->open && obj->intern->conn->intern) {
+                       PGresult *res = php_pq_exec(obj->intern->conn->intern->conn, "ROLLBACK");
 
                        if (res) {
-                               PHP_PQclear(res);
+                               php_pqres_clear(res);
                        }
                }
                php_pq_object_delref(obj->intern->conn TSRMLS_CC);
@@ -146,13 +146,13 @@ static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value
 
        switch ((obj->intern->isolation = Z_LVAL_P(zisolation))) {
        case PHP_PQTXN_READ_COMMITTED:
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL READ COMMITED");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL READ COMMITED");
                break;
        case PHP_PQTXN_REPEATABLE_READ:
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ");
                break;
        case PHP_PQTXN_SERIALIZABLE:
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
                break;
        default:
                obj->intern->isolation = orig;
@@ -166,7 +166,7 @@ static void php_pqtxn_object_write_isolation(zval *object, void *o, zval *value
 
        if (res) {
                php_pqres_success(res TSRMLS_CC);
-               PHP_PQclear(res);
+               php_pqres_clear(res);
        }
 }
 
@@ -176,14 +176,14 @@ static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value T
        PGresult *res;
 
        if ((obj->intern->readonly = z_is_true(value))) {
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION READ ONLY");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION READ ONLY");
        } else {
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION READ WRITE");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION READ WRITE");
        }
 
        if (res) {
                php_pqres_success(res TSRMLS_CC);
-               PHP_PQclear(res);
+               php_pqres_clear(res);
        }
 }
 
@@ -193,14 +193,14 @@ static void php_pqtxn_object_write_deferrable(zval *object, void *o, zval *value
        PGresult *res;
 
        if ((obj->intern->deferrable = z_is_true(value))) {
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION DEFERRABLE");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION DEFERRABLE");
        } else {
-               res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION NOT DEFERRABLE");
+               res = php_pq_exec(obj->intern->conn->intern->conn, "SET TRANSACTION NOT DEFERRABLE");
        }
 
        if (res) {
                php_pqres_success(res TSRMLS_CC);
-               PHP_PQclear(res);
+               php_pqres_clear(res);
        }
 }
 
@@ -217,7 +217,7 @@ static PHP_METHOD(pqtxn, __construct) {
        zval *zconn;
        long isolation = PHP_PQTXN_READ_COMMITTED;
        zend_bool async = 0, readonly = 0, deferrable = 0;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|blbb", &zconn, php_pqconn_class_entry, &async, &isolation, &readonly, &deferrable);
@@ -269,7 +269,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_savepoint, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, savepoint) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -291,13 +291,13 @@ static PHP_METHOD(pqtxn, savepoint) {
                        smart_str_appends(&cmd, "\"");
                        smart_str_0(&cmd);
 
-                       res = PQexec(obj->intern->conn->intern->conn, cmd.c);
+                       res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 
                        if (!res) {
                                throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                php_pqres_success(res TSRMLS_CC);
-                               PHP_PQclear(res);
+                               php_pqres_clear(res);
                        }
 
                        smart_str_free(&cmd);
@@ -309,7 +309,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_savepoint_async, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, savepointAsync) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -343,7 +343,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_commit, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, commit) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -355,20 +355,20 @@ static PHP_METHOD(pqtxn, commit) {
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transacation not initialized");
                } else if (!obj->intern->open) {
-                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transacation already closed");
+                       throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
                } else {
                        PGresult *res;
                        smart_str cmd = {0};
 
                        if (!obj->intern->savepoint) {
-                               res = PQexec(obj->intern->conn->intern->conn, "COMMIT");
+                               res = php_pq_exec(obj->intern->conn->intern->conn, "COMMIT");
                        } else {
                                smart_str_appends(&cmd, "RELEASE SAVEPOINT \"");
                                smart_str_append_unsigned(&cmd, obj->intern->savepoint--);
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
 
-                               res = PQexec(obj->intern->conn->intern->conn, cmd.c);
+                               res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
                        }
 
                        if (!res) {
@@ -379,7 +379,7 @@ static PHP_METHOD(pqtxn, commit) {
                                                obj->intern->open = 0;
                                        }
                                }
-                               PHP_PQclear(res);
+                               php_pqres_clear(res);
                        }
 
                        smart_str_free(&cmd);
@@ -392,7 +392,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_commit_async, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, commitAsync) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -439,7 +439,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_rollback, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, rollback) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -457,14 +457,14 @@ static PHP_METHOD(pqtxn, rollback) {
                        smart_str cmd = {0};
 
                        if (!obj->intern->savepoint) {
-                               res = PQexec(obj->intern->conn->intern->conn, "ROLLBACK");
+                               res = php_pq_exec(obj->intern->conn->intern->conn, "ROLLBACK");
                        } else {
                                smart_str_appends(&cmd, "ROLLBACK TO SAVEPOINT \"");
                                smart_str_append_unsigned(&cmd, obj->intern->savepoint--);
                                smart_str_appends(&cmd, "\"");
                                smart_str_0(&cmd);
 
-                               res = PQexec(obj->intern->conn->intern->conn, cmd.c);
+                               res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
                        }
 
                        if (!res) {
@@ -475,7 +475,7 @@ static PHP_METHOD(pqtxn, rollback) {
                                                obj->intern->open = 0;
                                        }
                                }
-                               PHP_PQclear(res);
+                               php_pqres_clear(res);
                        }
 
                        smart_str_free(&cmd);
@@ -488,7 +488,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_rollback_async, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, rollbackAsync) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -535,7 +535,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_export_snapshot, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, exportSnapshot) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -547,7 +547,7 @@ static PHP_METHOD(pqtxn, exportSnapshot) {
                if (!obj->intern) {
                        throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
                } else {
-                       PGresult *res = PQexec(obj->intern->conn->intern->conn, "SELECT pg_export_snapshot()");
+                       PGresult *res = php_pq_exec(obj->intern->conn->intern->conn, "SELECT pg_export_snapshot()");
 
                        if (!res) {
                                throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
@@ -556,7 +556,7 @@ static PHP_METHOD(pqtxn, exportSnapshot) {
                                        RETVAL_STRING(PQgetvalue(res, 0, 0), 1);
                                }
 
-                               PHP_PQclear(res);
+                               php_pqres_clear(res);
                        }
 
                        php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
@@ -568,7 +568,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_export_snapshot_async, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, exportSnapshotAsync) {
        zend_error_handling zeh;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters_none();
@@ -595,7 +595,7 @@ static PHP_METHOD(pqtxn, importSnapshot) {
        zend_error_handling zeh;
        char *snapshot_str;
        int snapshot_len;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &snapshot_str, &snapshot_len);
@@ -621,13 +621,13 @@ static PHP_METHOD(pqtxn, importSnapshot) {
                                smart_str_appends(&cmd, sid);
                                smart_str_0(&cmd);
 
-                               res = PQexec(obj->intern->conn->intern->conn, cmd.c);
+                               res = php_pq_exec(obj->intern->conn->intern->conn, cmd.c);
 
                                if (!res) {
                                        throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to import transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
                                        php_pqres_success(res TSRMLS_CC);
-                                       PHP_PQclear(res);
+                                       php_pqres_clear(res);
                                }
 
                                smart_str_free(&cmd);
@@ -644,7 +644,7 @@ static PHP_METHOD(pqtxn, importSnapshotAsync) {
        zend_error_handling zeh;
        char *snapshot_str;
        int snapshot_len;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &snapshot_str, &snapshot_len);
@@ -689,7 +689,7 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, openLOB) {
        zend_error_handling zeh;
        long mode = INV_WRITE|INV_READ, loid;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &loid, &mode);
@@ -704,7 +704,7 @@ static PHP_METHOD(pqtxn, openLOB) {
                        int lofd = lo_open(obj->intern->conn->intern->conn, loid, mode);
 
                        if (lofd < 0) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
 
@@ -728,7 +728,7 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, createLOB) {
        zend_error_handling zeh;
        long mode = INV_WRITE|INV_READ;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mode);
@@ -743,12 +743,12 @@ static PHP_METHOD(pqtxn, createLOB) {
                        Oid loid = lo_creat(obj->intern->conn->intern->conn, mode);
 
                        if (loid == InvalidOid) {
-                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create large object with mode '%s' (%s)", strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                               throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create large object with mode '%s' (%s)", php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                        } else {
                                int lofd = lo_open(obj->intern->conn->intern->conn, loid, mode);
 
                                if (lofd < 0) {
-                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s': %s", loid, strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+                                       throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s': %s", loid, php_pq_strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
                                } else {
                                        php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
 
@@ -773,7 +773,7 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(pqtxn, unlinkLOB) {
        zend_error_handling zeh;
        long loid;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &loid);
@@ -805,7 +805,7 @@ static PHP_METHOD(pqtxn, importLOB) {
        char *path_str;
        int path_len;
        long oid = InvalidOid;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &path_str, &path_len, &oid);
@@ -843,7 +843,7 @@ static PHP_METHOD(pqtxn, exportLOB) {
        char *path_str;
        int path_len;
        long oid;
-       STATUS rv;
+       ZEND_RESULT_CODE rv;
 
        zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
        rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lp", &oid, &path_str, &path_len);