diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 5ee5d394981cb..22a2f3e8f4fbe 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -727,7 +727,7 @@ static const func_info_t func_infos[] = { F1("pg_result_error", MAY_BE_FALSE | MAY_BE_STRING), F1("pg_result_error_field", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING), F1("pg_get_result", MAY_BE_FALSE | MAY_BE_RESOURCE), - F1("pg_result_status", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING), + F1("pg_result_status", MAY_BE_LONG | MAY_BE_STRING), F1("pg_get_notify", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY), F1("pg_socket", MAY_BE_FALSE | MAY_BE_RESOURCE), F1("pg_meta_data", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY), diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c5ee4ffebc66d..314f28404a615 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1468,8 +1468,8 @@ PHP_FUNCTION(pg_last_notice) RETURN_TRUE; break; default: - php_error_docref(NULL, E_WARNING, - "Invalid option specified (" ZEND_LONG_FMT ")", option); + zend_argument_value_error(2, "must be one of PGSQL_NOTICE_LAST, PGSQL_NOTICE_ALL, or PGSQL_NOTICE_CLEAR"); + RETURN_THROWS(); } RETURN_FALSE; } @@ -1555,7 +1555,12 @@ PHP_FUNCTION(pg_field_table) RETURN_THROWS(); } - if (fnum < 0 || fnum >= PQnfields(pg_result->result)) { + if (fnum < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + + if (fnum >= PQnfields(pg_result->result)) { php_error_docref(NULL, E_WARNING, "Bad field offset specified"); RETURN_FALSE; } @@ -1638,10 +1643,14 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ RETURN_THROWS(); } + if (field < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); + } pgsql_result = pg_result->result; - if (field < 0 || field >= PQnfields(pgsql_result)) { + if (field >= PQnfields(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Bad field offset specified"); RETURN_FALSE; } @@ -1758,7 +1767,11 @@ PHP_FUNCTION(pg_fetch_result) } pg_result->row++; } else { - if (row < 0 || row >= PQntuples(pgsql_result)) { + if (row < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if (row >= PQntuples(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT, row, Z_LVAL_P(result)); RETURN_FALSE; @@ -1772,7 +1785,11 @@ PHP_FUNCTION(pg_fetch_result) RETURN_FALSE; } } else { - if (field_offset < 0 || field_offset >= PQnfields(pgsql_result)) { + if (field_offset < 0) { + zend_argument_value_error(argc, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if (field_offset >= PQnfields(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Bad column offset specified"); RETURN_FALSE; } @@ -1815,13 +1832,13 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ } if (!row_is_null && row < 0) { - php_error_docref(NULL, E_WARNING, "The row parameter must be greater or equal to zero"); - RETURN_FALSE; + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); } if (!(result_type & PGSQL_BOTH)) { - php_error_docref(NULL, E_WARNING, "Invalid result type"); - RETURN_FALSE; + zend_argument_value_error(3, "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH"); + RETURN_THROWS(); } if ((pg_result = (pgsql_result_handle *)zend_fetch_resource(Z_RES_P(result), "PostgreSQL result", le_result)) == NULL) { @@ -1831,7 +1848,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ pgsql_result = pg_result->result; if (!row_is_null) { - if (row < 0 || row >= PQntuples(pgsql_result)) { + if (row >= PQntuples(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT, row, Z_LVAL_P(result)); RETURN_FALSE; @@ -1977,8 +1994,8 @@ PHP_FUNCTION(pg_fetch_all) } if (!(result_type & PGSQL_BOTH)) { - php_error_docref(NULL, E_WARNING, "Invalid result type"); - RETURN_FALSE; + zend_argument_value_error(2, "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH"); + RETURN_THROWS(); } if ((pg_result = (pgsql_result_handle *)zend_fetch_resource(Z_RES_P(result), "PostgreSQL result", le_result)) == NULL) { @@ -2012,10 +2029,15 @@ PHP_FUNCTION(pg_fetch_all_columns) RETURN_THROWS(); } + if (colno < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + pgsql_result = pg_result->result; num_fields = PQnfields(pgsql_result); - if (colno >= (zend_long)num_fields || colno < 0) { + if (colno >= (zend_long)num_fields) { php_error_docref(NULL, E_WARNING, "Invalid column number '" ZEND_LONG_FMT "'", colno); RETURN_FALSE; } @@ -2101,7 +2123,11 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) RETURN_FALSE; } } else { - if (row < 0 || row >= PQntuples(pgsql_result)) { + if (row < 0) { + zend_argument_value_error(2, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if (row >= PQntuples(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT, row, Z_LVAL_P(result)); RETURN_FALSE; @@ -2116,7 +2142,10 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type) RETURN_FALSE; } } else { - if (field_offset < 0 || field_offset >= PQnfields(pgsql_result)) { + if (field_offset < 0) { + zend_argument_value_error(argc, "must be greater than or equal to 0"); + } + if (field_offset >= PQnfields(pgsql_result)) { php_error_docref(NULL, E_WARNING, "Bad column offset specified"); RETURN_FALSE; } @@ -2316,7 +2345,7 @@ PHP_FUNCTION(pg_lo_create) default: php_error_docref(NULL, E_NOTICE, "Invalid OID value passed"); RETURN_FALSE; - } + } if ((pgsql_oid = lo_create(pgsql, wanted_oid)) == InvalidOid) { php_error_docref(NULL, E_WARNING, "Unable to create PostgreSQL large object"); RETURN_FALSE; @@ -2603,13 +2632,13 @@ PHP_FUNCTION(pg_lo_write) } if (argc > 2) { - if (z_len > (zend_long)str_len) { - php_error_docref(NULL, E_WARNING, "Cannot write more than buffer size %zu. Tried to write " ZEND_LONG_FMT, str_len, z_len); - RETURN_FALSE; - } if (z_len < 0) { - php_error_docref(NULL, E_WARNING, "Buffer size must be larger than 0, but " ZEND_LONG_FMT " was specified", z_len); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than or equal to 0"); + RETURN_THROWS(); + } + if (z_len > (zend_long)str_len) { + zend_argument_value_error(3, "must be less than or equal to the length of argument #2 ($buf)"); + RETURN_THROWS(); } len = z_len; } @@ -2711,15 +2740,15 @@ PHP_FUNCTION(pg_lo_import) default: php_error_docref(NULL, E_NOTICE, "Invalid OID value passed"); RETURN_FALSE; - } + } - returned_oid = lo_import_with_oid(pgsql, file_in, wanted_oid); + returned_oid = lo_import_with_oid(pgsql, file_in, wanted_oid); - if (returned_oid == InvalidOid) { - RETURN_FALSE; - } + if (returned_oid == InvalidOid) { + RETURN_FALSE; + } - PGSQL_RETURN_OID(returned_oid); + PGSQL_RETURN_OID(returned_oid); } returned_oid = lo_import(pgsql, file_in); @@ -2817,8 +2846,8 @@ PHP_FUNCTION(pg_lo_seek) RETURN_THROWS(); } if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END) { - php_error_docref(NULL, E_WARNING, "Invalid whence parameter"); - return; + zend_argument_value_error(3, "must be one of PGSQL_SEEK_SET, PGSQL_SEEK_CUR, or PGSQL_SEEK_END"); + RETURN_THROWS(); } if ((pgsql = (pgLofp *)zend_fetch_resource(Z_RES_P(pgsql_id), "PostgreSQL large object", le_lofp)) == NULL) { @@ -4020,10 +4049,9 @@ PHP_FUNCTION(pg_result_status) } else if (result_type == PGSQL_STATUS_STRING) { RETURN_STRING(PQcmdStatus(pgsql_result)); - } - else { - php_error_docref(NULL, E_WARNING, "Optional 2nd parameter should be PGSQL_STATUS_LONG or PGSQL_STATUS_STRING"); - RETURN_FALSE; + } else { + zend_argument_value_error(2, "must be either PGSQL_STATUS_LONG or PGSQL_STATUS_STRING"); + RETURN_THROWS(); } } /* }}} */ @@ -4045,8 +4073,8 @@ PHP_FUNCTION(pg_get_notify) } if (!(result_type & PGSQL_BOTH)) { - php_error_docref(NULL, E_WARNING, "Invalid result type"); - RETURN_FALSE; + zend_argument_value_error(2, "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH"); + RETURN_THROWS(); } PQconsumeInput(pgsql); @@ -4233,6 +4261,7 @@ PHP_FUNCTION(pg_flush) /* }}} */ /* {{{ php_pgsql_meta_data + * table_name must not be empty * TODO: Add meta_data cache for better performance */ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta, zend_bool extended) @@ -4245,10 +4274,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z int i, num_rows; zval elem; - if (!*table_name) { - php_error_docref(NULL, E_WARNING, "The table name must be specified"); - return FAILURE; - } + ZEND_ASSERT(*table_name); src = estrdup(table_name); tmp_name = php_strtok_r(src, ".", &tmp_name2); @@ -4364,6 +4390,12 @@ PHP_FUNCTION(pg_meta_data) RETURN_THROWS(); } + /* php_pgsql_meta_data() asserts that table_name is not empty */ + if (table_name_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); + } + array_init(return_value); if (php_pgsql_meta_data(pgsql, table_name, return_value, extended) == FAILURE) { zend_array_destroy(Z_ARR_P(return_value)); /* destroy array */ @@ -4467,7 +4499,7 @@ static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , size_t regex_len, int icase) { pcre2_code *re; - PCRE2_SIZE err_offset; + PCRE2_SIZE err_offset; int res, errnumber; uint32_t options = PCRE2_NO_AUTO_CAPTURE; size_t i; @@ -4564,14 +4596,13 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con int err = 0, skip_field; php_pgsql_data_type data_type; - assert(pg_link != NULL); - assert(Z_TYPE_P(values) == IS_ARRAY); - assert(Z_TYPE_P(result) == IS_ARRAY); - assert(!(opt & ~PGSQL_CONV_OPTS)); - - if (!table_name) { - return FAILURE; - } + ZEND_ASSERT(pg_link != NULL); + ZEND_ASSERT(Z_TYPE_P(values) == IS_ARRAY); + ZEND_ASSERT(Z_TYPE_P(result) == IS_ARRAY); + ZEND_ASSERT(!(opt & ~PGSQL_CONV_OPTS)); + ZEND_ASSERT(table_name); + /* Table name cannot be empty for php_pgsql_meta_data() */ + ZEND_ASSERT(*table_name); array_init(&meta); /* table_name is escaped by php_pgsql_meta_data */ @@ -5222,13 +5253,16 @@ PHP_FUNCTION(pg_convert) "rsa|l", &pgsql_link, &table_name, &table_name_len, &values, &option) == FAILURE) { RETURN_THROWS(); } - if (option & ~PGSQL_CONV_OPTS) { - php_error_docref(NULL, E_WARNING, "Invalid option is specified"); - RETURN_FALSE; + + if (table_name_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); } - if (!table_name_len) { - php_error_docref(NULL, E_NOTICE, "Table name is invalid"); - RETURN_FALSE; + + if (option & ~PGSQL_CONV_OPTS) { + zend_argument_value_error(4, "must be a valid bit mask of PGSQL_CONV_IGNORE_DEFAULT, " + "PGSQL_CONV_FORCE_NULL, and PGSQL_CONV_IGNORE_NOT_NULL"); + RETURN_THROWS(); } if ((pg_link = (PGconn *)zend_fetch_resource2(Z_RES_P(pgsql_link), "PostgreSQL link", le_link, le_plink)) == NULL) { @@ -5433,9 +5467,16 @@ PHP_FUNCTION(pg_insert) &pgsql_link, &table, &table_len, &values, &option) == FAILURE) { RETURN_THROWS(); } + + if (table_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); + } + if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING|PGSQL_DML_ESCAPE)) { - php_error_docref(NULL, E_WARNING, "Invalid option is specified"); - RETURN_FALSE; + zend_argument_value_error(4, "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, " + "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC, and PGSQL_DML_STRING"); + RETURN_THROWS(); } if ((pg_link = (PGconn *)zend_fetch_resource2(Z_RES_P(pgsql_link), "PostgreSQL link", le_link, le_plink)) == NULL) { @@ -5643,9 +5684,16 @@ PHP_FUNCTION(pg_update) &pgsql_link, &table, &table_len, &values, &ids, &option) == FAILURE) { RETURN_THROWS(); } + + if (table_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); + } + if (option & ~(PGSQL_CONV_OPTS|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING|PGSQL_DML_ESCAPE)) { - php_error_docref(NULL, E_WARNING, "Invalid option is specified"); - RETURN_FALSE; + zend_argument_value_error(5, "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, " + "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC, and PGSQL_DML_STRING"); + RETURN_THROWS(); } if ((pg_link = (PGconn *)zend_fetch_resource2(Z_RES_P(pgsql_link), "PostgreSQL link", le_link, le_plink)) == NULL) { @@ -5733,9 +5781,16 @@ PHP_FUNCTION(pg_delete) &pgsql_link, &table, &table_len, &ids, &option) == FAILURE) { RETURN_THROWS(); } + + if (table_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); + } + if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_STRING|PGSQL_DML_ESCAPE)) { - php_error_docref(NULL, E_WARNING, "Invalid option is specified"); - RETURN_FALSE; + zend_argument_value_error(4, "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, " + "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC, and PGSQL_DML_STRING"); + RETURN_THROWS(); } if ((pg_link = (PGconn *)zend_fetch_resource2(Z_RES_P(pgsql_link), "PostgreSQL link", le_link, le_plink)) == NULL) { @@ -5865,20 +5920,26 @@ PHP_FUNCTION(pg_select) long result_type = PGSQL_ASSOC; PGconn *pg_link; zend_string *sql = NULL; - int argc = ZEND_NUM_ARGS(); - // TODO: result_type is unused by zpp! - if (zend_parse_parameters(argc, "rsa|l", + /* TODO Document result_type param on php.net (apparently it was added in PHP 7.1) */ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa|ll", &pgsql_link, &table, &table_len, &ids, &option, &result_type) == FAILURE) { RETURN_THROWS(); } + + if (table_len == 0) { + zend_argument_value_error(2, "cannot be empty"); + RETURN_THROWS(); + } + if (option & ~(PGSQL_CONV_FORCE_NULL|PGSQL_DML_NO_CONV|PGSQL_DML_EXEC|PGSQL_DML_ASYNC|PGSQL_DML_STRING|PGSQL_DML_ESCAPE)) { - php_error_docref(NULL, E_WARNING, "Invalid option is specified"); - RETURN_FALSE; + zend_argument_value_error(4, "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, " + "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC, and PGSQL_DML_STRING"); + RETURN_THROWS(); } if (!(result_type & PGSQL_BOTH)) { - php_error_docref(NULL, E_WARNING, "Invalid result type"); - RETURN_FALSE; + zend_argument_value_error(5, "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH"); + RETURN_THROWS(); } if ((pg_link = (PGconn *)zend_fetch_resource2(Z_RES_P(pgsql_link), "PostgreSQL link", le_link, le_plink)) == NULL) { diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index 5537b8ff6f83b..3d8ce3a701468 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -449,7 +449,7 @@ function pg_send_execute($connection, string $query, array $params): int|bool {} function pg_get_result($connection) {} /** @param resource $result */ -function pg_result_status($result, int $result_type = PGSQL_STATUS_LONG): string|int|false {} +function pg_result_status($result, int $result_type = PGSQL_STATUS_LONG): string|int {} /** @param resource $result */ function pg_get_notify($result, int $result_type = PGSQL_ASSOC): array|false {} @@ -488,4 +488,4 @@ function pg_update($connection, string $table_name, array $values, array $ids, i function pg_delete($connection, string $table_name, array $ids, int $options = 0): string|bool {} /** @param resource $connection */ -function pg_select($connection, string $table_name, array $ids, int $options = 0): array|string|false {} +function pg_select($connection, string $table_name, array $ids, int $options = 0, int $result_type = PGSQL_ASSOC): array|string|false {} diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index cfbdc18c2b43b..0c9234acdc5c5 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: 38d1c57d8bf23dcd17d4f775cdf4c2df61087331 */ + * Stub hash: 90dd576049fe13617343fe689000b94b20f47655 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_connect, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) @@ -380,7 +380,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_get_result, 0, 0, 1) ZEND_ARG_INFO(0, connection) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_result_status, 0, 1, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_result_status, 0, 1, MAY_BE_STRING|MAY_BE_LONG) ZEND_ARG_INFO(0, result) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_type, IS_LONG, 0, "PGSQL_STATUS_LONG") ZEND_END_ARG_INFO() @@ -437,6 +437,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_select, 0, 3, MAY_BE_ARRAY|MA ZEND_ARG_TYPE_INFO(0, table_name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, ids, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_type, IS_LONG, 0, "PGSQL_ASSOC") ZEND_END_ARG_INFO() diff --git a/ext/pgsql/tests/09notice.phpt b/ext/pgsql/tests/09notice.phpt index 11c80481f6dda..2b4df446d8f05 100644 --- a/ext/pgsql/tests/09notice.phpt +++ b/ext/pgsql/tests/09notice.phpt @@ -42,7 +42,11 @@ var_dump(pg_last_notice($db, PGSQL_NOTICE_LAST)); var_dump(pg_last_notice($db, PGSQL_NOTICE_ALL)); // Invalid option -var_dump(pg_last_notice($db, 99)); +try { + var_dump(pg_last_notice($db, 99)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECTF-- resource(%d) of type (pgsql result) @@ -68,6 +72,4 @@ bool(true) string(0) "" array(0) { } - -Warning: pg_last_notice(): Invalid option specified (99) in %s%e09notice.php on line %d -bool(false) +pg_last_notice(): Argument #2 ($option) must be one of PGSQL_NOTICE_LAST, PGSQL_NOTICE_ALL, or PGSQL_NOTICE_CLEAR diff --git a/ext/pgsql/tests/bug60244.phpt b/ext/pgsql/tests/bug60244.phpt index 94568b6031305..4d2f4cbcd773b 100644 --- a/ext/pgsql/tests/bug60244.phpt +++ b/ext/pgsql/tests/bug60244.phpt @@ -12,10 +12,26 @@ include 'config.inc'; $db = pg_connect($conn_str); $result = pg_query("select 'a' union select 'b'"); -var_dump(pg_fetch_array($result, -1)); -var_dump(pg_fetch_assoc($result, -1)); -var_dump(pg_fetch_object($result, -1)); -var_dump(pg_fetch_row($result, -1)); +try { + var_dump(pg_fetch_array($result, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(pg_fetch_assoc($result, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(pg_fetch_object($result, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(pg_fetch_row($result, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(pg_fetch_array($result, 0)); var_dump(pg_fetch_assoc($result, 0)); @@ -25,18 +41,11 @@ var_dump(pg_fetch_row($result, 0)); pg_close($db); ?> ---EXPECTF-- -Warning: pg_fetch_array(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d -bool(false) - -Warning: pg_fetch_assoc(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d -bool(false) - -Warning: pg_fetch_object(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d -bool(false) - -Warning: pg_fetch_row(): The row parameter must be greater or equal to zero in %sbug60244.php on line %d -bool(false) +--EXPECT-- +pg_fetch_array(): Argument #2 ($row_number) must be greater than or equal to 0 +pg_fetch_assoc(): Argument #2 ($row_number) must be greater than or equal to 0 +pg_fetch_object(): Argument #2 ($row_number) must be greater than or equal to 0 +pg_fetch_row(): Argument #2 ($row_number) must be greater than or equal to 0 array(2) { [0]=> string(1) "a" diff --git a/ext/pgsql/tests/pg_insert_002.phpt b/ext/pgsql/tests/pg_insert_002.phpt index bb84a00d0dd2c..0aa6395cfa0cf 100644 --- a/ext/pgsql/tests/pg_insert_002.phpt +++ b/ext/pgsql/tests/pg_insert_002.phpt @@ -10,13 +10,16 @@ include('config.inc'); $conn = pg_connect($conn_str); foreach (array('', '.', '..') as $table) { - var_dump(pg_insert($conn, $table, array('id' => 1, 'id2' => 1))); + try { + var_dump(pg_insert($conn, $table, array('id' => 1, 'id2' => 1))); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } } ?> Done --EXPECTF-- -Warning: pg_insert(): The table name must be specified in %s on line %d -bool(false) +pg_insert(): Argument #2 ($table_name) cannot be empty Warning: pg_insert(): The table name must be specified in %s on line %d bool(false) diff --git a/ext/pgsql/tests/pg_select_001.phpt b/ext/pgsql/tests/pg_select_001.phpt index 9bcf130dd8389..803cf1fbbfc5e 100644 --- a/ext/pgsql/tests/pg_select_001.phpt +++ b/ext/pgsql/tests/pg_select_001.phpt @@ -31,6 +31,8 @@ var_dump(pg_select($conn, 'phptests.bar', array('id' => 1))); /* Existent column */ var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4))); +/* Use a different result type */ +var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4), 0, PGSQL_NUM)); pg_query('DROP TABLE phptests.foo'); pg_query('DROP TABLE phptests.bar'); @@ -61,3 +63,12 @@ array(1) { string(1) "5" } } +array(1) { + [0]=> + array(2) { + [0]=> + string(1) "4" + [1]=> + string(1) "5" + } +}