X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=php_pq.c;h=40d7c649cc0d9fccb57c2abaead998b86aca0a29;hp=171b1d17e10e274569e274911d0d2ce8dbf30c98;hb=c566b350f18fe5d2ac5a28e82948514a8798a2b6;hpb=9746180a4d53f167dd4fd15e0cde34cd348ecb30 diff --git a/php_pq.c b/php_pq.c index 171b1d1..40d7c64 100644 --- a/php_pq.c +++ b/php_pq.c @@ -479,6 +479,14 @@ static void php_pqres_iterator_current(zend_object_iterator *i, zval ***data_ptr *data_ptr = &iter->current_val; } +#if PHP_VERSION_ID >= 50500 +static void php_pqres_iterator_key(zend_object_iterator *i, zval *key TSRMLS_DC) +{ + php_pqres_iterator_t *iter = (php_pqres_iterator_t *) i; + + ZVAL_LONG(key, iter->index); +} +#else static int php_pqres_iterator_key(zend_object_iterator *i, char **key_str, uint *key_len, ulong *key_num TSRMLS_DC) { php_pqres_iterator_t *iter = (php_pqres_iterator_t *) i; @@ -487,6 +495,7 @@ static int php_pqres_iterator_key(zend_object_iterator *i, char **key_str, uint return HASH_KEY_IS_LONG; } +#endif static void php_pqres_iterator_invalidate(zend_object_iterator *i TSRMLS_DC) { @@ -4582,6 +4591,76 @@ static PHP_METHOD(pqtxn, unlinkLOB) { } } +ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_import_lob, 0, 0, 1) + ZEND_ARG_INFO(0, local_path) + ZEND_ARG_INFO(0, oid) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqtxn, importLOB) { + zend_error_handling zeh; + char *path_str; + int path_len; + long oid = 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, "p|l", &path_str, &path_len, &oid); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == SUCCESS) { + 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 (oid == InvalidOid) { + oid = lo_import(obj->intern->conn->intern->conn, path_str); + } else { + oid = lo_import_with_oid(obj->intern->conn->intern->conn, path_str, oid); + } + + if (oid == InvalidOid) { + throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to import LOB from '%s' (%s)", path_str, PHP_PQerrorMessage(obj->intern->conn->intern->conn)); + } else { + RETVAL_LONG(oid); + } + + php_pqconn_notify_listeners(obj->intern->conn TSRMLS_CC); + } + } +} + +ZEND_BEGIN_ARG_INFO_EX(ai_pqtxn_export_lob, 0, 0, 2) + ZEND_ARG_INFO(0, oid) + ZEND_ARG_INFO(0, local_path) +ZEND_END_ARG_INFO(); +static PHP_METHOD(pqtxn, exportLOB) { + zend_error_handling zeh; + char *path_str; + int path_len; + long oid; + STATUS 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); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == SUCCESS) { + 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_export(obj->intern->conn->intern->conn, oid, path_str); + + if (rc == -1) { + throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to export LOB (oid=%u) to '%s' (%s)", oid, path_str, 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) @@ -4597,6 +4676,8 @@ static zend_function_entry php_pqtxn_methods[] = { 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) + PHP_ME(pqtxn, importLOB, ai_pqtxn_import_lob, ZEND_ACC_PUBLIC) + PHP_ME(pqtxn, exportLOB, ai_pqtxn_export_lob, ZEND_ACC_PUBLIC) {0} };