From 5b3712ea05a503958a41eeae9fca779c7f3754b1 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 29 Jul 2023 16:19:03 +0100 Subject: [PATCH] ext/pgsql: remove deprecated default link support --- ext/pgsql/pgsql.c | 518 +++++++++--------- ext/pgsql/pgsql.stub.php | 42 +- ext/pgsql/pgsql_arginfo.h | 42 +- ext/pgsql/php_pgsql.h | 1 - ext/pgsql/tests/05large_object.phpt | 32 +- ext/pgsql/tests/08escape.phpt | 3 - ext/pgsql/tests/18pg_escape_bytea_before.phpt | 1 - ext/pgsql/tests/27large_object_oid.phpt | 17 - .../tests/28large_object_import_oid.phpt | 40 -- ext/pgsql/tests/bug72197.phpt | 16 +- ext/pgsql/tests/bug75419.phpt | 9 +- ext/pgsql/tests/close_default_link.phpt | 9 +- ext/pgsql/tests/connect_after_close.phpt | 19 +- .../deprecated_implicit_default_link.phpt | 144 ----- ext/pgsql/tests/no_link_open.phpt | 5 +- 15 files changed, 323 insertions(+), 575 deletions(-) delete mode 100644 ext/pgsql/tests/deprecated_implicit_default_link.phpt diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index a6cdd590aa593..456db4c0555c2 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -75,21 +75,6 @@ char pgsql_libpq_version[16]; #define PGSQL_RETURN_OID(oid) RETURN_LONG((zend_long)oid) #endif -#define CHECK_DEFAULT_LINK(x) \ - if ((x) == NULL) { \ - zend_throw_error(NULL, "No PostgreSQL connection opened yet"); \ - RETURN_THROWS(); \ - } - -/* This is a bit hacky as the macro usage is "link = FETCH_DEFAULT_LINK();" */ -#define FETCH_DEFAULT_LINK() \ - (PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL); \ - php_error_docref(NULL, E_DEPRECATED, "Automatic fetching of PostgreSQL connection is deprecated") - -/* Used only when creating a connection */ -#define FETCH_DEFAULT_LINK_NO_WARNING() \ - (PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL) - #define CHECK_PGSQL_LINK(link_handle) \ if (link_handle->conn == NULL) { \ zend_throw_error(NULL, "PostgreSQL connection has already been closed"); \ @@ -295,17 +280,6 @@ static zend_string *_php_pgsql_trim_message(const char *message) zend_string_release(msgbuf); \ } \ -static void php_pgsql_set_default_link(zend_object *obj) -{ - GC_ADDREF(obj); - - if (PGG(default_link) != NULL) { - zend_object_release(PGG(default_link)); - } - - PGG(default_link) = obj; -} - static void _close_pgsql_plink(zend_resource *rsrc) { PGconn *link = (PGconn *)rsrc->ptr; @@ -491,7 +465,6 @@ PHP_MSHUTDOWN_FUNCTION(pgsql) PHP_RINIT_FUNCTION(pgsql) { - PGG(default_link) = NULL; PGG(num_links) = PGG(num_persistent); zend_hash_init(&PGG(field_oids), 0, NULL, release_string, 0); zend_hash_init(&PGG(table_oids), 0, NULL, release_string, 0); @@ -500,11 +473,6 @@ PHP_RINIT_FUNCTION(pgsql) PHP_RSHUTDOWN_FUNCTION(pgsql) { - if (PGG(default_link)) { - zend_object_release(PGG(default_link)); - PGG(default_link) = NULL; - } - zend_hash_destroy(&PGG(field_oids)); zend_hash_destroy(&PGG(table_oids)); /* clean up persistent connection */ @@ -636,7 +604,6 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) */ if (!(connect_type & PGSQL_CONNECT_FORCE_NEW) && (index_ptr = zend_hash_find(&PGG(connections), str.s)) != NULL) { - php_pgsql_set_default_link(Z_OBJ_P(index_ptr)); ZVAL_COPY(return_value, index_ptr); goto cleanup; @@ -688,7 +655,6 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (! PGG(ignore_notices) && Z_TYPE_P(return_value) == IS_OBJECT) { PQsetNoticeProcessor(pgsql, _php_pgsql_notice_handler, link); } - php_pgsql_set_default_link(Z_OBJ_P(return_value)); cleanup: smart_str_free(&str); @@ -739,28 +705,21 @@ PHP_FUNCTION(pg_pconnect) /* {{{ Close a PostgreSQL connection */ PHP_FUNCTION(pg_close) { - zval *pgsql_link = NULL; + zval *pgsql_link; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &pgsql_link, pgsql_link_ce) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &pgsql_link, pgsql_link_ce) == FAILURE) { RETURN_THROWS(); } if (!pgsql_link) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - zend_object_release(PGG(default_link)); - PGG(default_link) = NULL; - RETURN_TRUE; + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); - if (link == FETCH_DEFAULT_LINK_NO_WARNING()) { - GC_DELREF(PGG(default_link)); - PGG(default_link) = NULL; - } pgsql_link_free(link); RETURN_TRUE; @@ -783,18 +742,18 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type PGconn *pgsql; char *result; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &pgsql_link, pgsql_link_ce) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &pgsql_link, pgsql_link_ce) == FAILURE) { RETURN_THROWS(); } if (!pgsql_link) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; switch(entry_type) { @@ -900,18 +859,18 @@ PHP_FUNCTION(pg_parameter_status) char *param; size_t len; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, ¶m, &len) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", ¶m, &len) == FAILURE) { - RETURN_THROWS(); - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, ¶m, &len) == FAILURE) { + RETURN_THROWS(); + } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; param = (char*)PQparameterStatus(pgsql, param); @@ -930,18 +889,18 @@ PHP_FUNCTION(pg_ping) PGresult *res; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &pgsql_link, pgsql_link_ce) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &pgsql_link, pgsql_link_ce) == FAILURE) { RETURN_THROWS(); } - if (pgsql_link == NULL) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; /* ping connection */ @@ -972,20 +931,18 @@ PHP_FUNCTION(pg_query) PGresult *pgsql_result; ExecStatusType status; - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &query, &query_len) == FAILURE) { + RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; if (PQsetnonblocking(pgsql, 0)) { @@ -1066,19 +1023,11 @@ PHP_FUNCTION(pg_query_params) ExecStatusType status; pgsql_result_handle *pg_result; - if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &query, &query_len, &pv_param_arr) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osa", &pgsql_link, pgsql_link_ce, &query, &query_len, &pv_param_arr) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osa", &pgsql_link, pgsql_link_ce, &query, &query_len, &pv_param_arr) == FAILURE) { + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -1171,19 +1120,11 @@ PHP_FUNCTION(pg_prepare) ExecStatusType status; pgsql_result_handle *pg_result; - if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &pgsql_link, pgsql_link_ce, &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &pgsql_link, pgsql_link_ce, &stmtname, &stmtname_len, &query, &query_len) == FAILURE) { + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -1252,19 +1193,11 @@ PHP_FUNCTION(pg_execute) ExecStatusType status; pgsql_result_handle *pg_result; - if (ZEND_NUM_ARGS() == 2) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa", &stmtname, &stmtname_len, &pv_param_arr)==FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osa", &pgsql_link, pgsql_link_ce, &stmtname, &stmtname_len, &pv_param_arr) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osa", &pgsql_link, pgsql_link_ce, &stmtname, &stmtname_len, &pv_param_arr) == FAILURE) { + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -2151,18 +2084,18 @@ PHP_FUNCTION(pg_trace) php_stream *stream; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sO!l", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link, pgsql_link_ce, &trace_mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "psO!|l", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link, pgsql_link_ce, &trace_mode) == FAILURE) { RETURN_THROWS(); } if (!pgsql_link) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; stream = php_stream_open_wrapper(z_filename, mode, REPORT_ERRORS, NULL); @@ -2201,18 +2134,17 @@ PHP_FUNCTION(pg_untrace) PGconn *pgsql; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pgsql_link) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r!", &pgsql_link) == FAILURE) { RETURN_THROWS(); } - if (pgsql_link == NULL) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); pgsql = link->conn; PQuntrace(pgsql); @@ -2228,20 +2160,11 @@ PHP_FUNCTION(pg_lo_create) Oid pgsql_oid, wanted_oid = InvalidOid; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &pgsql_link, &oid) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|z", &pgsql_link, &oid) == FAILURE) { RETURN_THROWS(); } - /* Overloaded method uses default link if arg 1 is not an object, set oid pointer */ - if ((ZEND_NUM_ARGS() == 1) && (Z_TYPE_P(pgsql_link) != IS_OBJECT)) { - oid = pgsql_link; - pgsql_link = NULL; - } - - if (pgsql_link == NULL) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else if ((Z_TYPE_P(pgsql_link) == IS_OBJECT && instanceof_function(Z_OBJCE_P(pgsql_link), pgsql_link_ce))) { + if ((Z_TYPE_P(pgsql_link) == IS_OBJECT && instanceof_function(Z_OBJCE_P(pgsql_link), pgsql_link_ce))) { link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); } else { @@ -2320,27 +2243,8 @@ PHP_FUNCTION(pg_lo_unlink) link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S", &oid_string) == SUCCESS) { - if (!is_valid_oid_string(oid_string, &oid)) { - /* wrong integer format */ - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "l", &oid_long) == SUCCESS) { - if (oid_long <= (zend_long)InvalidOid) { - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - oid = (Oid)oid_long; - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - zend_argument_count_error("Requires 1 or 2 arguments, %d given", ZEND_NUM_ARGS()); + zend_argument_count_error("Requires 2 arguments, %d given", ZEND_NUM_ARGS()); RETURN_THROWS(); } @@ -2389,28 +2293,8 @@ PHP_FUNCTION(pg_lo_open) link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "SS", &oid_string, &mode) == SUCCESS) { - if (!is_valid_oid_string(oid_string, &oid)) { - /* wrong integer format */ - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "lS", &oid_long, &mode) == SUCCESS) { - if (oid_long <= (zend_long)InvalidOid) { - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - oid = (Oid)oid_long; - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - zend_argument_count_error("Requires 1 or 2 arguments, %d given", ZEND_NUM_ARGS()); + zend_argument_count_error("Requires 3 arguments, %d given", ZEND_NUM_ARGS()); RETURN_THROWS(); } @@ -2605,11 +2489,6 @@ PHP_FUNCTION(pg_lo_import) link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "P|z", &file_in, &oid) == SUCCESS) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { WRONG_PARAM_COUNT; } @@ -2694,28 +2573,8 @@ PHP_FUNCTION(pg_lo_export) link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "lP", &oid_long, &file_out) == SUCCESS) { - if (oid_long <= (zend_long)InvalidOid) { - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - oid = (Oid)oid_long; - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } - else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), - "SP", &oid_string, &file_out) == SUCCESS) { - if (!is_valid_oid_string(oid_string, &oid)) { - /* wrong integer format */ - zend_value_error("Invalid OID value passed"); - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - zend_argument_count_error("Requires 2 or 3 arguments, %d given", ZEND_NUM_ARGS()); + zend_argument_count_error("Requires 3 arguments, %d given", ZEND_NUM_ARGS()); RETURN_THROWS(); } @@ -2834,19 +2693,11 @@ PHP_FUNCTION(pg_set_error_verbosity) PGconn *pgsql; pgsql_link_handle *link; - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &verbosity) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &pgsql_link, pgsql_link_ce, &verbosity) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &pgsql_link, pgsql_link_ce, &verbosity) == FAILURE) { + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -2892,20 +2743,18 @@ PHP_FUNCTION(pg_set_client_encoding) PGconn *pgsql; pgsql_link_handle *link; - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &encoding, &encoding_len) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &encoding, &encoding_len) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &encoding, &encoding_len) == FAILURE) { + RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; RETURN_LONG(PQsetClientEncoding(pgsql, encoding)); @@ -2919,18 +2768,18 @@ PHP_FUNCTION(pg_client_encoding) PGconn *pgsql; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &pgsql_link, pgsql_link_ce) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &pgsql_link, pgsql_link_ce) == FAILURE) { RETURN_THROWS(); } - if (pgsql_link == NULL) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; /* Just do the same as found in PostgreSQL sources... */ @@ -2947,18 +2796,18 @@ PHP_FUNCTION(pg_end_copy) int result = 0; pgsql_link_handle *link; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &pgsql_link, pgsql_link_ce) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O!", &pgsql_link, pgsql_link_ce) == FAILURE) { RETURN_THROWS(); } - if (pgsql_link == NULL) { - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; result = PQendcopy(pgsql); @@ -2981,20 +2830,18 @@ PHP_FUNCTION(pg_put_line) pgsql_link_handle *link; int result = 0; - if (ZEND_NUM_ARGS() == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &query, &query_len) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &query, &query_len) == FAILURE) { + RETURN_THROWS(); + } + + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; result = PQputline(pgsql, query); @@ -3028,6 +2875,11 @@ PHP_FUNCTION(pg_copy_to) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3124,6 +2976,11 @@ PHP_FUNCTION(pg_copy_from) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3223,7 +3080,7 @@ PHP_FUNCTION(pg_escape_string) if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &from) == FAILURE) { RETURN_THROWS(); } - link = FETCH_DEFAULT_LINK(); + link = NULL; break; default: if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) { @@ -3263,7 +3120,7 @@ PHP_FUNCTION(pg_escape_bytea) if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &from) == FAILURE) { RETURN_THROWS(); } - link = FETCH_DEFAULT_LINK(); + link = NULL; break; default: if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) { @@ -3274,6 +3131,7 @@ PHP_FUNCTION(pg_escape_bytea) break; } + if (link) { pgsql = link->conn; to = (char *)PQescapeByteaConn(pgsql, (unsigned char *)ZSTR_VAL(from), ZSTR_LEN(from), &to_len); @@ -3314,24 +3172,18 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l char *tmp; pgsql_link_handle *link; - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &from) == FAILURE) { - RETURN_THROWS(); - } - link = FETCH_DEFAULT_LINK(); - CHECK_DEFAULT_LINK(link); - break; + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) { + RETURN_THROWS(); + } - default: - if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &pgsql_link, pgsql_link_ce, &from) == FAILURE) { - RETURN_THROWS(); - } - link = Z_PGSQL_LINK_P(pgsql_link); - CHECK_PGSQL_LINK(link); - break; + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); } + link = Z_PGSQL_LINK_P(pgsql_link); + CHECK_PGSQL_LINK(link); + pgsql = link->conn; if (escape_literal) { @@ -3438,6 +3290,11 @@ PHP_FUNCTION(pg_connection_status) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3458,6 +3315,11 @@ PHP_FUNCTION(pg_transaction_status) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3478,6 +3340,11 @@ PHP_FUNCTION(pg_connection_reset) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3524,6 +3391,11 @@ static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS, int entry_type) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3602,6 +3474,11 @@ PHP_FUNCTION(pg_send_query) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3674,6 +3551,11 @@ PHP_FUNCTION(pg_send_query_params) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3768,6 +3650,11 @@ PHP_FUNCTION(pg_send_prepare) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3841,6 +3728,11 @@ PHP_FUNCTION(pg_send_execute) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3934,6 +3826,11 @@ PHP_FUNCTION(pg_get_result) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -3995,6 +3892,11 @@ PHP_FUNCTION(pg_get_notify) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -4042,6 +3944,11 @@ PHP_FUNCTION(pg_get_pid) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -4123,6 +4030,11 @@ PHP_FUNCTION(pg_socket) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -4149,6 +4061,11 @@ PHP_FUNCTION(pg_consume_input) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -4170,6 +4087,11 @@ PHP_FUNCTION(pg_flush) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -4322,6 +4244,11 @@ PHP_FUNCTION(pg_meta_data) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + link = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(link); pgsql = link->conn; @@ -5171,6 +5098,11 @@ PHP_FUNCTION(pg_convert) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + if (ZSTR_LEN(table_name) == 0) { zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); @@ -5382,6 +5314,11 @@ PHP_FUNCTION(pg_insert) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + if (ZSTR_LEN(table) == 0) { zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); @@ -5601,6 +5538,11 @@ PHP_FUNCTION(pg_update) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + if (ZSTR_LEN(table) == 0) { zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); @@ -5698,6 +5640,11 @@ PHP_FUNCTION(pg_delete) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + if (ZSTR_LEN(table) == 0) { zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); @@ -5843,6 +5790,11 @@ PHP_FUNCTION(pg_select) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + if (ZSTR_LEN(table) == 0) { zend_argument_value_error(2, "cannot be empty"); RETURN_THROWS(); @@ -5888,6 +5840,11 @@ PHP_FUNCTION(pg_enter_pipeline_mode) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + pgsql_handle = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(pgsql_handle); @@ -5903,6 +5860,11 @@ PHP_FUNCTION(pg_exit_pipeline_mode) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + pgsql_handle = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(pgsql_handle); @@ -5918,6 +5880,11 @@ PHP_FUNCTION(pg_pipeline_sync) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + pgsql_handle = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(pgsql_handle); @@ -5933,6 +5900,11 @@ PHP_FUNCTION(pg_pipeline_status) RETURN_THROWS(); } + if (!pgsql_link) { + zend_argument_value_error(1, "must provide a PgSql\\Connection value"); + RETURN_THROWS(); + } + pgsql_handle = Z_PGSQL_LINK_P(pgsql_link); CHECK_PGSQL_LINK(pgsql_handle); diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index 7ce709d17e2d8..8529e58eec5f1 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -489,76 +489,76 @@ function pg_pconnect(string $connection_string, int $flags = 0): PgSql\Connectio function pg_connect_poll(PgSql\Connection $connection): int {} - function pg_close(?PgSql\Connection $connection = null): true {} + function pg_close(PgSql\Connection $connection): true {} /** @refcount 1 */ - function pg_dbname(?PgSql\Connection $connection = null): string {} + function pg_dbname(PgSql\Connection $connection): string {} - function pg_last_error(?PgSql\Connection $connection = null): string {} + function pg_last_error(PgSql\Connection $connection): string {} /** * @alias pg_last_error * @deprecated */ - function pg_errormessage(?PgSql\Connection $connection = null): string {} + function pg_errormessage(PgSql\Connection $connection): string {} /** @refcount 1 */ - function pg_options(?PgSql\Connection $connection = null): string {} + function pg_options(PgSql\Connection $connection): string {} /** @refcount 1 */ - function pg_port(?PgSql\Connection $connection = null): string {} + function pg_port(PgSql\Connection $connection): string {} /** @refcount 1 */ - function pg_tty(?PgSql\Connection $connection = null): string {} + function pg_tty(PgSql\Connection $connection): string {} /** @refcount 1 */ - function pg_host(?PgSql\Connection $connection = null): string {} + function pg_host(PgSql\Connection $connection): string {} /** * @return array * @refcount 1 */ - function pg_version(?PgSql\Connection $connection = null): array {} + function pg_version(PgSql\Connection $connection): array {} /** * @param PgSql\Connection|string $connection * @refcount 1 */ - function pg_parameter_status($connection, string $name = UNKNOWN): string|false {} + function pg_parameter_status($connection, string $name): string|false {} - function pg_ping(?PgSql\Connection $connection = null): bool {} + function pg_ping(PgSql\Connection $connection): bool {} /** * @param PgSql\Connection|string $connection * @refcount 1 */ - function pg_query($connection, string $query = UNKNOWN): PgSql\Result|false {} + function pg_query($connection, string $query): PgSql\Result|false {} /** * @param PgSql\Connection|string $connection * @alias pg_query */ - function pg_exec($connection, string $query = UNKNOWN): PgSql\Result|false {} + function pg_exec($connection, string $query): PgSql\Result|false {} /** * @param PgSql\Connection|string $connection * @param string|array $query * @refcount 1 */ - function pg_query_params($connection, $query, array $params = UNKNOWN): PgSql\Result|false {} + function pg_query_params($connection, $query, array $params): PgSql\Result|false {} /** * @param PgSql\Connection|string $connection * @refcount 1 */ - function pg_prepare($connection, string $statement_name, string $query = UNKNOWN): PgSql\Result|false {} + function pg_prepare($connection, string $statement_name, string $query): PgSql\Result|false {} /** * @param PgSql\Connection|string $connection * @param string|array $statement_name * @refcount 1 */ - function pg_execute($connection, $statement_name, array $params = UNKNOWN): PgSql\Result|false {} + function pg_execute($connection, $statement_name, array $params): PgSql\Result|false {} function pg_num_rows(PgSql\Result $result): int {} @@ -707,9 +707,9 @@ function pg_last_oid(PgSql\Result $result): string|int|false {} */ function pg_getlastoid(PgSql\Result $result): string|int|false {} - function pg_trace(string $filename, string $mode = "w", ?PgSql\Connection $connection = null, int $trace_mode = 0): bool {} + function pg_trace(string $filename, string $mode = "w", PgSql\Connection $connection, int $trace_mode = 0): bool {} - function pg_untrace(?PgSql\Connection $connection = null): true {} + function pg_untrace(PgSql\Connection $connection): true {} /** * @param PgSql\Connection $connection @@ -840,15 +840,15 @@ function pg_set_client_encoding($connection, string $encoding = UNKNOWN): int {} */ function pg_setclientencoding($connection, string $encoding = UNKNOWN): int {} - function pg_client_encoding(?PgSql\Connection $connection = null): string {} + function pg_client_encoding(PgSql\Connection $connection): string {} /** * @alias pg_client_encoding * @deprecated */ - function pg_clientencoding(?PgSql\Connection $connection = null): string {} + function pg_clientencoding(PgSql\Connection $connection): string {} - function pg_end_copy(?PgSql\Connection $connection = null): bool {} + function pg_end_copy(PgSql\Connection $connection): bool {} /** @param PgSql\Connection|string $connection */ function pg_put_line($connection, string $query = UNKNOWN): bool {} diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index 6f035f19246cf..84ad4ebc30333 100644 --- a/ext/pgsql/pgsql_arginfo.h +++ b/ext/pgsql/pgsql_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0d6ef9904082180bf9205d61c2f45c0752be8f7b */ + * Stub hash: 9a986534dbdb29a9fc2ff5a2a4368cfb6d6d041f */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) @@ -12,12 +12,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_connect_poll, 0, 1, IS_LONG, ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_close, 0, 0, IS_TRUE, 0) - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null") +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_close, 0, 1, IS_TRUE, 0) + ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_dbname, 0, 0, IS_STRING, 0) - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null") +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_dbname, 0, 1, IS_STRING, 0) + ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() #define arginfo_pg_last_error arginfo_pg_dbname @@ -32,39 +32,39 @@ ZEND_END_ARG_INFO() #define arginfo_pg_host arginfo_pg_dbname -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_version, 0, 0, IS_ARRAY, 0) - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null") +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_version, 0, 1, IS_ARRAY, 0) + ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_parameter_status, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_parameter_status, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_INFO(0, connection) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_ping, 0, 0, _IS_BOOL, 0) - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null") +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_ping, 0, 1, _IS_BOOL, 0) + ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_query, 0, 1, PgSql\\Result, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_query, 0, 2, PgSql\\Result, MAY_BE_FALSE) ZEND_ARG_INFO(0, connection) ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_pg_exec arginfo_pg_query -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_query_params, 0, 2, PgSql\\Result, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_query_params, 0, 3, PgSql\\Result, MAY_BE_FALSE) ZEND_ARG_INFO(0, connection) ZEND_ARG_INFO(0, query) ZEND_ARG_TYPE_INFO(0, params, IS_ARRAY, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_prepare, 0, 2, PgSql\\Result, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_prepare, 0, 3, PgSql\\Result, MAY_BE_FALSE) ZEND_ARG_INFO(0, connection) ZEND_ARG_TYPE_INFO(0, statement_name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_execute, 0, 2, PgSql\\Result, MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_execute, 0, 3, PgSql\\Result, MAY_BE_FALSE) ZEND_ARG_INFO(0, connection) ZEND_ARG_INFO(0, statement_name) ZEND_ARG_TYPE_INFO(0, params, IS_ARRAY, 0) @@ -196,10 +196,10 @@ ZEND_END_ARG_INFO() #define arginfo_pg_getlastoid arginfo_pg_last_oid -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_trace, 0, 1, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_trace, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"w\"") - ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null") + ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, trace_mode, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -352,13 +352,11 @@ ZEND_END_ARG_INFO() #define arginfo_pg_transaction_status arginfo_pg_connect_poll -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_connection_reset, 0, 1, _IS_BOOL, 0) - ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) -ZEND_END_ARG_INFO() +#define arginfo_pg_connection_reset arginfo_pg_ping -#define arginfo_pg_cancel_query arginfo_pg_connection_reset +#define arginfo_pg_cancel_query arginfo_pg_ping -#define arginfo_pg_connection_busy arginfo_pg_connection_reset +#define arginfo_pg_connection_busy arginfo_pg_ping ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_send_query, 0, 2, MAY_BE_LONG|MAY_BE_BOOL) ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) @@ -403,7 +401,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_socket, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) ZEND_END_ARG_INFO() -#define arginfo_pg_consume_input arginfo_pg_connection_reset +#define arginfo_pg_consume_input arginfo_pg_ping ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_flush, 0, 1, MAY_BE_LONG|MAY_BE_BOOL) ZEND_ARG_OBJ_INFO(0, connection, PgSql\\Connection, 0) diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 5286ccec636b4..4004aaf1dec7a 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -187,7 +187,6 @@ ZEND_BEGIN_MODULE_GLOBALS(pgsql) zend_long allow_persistent; zend_long auto_reset_persistent; int ignore_notices,log_notices; - zend_object *default_link; /* default link when connection is omitted */ HashTable field_oids; HashTable table_oids; HashTable connections; diff --git a/ext/pgsql/tests/05large_object.phpt b/ext/pgsql/tests/05large_object.phpt index f4488ca5aa522..d2db1029faacf 100644 --- a/ext/pgsql/tests/05large_object.phpt +++ b/ext/pgsql/tests/05large_object.phpt @@ -52,13 +52,6 @@ pg_exec ($db, "begin"); pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error 1\n"); pg_exec ($db, "commit"); -// more pg_lo_unlink() tests -echo "Test without connection\n"; -pg_exec ($db, "begin"); -$oid = pg_lo_create ($db) or print("pg_lo_create() error\n"); -pg_lo_unlink($oid) or print("pg_lo_unlink() error 2\n"); -pg_exec ($db, "commit"); - echo "Test with string oid value\n"; pg_exec ($db, "begin"); $oid = pg_lo_create ($db) or print("pg_lo_create() error\n"); @@ -80,21 +73,11 @@ if (!file_exists($path . 'php.gif.exported')) { pg_query($db, 'commit'); /* invalid OID values */ -try { - pg_lo_create(-15); -} catch (\ValueError $e) { - echo $e->getMessage(), \PHP_EOL; -} try { pg_lo_create($db, -15); } catch (\ValueError $e) { echo $e->getMessage(), \PHP_EOL; } -try { - pg_lo_create('giberrish'); -} catch (\ValueError $e) { - echo $e->getMessage(), \PHP_EOL; -} try { pg_lo_create($db, 'giberrish'); } catch (\ValueError $e) { @@ -107,29 +90,20 @@ echo "OK"; create/write/close LO open/read/tell/seek/close LO string(5) "large" -int(5) +int(%d) bool(true) string(10) "bject data" -int(17) +int(%d) bool(true) string(17) "large object data" bool(true) string(4) "data" open/read_all/close LO large object data -int(17) +int(%d) unlink LO -Test without connection - -Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Test with string oid value import/export LO - -Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -Invalid OID value passed -Invalid OID value passed - -Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed Invalid OID value passed OK diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt index 64bbe5885fc98..a4f2063dd8a4a 100644 --- a/ext/pgsql/tests/08escape.phpt +++ b/ext/pgsql/tests/08escape.phpt @@ -99,10 +99,7 @@ else { ?> --EXPECTF-- -Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d pg_escape_string() is Ok - -Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d pg_escape_bytea() is Ok pg_escape_bytea() actually works with database pg_escape_literal() is Ok diff --git a/ext/pgsql/tests/18pg_escape_bytea_before.phpt b/ext/pgsql/tests/18pg_escape_bytea_before.phpt index c55fdf3ba4d66..1b84980341991 100644 --- a/ext/pgsql/tests/18pg_escape_bytea_before.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea_before.phpt @@ -29,5 +29,4 @@ else { } ?> --EXPECTF-- -Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d OK diff --git a/ext/pgsql/tests/27large_object_oid.phpt b/ext/pgsql/tests/27large_object_oid.phpt index 4581d18a88080..0224cc0fe19bc 100644 --- a/ext/pgsql/tests/27large_object_oid.phpt +++ b/ext/pgsql/tests/27large_object_oid.phpt @@ -32,26 +32,9 @@ if ($oid != 21001) echo ("pg_lo_create() wrong id\n"); pg_lo_unlink ($db, $oid); pg_exec ($db, "commit"); -echo "create LO using default connection\n"; -pg_exec ("begin"); -$oid = pg_lo_create (21002); -if (!$oid) echo ("pg_lo_create() error\n"); -if ($oid != 21002) echo ("pg_lo_create() wrong id\n"); -pg_lo_unlink ($oid); -pg_exec ("commit"); - echo "OK"; ?> --EXPECTF-- create LO from int create LO from string -create LO using default connection - -Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d OK diff --git a/ext/pgsql/tests/28large_object_import_oid.phpt b/ext/pgsql/tests/28large_object_import_oid.phpt index 13a0918d84879..2a63e28fde8b7 100644 --- a/ext/pgsql/tests/28large_object_import_oid.phpt +++ b/ext/pgsql/tests/28large_object_import_oid.phpt @@ -32,40 +32,16 @@ if ($oid != 21004) echo ("pg_lo_import() wrong id\n"); pg_lo_unlink ($db, $oid); pg_exec($db, 'commit'); -echo "import LO using default connection\n"; -pg_exec('begin'); -$oid = pg_lo_import($db, __FILE__, 21005); -if (!$oid) echo ("pg_lo_import() error\n"); -if ($oid != 21005) echo ("pg_lo_import() wrong id\n"); -pg_lo_unlink ($oid); -pg_exec('commit'); - -/* Invalide OID */ -try { - pg_lo_import(__FILE__, -15); -} catch (\ValueError $e) { - echo $e->getMessage(), \PHP_EOL; -} try { pg_lo_import($db, __FILE__, -15); } catch (\ValueError $e) { echo $e->getMessage(), \PHP_EOL; } -try { - pg_lo_import(__FILE__, 'giberrish'); -} catch (\ValueError $e) { - echo $e->getMessage(), \PHP_EOL; -} try { pg_lo_import($db, __FILE__, 'giberrish'); } catch (\ValueError $e) { echo $e->getMessage(), \PHP_EOL; } -try { - pg_lo_import(__FILE__, true); -} catch (\TypeError $e) { - echo $e->getMessage(), \PHP_EOL; -} try { pg_lo_import($db, __FILE__, []); } catch (\TypeError $e) { @@ -87,24 +63,8 @@ echo "OK"; --EXPECTF-- import LO from int import LO from string -import LO using default connection - -Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -Invalid OID value passed Invalid OID value passed - -Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d Invalid OID value passed -Invalid OID value passed - -Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -OID value must be of type string|int, true given OID value must be of type string|int, array given OID value must be of type string|int, stdClass given OID value must be of type string|int, PgSql\Connection given diff --git a/ext/pgsql/tests/bug72197.phpt b/ext/pgsql/tests/bug72197.phpt index 04825c83045a3..598e7699786e4 100644 --- a/ext/pgsql/tests/bug72197.phpt +++ b/ext/pgsql/tests/bug72197.phpt @@ -12,7 +12,7 @@ $var2="12"; try { pg_lo_create($var1, $var2); } catch (TypeError $e) { - echo $e->getMessage(), "\n"; + echo $e->getMessage() . PHP_EOL; } /* This should work correctly. */ @@ -24,17 +24,17 @@ pg_query($conn, "BEGIN"); $oid = pg_lo_create($conn); var_dump($oid); -/* Check with default link */ -$oid = pg_lo_create(); -var_dump($oid); +try { + pg_lo_create(); +} catch (ArgumentCountError $e) { + echo $e->getMessage() . PHP_EOL; +} /* don't commit */ pg_query($conn, "ROLLBACK"); pg_close($conn); ?> --EXPECTF-- -pg_lo_create(): Argument #1 ($connection) must be of type PgSql\Connection when the connection is provided%w -int(%d) - -Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d +pg_lo_create(): Argument #1 ($connection) must be of type PgSql\Connection when the connection is provided int(%d) +pg_lo_create() expects at least 1 argument, 0 given diff --git a/ext/pgsql/tests/bug75419.phpt b/ext/pgsql/tests/bug75419.phpt index 6c1b2bd62278c..2923538ca1c03 100644 --- a/ext/pgsql/tests/bug75419.phpt +++ b/ext/pgsql/tests/bug75419.phpt @@ -11,8 +11,11 @@ include('config.inc'); $db1 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW); $db2 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW); pg_close($db1); -var_dump(pg_ping()); +try { + pg_ping(); +} catch (Error $e) { + echo $e->getMessage() . PHP_EOL; +} ?> --EXPECTF-- -Deprecated: pg_ping(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -bool(true) +pg_ping() expects exactly 1 argument, 0 given diff --git a/ext/pgsql/tests/close_default_link.phpt b/ext/pgsql/tests/close_default_link.phpt index db9851cebebc5..14c4f7c0a1b5c 100644 --- a/ext/pgsql/tests/close_default_link.phpt +++ b/ext/pgsql/tests/close_default_link.phpt @@ -11,8 +11,11 @@ include('config.inc'); /* Run me under valgrind */ $db1 = pg_connect($conn_str); unset($db1); -var_dump(pg_close()); +try { + pg_close(); +} catch (ArgumentCountError $e) { + echo $e->getMessage() . PHP_EOL; +} ?> --EXPECTF-- -Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -bool(true) +pg_close() expects exactly 1 argument, 0 given diff --git a/ext/pgsql/tests/connect_after_close.phpt b/ext/pgsql/tests/connect_after_close.phpt index 1f450a88e0d13..55767f1bd3739 100644 --- a/ext/pgsql/tests/connect_after_close.phpt +++ b/ext/pgsql/tests/connect_after_close.phpt @@ -11,15 +11,20 @@ include('config.inc'); /* Run me under valgrind */ $db1 = pg_connect($conn_str); unset($db1); -var_dump(pg_close()); +try { + pg_close(); +} catch (ArgumentCountError $e) { + echo $e->getMessage() . PHP_EOL; +} $db2 = pg_connect($conn_str); unset($db2); -var_dump(pg_close()); +try { + pg_close(); +} catch (ArgumentCountError $e) { + echo $e->getMessage() . PHP_EOL; +} ?> --EXPECTF-- -Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -bool(true) - -Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -bool(true) +pg_close() expects exactly 1 argument, 0 given +pg_close() expects exactly 1 argument, 0 given diff --git a/ext/pgsql/tests/deprecated_implicit_default_link.phpt b/ext/pgsql/tests/deprecated_implicit_default_link.phpt deleted file mode 100644 index 7c508e0da9569..0000000000000 --- a/ext/pgsql/tests/deprecated_implicit_default_link.phpt +++ /dev/null @@ -1,144 +0,0 @@ ---TEST-- -PostgreSQL fetching default link automatically is deprecated ---EXTENSIONS-- -pgsql ---SKIPIF-- - ---FILE-- -getMessage(), 'type array')) { - $args[$argNum] = []; - goto retry; - } - var_dump($e->getMessage()); - } catch (\Error $e) { - echo $e->getMessage(); - } -} - -echo "END"; -?> ---EXPECTF-- -Deprecated: pg_set_error_verbosity(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_query_params(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_execute(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_open(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_export(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_dbname(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_last_error(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_options(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_port(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_tty(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_host(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_version(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_parameter_status(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_ping(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_query(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_prepare(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_untrace(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_set_client_encoding(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_client_encoding(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_end_copy(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_put_line(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_escape_literal(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_escape_identifier(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d - -Deprecated: pg_close(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -END diff --git a/ext/pgsql/tests/no_link_open.phpt b/ext/pgsql/tests/no_link_open.phpt index 4a94401f3e6e1..c19e532c12ae5 100644 --- a/ext/pgsql/tests/no_link_open.phpt +++ b/ext/pgsql/tests/no_link_open.phpt @@ -7,11 +7,10 @@ pgsql try { pg_dbname(); -} catch (Error $e) { +} catch (ArgumentCountError $e) { echo $e->getMessage(), "\n"; } ?> --EXPECTF-- -Deprecated: pg_dbname(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d -No PostgreSQL connection opened yet +pg_dbname() expects exactly 1 argument, 0 given