]> granicus.if.org Git - php/commitdiff
Promote warnings to Errors in PostgreSQL extension
authorGeorge Peter Banyard <girgias@php.net>
Sun, 13 Sep 2020 03:31:01 +0000 (05:31 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Mon, 14 Sep 2020 15:01:35 +0000 (17:01 +0200)
Do some drive by indentation fixes
Also fix pg_select() in regards to the $result_type arg which was missing from ZPP

Closes GH-6129

ext/opcache/Optimizer/zend_func_info.c
ext/pgsql/pgsql.c
ext/pgsql/pgsql.stub.php
ext/pgsql/pgsql_arginfo.h
ext/pgsql/tests/09notice.phpt
ext/pgsql/tests/bug60244.phpt
ext/pgsql/tests/pg_insert_002.phpt
ext/pgsql/tests/pg_select_001.phpt

index 5ee5d394981cb71dc2c3da5a3af2b7fe907c1f38..22a2f3e8f4fbe5c06c2504fb3eef298340693c13 100644 (file)
@@ -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),
index c5ee4ffebc66d2fad336a12949294600dbd9e464..314f28404a615d81ef21f33d11175a131006d385 100644 (file)
@@ -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) {
index 5537b8ff6f83b970fac46c44af3aad4b0c8e6589..3d8ce3a701468644b85dafdac2ca1160a7075b84 100644 (file)
@@ -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 {}
index cfbdc18c2b43b14192aa6452494168ddcd98c8aa..0c9234acdc5c5eb1dcbe13c0c588d870b7a049bf 100644 (file)
@@ -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()
 
 
index 11c80481f6dda69deec34e5a04587d7713ee9134..2b4df446d8f0585e4f338c9dbed14f40f361c1b5 100644 (file)
@@ -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
index 94568b603130519d36abb4a8866466af9e086ee6..4d2f4cbcd773b2715c0731ba0d0222a3ccece607 100644 (file)
@@ -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"
index bb84a00d0dd2cd85b391a3c1376e54fb3890d86a..0aa6395cfa0cf4ea9002b9ab36cc2b5ecc24d9d4 100644 (file)
@@ -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)
index 9bcf130dd8389176cb67b36cce949dcec23613cc..803cf1fbbfc5eedc45ca6e8c3b2ce4a61f653a9d 100644 (file)
@@ -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"
+  }
+}