X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqtxn.c;h=0f5c4eb716c44dd0eb63ec7db88d63cb5f0ea71a;hp=411b7fbc587905fc70335efa26cf3ede176cdc42;hb=a5470139f5305341fca92f942852d1ae18b254ea;hpb=6c838021951716e5b37a0c891cd40c669268de8c diff --git a/src/php_pqtxn.c b/src/php_pqtxn.c index 411b7fb..0f5c4eb 100644 --- a/src/php_pqtxn.c +++ b/src/php_pqtxn.c @@ -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: @@ -175,7 +175,7 @@ static void php_pqtxn_object_write_readonly(zval *object, void *o, zval *value T php_pqtxn_object_t *obj = o; PGresult *res; - if ((obj->intern->readonly = zend_is_true(value))) { + if ((obj->intern->readonly = z_is_true(value))) { res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION READ ONLY"); } else { res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION READ WRITE"); @@ -192,7 +192,7 @@ static void php_pqtxn_object_write_deferrable(zval *object, void *o, zval *value php_pqtxn_object_t *obj = o; PGresult *res; - if ((obj->intern->deferrable = zend_is_true(value))) { + if ((obj->intern->deferrable = z_is_true(value))) { res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION DEFERRABLE"); } else { res = PQexec(obj->intern->conn->intern->conn, "SET TRANSACTION NOT DEFERRABLE"); @@ -229,6 +229,20 @@ static PHP_METHOD(pqtxn, __construct) { if (!conn_obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else { + + switch (ZEND_NUM_ARGS()) { + case 1: + case 2: + isolation = conn_obj->intern->default_txn_isolation; + /* no break */ + case 3: + readonly = conn_obj->intern->default_txn_readonly; + /* no break */ + case 4: + deferrable = conn_obj->intern->default_txn_deferrable; + break; + } + if (async) { rv = php_pqconn_start_transaction_async(zconn, conn_obj, isolation, readonly, deferrable TSRMLS_CC); } else { @@ -341,7 +355,7 @@ 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}; @@ -690,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)); @@ -729,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)); @@ -872,6 +886,12 @@ static zend_function_entry php_pqtxn_methods[] = { {0} }; +PHP_MSHUTDOWN_FUNCTION(pqtxn) +{ + zend_hash_destroy(&php_pqtxn_object_prophandlers); + return SUCCESS; +} + PHP_MINIT_FUNCTION(pqtxn) { zend_class_entry ce = {0}; @@ -886,6 +906,7 @@ PHP_MINIT_FUNCTION(pqtxn) php_pqtxn_object_handlers.write_property = php_pq_object_write_prop; php_pqtxn_object_handlers.clone_obj = NULL; php_pqtxn_object_handlers.get_property_ptr_ptr = NULL; + php_pqtxn_object_handlers.get_gc = NULL; php_pqtxn_object_handlers.get_properties = php_pq_object_properties; php_pqtxn_object_handlers.get_debug_info = php_pq_object_debug_info;