X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fphp_pqstm.c;h=7156145bcab1b053b7abaa21ed5534f0eb4273a1;hb=56e9738f80aee54b362f90a42c724abad5378e31;hp=d9ec1eab1c689663079aff228b614a9dad56e5c5;hpb=85d42a9baa5dcdcd1826dfe801df3ba89f9e0f72;p=m6w6%2Fext-pq diff --git a/src/php_pqstm.c b/src/php_pqstm.c index d9ec1ea..7156145 100644 --- a/src/php_pqstm.c +++ b/src/php_pqstm.c @@ -36,26 +36,28 @@ static void php_pqstm_object_free(void *o TSRMLS_DC) fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn); #endif if (obj->intern) { - char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name)); + if (obj->intern->conn->intern) { + char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name)); - php_pq_callback_dtor(&obj->intern->conn->intern->onevent); + php_pq_callback_dtor(&obj->intern->conn->intern->onevent); - if (quoted_name) { - PGresult *res; - smart_str cmd = {0}; + if (quoted_name) { + PGresult *res; + smart_str cmd = {0}; - smart_str_appends(&cmd, "DEALLOCATE "); - smart_str_appends(&cmd, quoted_name); - smart_str_0(&cmd); - PQfreemem(quoted_name); + smart_str_appends(&cmd, "DEALLOCATE "); + smart_str_appends(&cmd, quoted_name); + smart_str_0(&cmd); + PQfreemem(quoted_name); - if ((res = PQexec(obj->intern->conn->intern->conn, cmd.c))) { - PHP_PQclear(res); + if ((res = PQexec(obj->intern->conn->intern->conn, cmd.c))) { + PHP_PQclear(res); + } + smart_str_free(&cmd); } - smart_str_free(&cmd); - } - php_pq_object_delref(obj->intern->conn TSRMLS_CC); + php_pq_object_delref(obj->intern->conn TSRMLS_CC); + } efree(obj->intern->name); zend_hash_destroy(&obj->intern->bound); if (obj->intern->params) { @@ -112,7 +114,7 @@ static void php_pqstm_object_read_connection(zval *object, void *o, zval *return ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_construct, 0, 0, 3) - ZEND_ARG_OBJ_INFO(0, Connection, pq\\Connection, 0) + ZEND_ARG_OBJ_INFO(0, connection, pq\\Connection, 0) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, query) ZEND_ARG_ARRAY_INFO(0, types, 1) @@ -134,7 +136,9 @@ static PHP_METHOD(pqstm, __construct) { php_pqstm_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); php_pqconn_object_t *conn_obj = zend_object_store_get_object(zconn TSRMLS_CC); - if (!conn_obj->intern) { + if (obj->intern) { + throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\Statement already initialized"); + } else if (!conn_obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else { php_pq_params_t *params = php_pq_params_init(&conn_obj->intern->converters, ztypes ? Z_ARRVAL_P(ztypes) : NULL, NULL TSRMLS_CC); @@ -164,17 +168,24 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqstm_bind, 0, 0, 2) ZEND_END_ARG_INFO(); static PHP_METHOD(pqstm, bind) { long param_no; - zval *param_ref; + zval **param_ref; + zend_error_handling zeh; + STATUS rv; + + zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", ¶m_no, ¶m_ref); + zend_restore_error_handling(&zeh TSRMLS_CC); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", ¶m_no, ¶m_ref)) { + 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 { - 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); + SEPARATE_ZVAL_TO_MAKE_IS_REF(param_ref); + Z_ADDREF_PP(param_ref); + zend_hash_index_update(&obj->intern->bound, param_no, (void *) param_ref, sizeof(zval *), NULL); + zend_hash_sort(&obj->intern->bound, zend_qsort, php_pq_compare_index, 0 TSRMLS_CC); } } } @@ -241,8 +252,10 @@ static PHP_METHOD(pqstm, execAsync) { if (!rc) { throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn)); +#if HAVE_PQSETSINGLEROWMODE } 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)); +#endif } else { php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC); obj->intern->conn->intern->poller = PQconsumeInput;