+ if (SUCCESS == rv) {
+ php_pqstm_t *stm = ecalloc(1, sizeof(*stm));
+
+ php_pq_object_addref(conn_obj TSRMLS_CC);
+ stm->conn = conn_obj;
+ stm->name = estrdup(name_str);
+ ZEND_INIT_SYMTABLE(&stm->bound);
+ obj->intern = stm;
+ }
+ }
+ }
+}
+ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_bind, 0, 0, 2)
+ ZEND_ARG_INFO(0, param_no)
+ ZEND_ARG_INFO(1, param_ref)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqstm, bind) {
+ long param_no;
+ zval *param_ref;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", ¶m_no, ¶m_ref)) {
+ php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+ } else {
+ Z_ADDREF_P(param_ref);
+ zend_hash_index_update(&obj->intern->bound, param_no, (void *) ¶m_ref, sizeof(zval *), NULL);
+ zend_hash_sort(&obj->intern->bound, zend_qsort, compare_index, 0 TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_exec, 0, 0, 0)
+ ZEND_ARG_ARRAY_INFO(0, params, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqstm, exec) {
+ zend_error_handling zeh;
+ zval *zparams = NULL;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &zparams);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+ } else {
+ int count = 0;
+ char **params = NULL;
+ HashTable zdtor;
+ PGresult *res;
+
+ ZEND_INIT_SYMTABLE(&zdtor);
+
+ if (zparams) {
+ count = php_pq_params_to_array(Z_ARRVAL_P(zparams), ¶ms, &zdtor TSRMLS_CC);
+ } else {
+ count = php_pq_params_to_array(&obj->intern->bound, ¶ms, &zdtor TSRMLS_CC);
+ }
+
+ res = PQexecPrepared(obj->intern->conn->intern->conn, obj->intern->name, count, (const char *const*) params, NULL, NULL, 0);
+
+ if (params) {
+ efree(params);
+ }
+ zend_hash_destroy(&zdtor);
+
+ if (!res) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+ php_pq_object_to_zval_no_addref(PQresultInstanceData(res, php_pqconn_event), &return_value TSRMLS_CC);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_exec_async, 0, 0, 0)
+ ZEND_ARG_ARRAY_INFO(0, params, 1)
+ ZEND_ARG_INFO(0, callable)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqstm, execAsync) {
+ zend_error_handling zeh;
+ zval *zparams = NULL;
+ php_pq_callback_t resolver = {{0}};
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!f", &zparams, &resolver.fci, &resolver.fcc);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+ } else {
+ int count;
+ char **params = NULL;
+ HashTable zdtor;
+
+ if (zparams) {
+ ZEND_INIT_SYMTABLE(&zdtor);
+ count = php_pq_params_to_array(Z_ARRVAL_P(zparams), ¶ms, &zdtor TSRMLS_CC);
+ }
+
+ if (!PQsendQueryPrepared(obj->intern->conn->intern->conn, obj->intern->name, count, (const char *const*) params, NULL, NULL, 0)) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
+ if (resolver.fci.size > 0) {
+ obj->intern->conn->intern->onevent = resolver;
+ php_pq_callback_addref(&obj->intern->conn->intern->onevent);
+ }
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ }
+
+ if (params) {
+ efree(params);
+ }
+ if (zparams) {
+ zend_hash_destroy(&zdtor);
+ }
+
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_desc, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqstm, desc) {
+ zend_error_handling zeh;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+ } else {
+ PGresult *res = PQdescribePrepared(obj->intern->conn->intern->conn, obj->intern->name);
+
+ if (!res) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to describe statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+ int p, params;
+
+ array_init(return_value);
+ for (p = 0, params = PQnparams(res); p < params; ++p) {
+ add_next_index_long(return_value, PQparamtype(res, p));
+ }
+ }
+ PHP_PQclear(res);
+ php_pqconn_notify_listeners(obj->intern->conn 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;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Statement not initialized");
+ } else if (!PQsendDescribePrepared(obj->intern->conn->intern->conn, obj->intern->name)) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to describe statement: %s", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ php_pqconn_notify_listeners(obj->intern->conn 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}
+};
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_construct, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0)
+ ZEND_ARG_INFO(0, async)
+ ZEND_ARG_INFO(0, isolation)
+ ZEND_ARG_INFO(0, readonly)
+ ZEND_ARG_INFO(0, deferrable)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, __construct) {
+ zend_error_handling zeh;
+ zval *zconn;
+ long isolation = PHP_PQTXN_READ_COMMITTED;
+ zend_bool async = 0, readonly = 0, deferrable = 0;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+
+ if (!conn_obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ if (async) {
+ rv = php_pqconn_start_transaction_async(zconn, conn_obj, isolation, readonly, deferrable TSRMLS_CC);
+ } else {
+ rv = php_pqconn_start_transaction(zconn, conn_obj, isolation, readonly, deferrable TSRMLS_CC);
+ }
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->intern = ecalloc(1, sizeof(*obj->intern));
+
+ php_pq_object_addref(conn_obj TSRMLS_CC);
+ obj->intern->conn = conn_obj;
+ obj->intern->open = 1;
+ obj->intern->isolation = isolation;
+ obj->intern->readonly = readonly;
+ obj->intern->deferrable = deferrable;
+ }
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!obj->intern->open) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
+ } else {
+ PGresult *res;
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "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);
+
+ 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);
+ }
+
+ smart_str_free(&cmd);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!obj->intern->open) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
+ } else {
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "SAVEPOINT \"");
+ smart_str_append_unsigned(&cmd, ++obj->intern->savepoint);
+ smart_str_appends(&cmd, "\"");
+ smart_str_0(&cmd);
+
+ if (!PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to create %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ }
+
+ smart_str_free(&cmd);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ 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");
+ } else {
+ PGresult *res;
+ smart_str cmd = {0};
+
+ if (!obj->intern->savepoint) {
+ res = PQexec(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);
+ }
+
+ if (!res) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "commit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+ if (!cmd.c) {
+ obj->intern->open = 0;
+ }
+ }
+ PHP_PQclear(res);
+ }
+
+ smart_str_free(&cmd);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!obj->intern->open) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
+ } else {
+ int rc;
+ smart_str cmd = {0};
+
+ if (!obj->intern->savepoint) {
+ rc = PQsendQuery(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);
+
+ rc = PQsendQuery(obj->intern->conn->intern->conn, cmd.c);
+ }
+
+ if (!rc) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "commmit transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (!cmd.c) {
+ obj->intern->open = 0;
+ }
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+
+ smart_str_free(&cmd);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!obj->intern->open) {
+ 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, "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);
+ }
+
+ if (!res) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+ if (!cmd.c) {
+ obj->intern->open = 0;
+ }
+ }
+ PHP_PQclear(res);
+ }
+
+ smart_str_free(&cmd);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!obj->intern->open) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction already closed");
+ } else {
+ int rc;
+ smart_str cmd = {0};
+
+ if (!obj->intern->savepoint) {
+ rc = PQsendQuery(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);
+
+ rc = PQsendQuery(obj->intern->conn->intern->conn, cmd.c);
+ }
+
+ if (!rc) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c ? cmd.c : "rollback transaction", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (!cmd.c) {
+ obj->intern->open = 0;
+ }
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ }
+
+ smart_str_free(&cmd);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ 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()");
+
+ if (!res) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ if (SUCCESS == php_pqres_success(res TSRMLS_CC)) {
+ RETVAL_STRING(PQgetvalue(res, 0, 0), 1);
+ }
+
+ PHP_PQclear(res);
+ }
+
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+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_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!PQsendQuery(obj->intern->conn->intern->conn, "SELECT pg_export_snapshot()")) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to export transaction snapshot (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_import_snapshot, 0, 0, 1)
+ ZEND_ARG_INFO(0, snapshot_id)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, importSnapshot) {
+ zend_error_handling zeh;
+ char *snapshot_str;
+ int snapshot_len;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (obj->intern->isolation < PHP_PQTXN_REPEATABLE_READ) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
+ } else {
+ char *sid = PQescapeLiteral(obj->intern->conn->intern->conn, snapshot_str, snapshot_len);
+
+ if (!sid) {
+ throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ PGresult *res;
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "SET TRANSACTION SNAPSHOT ");
+ smart_str_appends(&cmd, sid);
+ smart_str_0(&cmd);
+
+ res = PQexec(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);
+ }
+
+ smart_str_free(&cmd);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_import_snapshot_async, 0, 0, 1)
+ ZEND_ARG_INFO(0, snapshot_id)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, importSnapshotAsync) {
+ zend_error_handling zeh;
+ char *snapshot_str;
+ int snapshot_len;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (obj->intern->isolation < PHP_PQTXN_REPEATABLE_READ) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transaction must have at least isolation level REPEATABLE READ to be able to import a snapshot");
+ } else {
+ char *sid = PQescapeLiteral(obj->intern->conn->intern->conn, snapshot_str, snapshot_len);
+
+ if (!sid) {
+ throw_exce(EX_ESCAPE TSRMLS_CC, "Failed to quote snapshot identifier (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "SET TRANSACTION SNAPSHOT ");
+ smart_str_appends(&cmd, sid);
+ smart_str_0(&cmd);
+
+ if (!PQsendQuery(obj->intern->conn->intern->conn, cmd.c)) {
+ throw_exce(EX_IO TSRMLS_CC, "Failed to %s (%s)", cmd.c, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ obj->intern->conn->intern->poller = PQconsumeInput;
+ }
+
+ smart_str_free(&cmd);
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+ }
+}
+
+static const char *strmode(long mode)
+{
+ switch (mode & (INV_READ|INV_WRITE)) {
+ case INV_READ|INV_WRITE:
+ return "rw";
+ case INV_READ:
+ return "r";
+ case INV_WRITE:
+ return "w";
+ default:
+ return "-";
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_open_lob, 0, 0, 1)
+ ZEND_ARG_INFO(0, oid)
+ ZEND_ARG_INFO(0, mode)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, openLOB) {
+ zend_error_handling zeh;
+ long mode = INV_WRITE|INV_READ, loid;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } 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=%ld with mode '%s' (%s)", loid, strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
+
+ lob->lofd = lofd;
+ lob->loid = loid;
+ php_pq_object_addref(obj TSRMLS_CC);
+ lob->txn = obj;
+
+ return_value->type = IS_OBJECT;
+ return_value->value.obj = php_pqlob_create_object_ex(php_pqlob_class_entry, lob, NULL TSRMLS_CC);
+ }
+
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_create_lob, 0, 0, 0)
+ ZEND_ARG_INFO(0, mode)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, createLOB) {
+ zend_error_handling zeh;
+ long mode = INV_WRITE|INV_READ;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else {
+ 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));
+ } 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=%ld with mode '%s': %s", loid, strmode(mode), PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ } else {
+ php_pqlob_t *lob = ecalloc(1, sizeof(*lob));
+
+ lob->lofd = lofd;
+ lob->loid = loid;
+ php_pq_object_addref(obj TSRMLS_CC);
+ lob->txn = obj;
+
+ return_value->type = IS_OBJECT;
+ return_value->value.obj = php_pqlob_create_object_ex(php_pqlob_class_entry, lob, NULL TSRMLS_CC);
+ }
+ }
+
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_unlink_lob, 0, 0, 1)
+ ZEND_ARG_INFO(0, oid)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqtxn, unlinkLOB) {
+ zend_error_handling zeh;
+ long loid;
+ STATUS 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);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else {
+ int rc = lo_unlink(obj->intern->conn->intern->conn, loid);
+
+ if (rc != 1) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to unlink LOB (oid=%ld): %s", loid, PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+ }
+
+ php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+static zend_function_entry php_pqtxn_methods[] = {
+ PHP_ME(pqtxn, __construct, ai_pqtxn_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(pqtxn, commit, ai_pqtxn_commit, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, rollback, ai_pqtxn_rollback, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, commitAsync, ai_pqtxn_commit_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, rollbackAsync, ai_pqtxn_rollback_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, savepoint, ai_pqtxn_savepoint, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, savepointAsync, ai_pqtxn_savepoint_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, exportSnapshot, ai_pqtxn_export_snapshot, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, exportSnapshotAsync, ai_pqtxn_export_snapshot_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, importSnapshot, ai_pqtxn_import_snapshot, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, importSnapshotAsync, ai_pqtxn_import_snapshot_async, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, openLOB, ai_pqtxn_open_lob, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, createLOB, ai_pqtxn_create_lob, ZEND_ACC_PUBLIC)
+ PHP_ME(pqtxn, unlinkLOB, ai_pqtxn_unlink_lob, ZEND_ACC_PUBLIC)
+ {0}
+};
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqcancel_construct, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqcancel, __construct) {
+ zend_error_handling zeh;
+ zval *zconn;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zconn, php_pqconn_class_entry);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+
+ if (!conn_obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ PGcancel *cancel = PQgetCancel(conn_obj->intern->conn);
+
+ if (!cancel) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to acquire cancel (%s)", PHP_PQerrorMessage(conn_obj->intern->conn));
+ } else {
+ php_pqcancel_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->intern = ecalloc(1, sizeof(*obj->intern));
+ obj->intern->cancel = cancel;
+ php_pq_object_addref(conn_obj TSRMLS_CC);
+ obj->intern->conn = conn_obj;
+ }
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqcancel_cancel, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqcancel, cancel) {
+ zend_error_handling zeh;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters_none();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqcancel_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Cancel not initialized");
+ } else {
+ char err[256] = {0};
+
+ if (!PQcancel(obj->intern->cancel, err, sizeof(err))) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to request cancellation (%s)", err);
+ }
+ }
+ }
+}
+
+static zend_function_entry php_pqcancel_methods[] = {
+ PHP_ME(pqcancel, __construct, ai_pqcancel_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(pqcancel, cancel, ai_pqcancel_cancel, ZEND_ACC_PUBLIC)
+ {0}
+};
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqevent_construct, 0, 0, 3)
+ ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0)
+ ZEND_ARG_INFO(0, type)
+ ZEND_ARG_INFO(0, callable)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqevent, __construct) {
+ zend_error_handling zeh;
+ zval *zconn;
+ char *type_str;
+ int type_len;
+ php_pq_callback_t cb;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Osf", &zconn, php_pqconn_class_entry, &type_str, &type_len, &cb.fci, &cb.fcc);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC);
+
+ if (!conn_obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ php_pqevent_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->intern = ecalloc(1, sizeof(*obj->intern));
+ php_pq_callback_addref(&cb);
+ obj->intern->cb = cb;
+ obj->intern->type = estrdup(type_str);
+ obj->intern->h = php_pqconn_add_eventhandler(conn_obj, type_str, type_len, getThis() TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqevent_trigger, 0, 0, 1)
+ ZEND_ARG_ARRAY_INFO(0, args, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqevent, trigger) {
+ zend_error_handling zeh;
+ zval *args;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &args);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqevent_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Event not initialized");
+ } else {
+ zval *rv = NULL;
+
+ if (SUCCESS != zend_fcall_info_call(&obj->intern->cb.fci, &obj->intern->cb.fcc, &rv, args TSRMLS_CC)) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to trigger event");
+ } else {
+ if (rv) {
+ RETVAL_ZVAL(rv, 0, 1);
+ } else {
+ RETVAL_TRUE;
+ }
+ }
+ }
+ }
+}
+
+static zend_function_entry php_pqevent_methods[] = {
+ PHP_ME(pqevent, __construct, ai_pqevent_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(pqevent, trigger, ai_pqevent_trigger, ZEND_ACC_PUBLIC)
+ {0}
+};
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_construct, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, transaction, pq\\Transaction, 0)
+ ZEND_ARG_INFO(0, oid)
+ ZEND_ARG_INFO(0, mode)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqlob, __construct) {
+ zend_error_handling zeh;
+ zval *ztxn;
+ long mode = INV_WRITE|INV_READ, loid = InvalidOid;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &ztxn, php_pqtxn_class_entry, &loid, &mode);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqtxn_object_t *txn_obj = zend_object_store_get_object(ztxn TSRMLS_CC);
+
+ if (!txn_obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized");
+ } else if (!txn_obj->intern->open) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transation already closed");
+ } else {
+ if (loid == InvalidOid) {
+ loid = lo_creat(txn_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(txn_obj->intern->conn->intern->conn));
+ } else {
+ int lofd = lo_open(txn_obj->intern->conn->intern->conn, loid, mode);
+
+ if (lofd < 0) {
+ throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%ld with mode '%s' (%s)", loid, strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn));
+ } else {
+ php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->intern = ecalloc(1, sizeof(*obj->intern));
+ obj->intern->lofd = lofd;
+ obj->intern->loid = loid;
+ php_pq_object_addref(txn_obj TSRMLS_CC);
+ obj->intern->txn = txn_obj;
+ }
+ }
+
+ php_pqconn_notify_listeners(txn_obj->intern->conn TSRMLS_CC);
+ }
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_write, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqlob, write) {
+ zend_error_handling zeh;
+ char *data_str;
+ int data_len;
+ STATUS rv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_str, &data_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\LOB not initialized");
+ } else {
+ int written = lo_write(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, data_str, data_len);