From 9b50fd2626277296b4ad47a508fbc9015eb01d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Thu, 17 Sep 2020 19:35:40 +0200 Subject: Fix UNKNOWN default values in ext/odbc Closes GH-6154 --- ext/odbc/odbc.stub.php | 24 +++++++-------- ext/odbc/odbc_arginfo.h | 38 +++++++++++------------- ext/odbc/php_odbc.c | 57 +++++++++++++----------------------- ext/odbc/tests/odbc_columns_001.phpt | 11 ++++++- ext/odbc/tests/odbc_tables_001.phpt | 12 ++++++-- 5 files changed, 69 insertions(+), 73 deletions(-) (limited to 'ext/odbc') diff --git a/ext/odbc/odbc.stub.php b/ext/odbc/odbc.stub.php index 36d8ad6dc7..28d3d28200 100644 --- a/ext/odbc/odbc.stub.php +++ b/ext/odbc/odbc.stub.php @@ -17,7 +17,7 @@ function odbc_longreadlen($result_id, int $length): bool {} function odbc_prepare($connection_id, string $query) {} /** @param resource $result_id */ -function odbc_execute($result_id, array $parameters_array = UNKNOWN): bool {} +function odbc_execute($result_id, array $parameters_array = []): bool {} /** @param resource $result_id */ function odbc_cursor($result_id): string|false {} @@ -31,14 +31,14 @@ function odbc_data_source($connection_id, int $fetch_type): array|false {} * @param resource $connection_id * @return resource|false */ -function odbc_exec($connection_id, string $query, int $flags = UNKNOWN) {} +function odbc_exec($connection_id, string $query) {} /** * @param resource $connection_id * @return resource|false * @alias odbc_exec */ -function odbc_do($connection_id, string $query, int $flags = UNKNOWN) {} +function odbc_do($connection_id, string $query) {} #ifdef PHP_ODBC_HAVE_FETCH_HASH /** @param resource $result */ @@ -55,7 +55,7 @@ function odbc_fetch_array($result, int $rownumber = -1): array|false {} function odbc_fetch_into($result_id, &$result_array, int $rownumber = 0): int|false {} /** @param resource $result_id */ -function odbc_fetch_row($result_id, int $row_number = UNKNOWN): bool {} +function odbc_fetch_row($result_id, ?int $row_number = null): bool {} /** @param resource $result_id */ function odbc_result($result_id, string|int $field): string|bool|null {} @@ -116,11 +116,11 @@ function odbc_commit($connection_id): bool {} /** @param resource $connection_id */ function odbc_rollback($connection_id): bool {} -/** @param resource $connection_id */ -function odbc_error($connection_id = UNKNOWN): string {} +/** @param resource|null $connection_id */ +function odbc_error($connection_id = null): string {} -/** @param resource $connection_id */ -function odbc_errormsg($connection_id = UNKNOWN): string {} +/** @param resource|null $connection_id */ +function odbc_errormsg($connection_id = null): string {} /** @param resource $conn_id */ function odbc_setoption($conn_id, int $which, int $option, int $value): bool {} @@ -129,13 +129,13 @@ function odbc_setoption($conn_id, int $which, int $option, int $value): bool {} * @param resource $connection_id * @return resource|false */ -function odbc_tables($connection_id, ?string $qualfier = null, string $owner = UNKNOWN, string $name = UNKNOWN, string $table_types = UNKNOWN) {} +function odbc_tables($connection_id, ?string $qualfier = null, ?string $owner = null, ?string $name = null, ?string $table_types = null) {} /** * @param resource $connection_id * @return resource|false */ -function odbc_columns($connection_id, ?string $qualifier = null, string $owner = UNKNOWN, string $table_name = UNKNOWN, string $column_name = UNKNOWN) {} +function odbc_columns($connection_id, ?string $qualifier = null, ?string $owner = null, ?string $table_name = null, ?string $column_name = null) {} /** * @param resource $connection_id @@ -154,13 +154,13 @@ function odbc_primarykeys($connection_id, ?string $qualifier, string $owner, str * @param resource $connection_id * @return resource|false */ -function odbc_procedurecolumns($connection_id, ?string $qualifier = null, string $owner = UNKNOWN, string $proc = UNKNOWN, string $column = UNKNOWN) {} +function odbc_procedurecolumns($connection_id, ?string $qualifier = null, ?string $owner = null, ?string $proc = null, ?string $column = null) {} /** * @param resource $connection_id * @return resource|false */ -function odbc_procedures($connection_id, ?string $qualifier = null, string $owner = UNKNOWN, string $name = UNKNOWN) {} +function odbc_procedures($connection_id, ?string $qualifier = null, ?string $owner = null, ?string $name = null) {} /** * @param resource $connection_id diff --git a/ext/odbc/odbc_arginfo.h b/ext/odbc/odbc_arginfo.h index 738bd44886..ad410d609c 100644 --- a/ext/odbc/odbc_arginfo.h +++ b/ext/odbc/odbc_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b533372de4f1110216b2545121d7851022980650 */ + * Stub hash: 9c4eb9f1131356ac8c026b7b57c81f3b43100e1b */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_close_all, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -21,7 +21,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_execute, 0, 1, _IS_BOOL, 0) ZEND_ARG_INFO(0, result_id) - ZEND_ARG_TYPE_INFO(0, parameters_array, IS_ARRAY, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, parameters_array, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_cursor, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) @@ -35,13 +35,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_data_source, 0, 2, MAY_BE_A ZEND_END_ARG_INFO() #endif -ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_exec, 0, 0, 2) - ZEND_ARG_INFO(0, connection_id) - ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) -ZEND_END_ARG_INFO() +#define arginfo_odbc_exec arginfo_odbc_prepare -#define arginfo_odbc_do arginfo_odbc_exec +#define arginfo_odbc_do arginfo_odbc_prepare #if defined(PHP_ODBC_HAVE_FETCH_HASH) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_odbc_fetch_object, 0, 1, stdClass, MAY_BE_FALSE) @@ -65,7 +61,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_fetch_row, 0, 1, _IS_BOOL, 0) ZEND_ARG_INFO(0, result_id) - ZEND_ARG_TYPE_INFO(0, row_number, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, row_number, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_result, 0, 2, MAY_BE_STRING|MAY_BE_BOOL|MAY_BE_NULL) @@ -140,7 +136,7 @@ ZEND_END_ARG_INFO() #define arginfo_odbc_rollback arginfo_odbc_commit ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_error, 0, 0, IS_STRING, 0) - ZEND_ARG_INFO(0, connection_id) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, connection_id, "null") ZEND_END_ARG_INFO() #define arginfo_odbc_errormsg arginfo_odbc_error @@ -155,17 +151,17 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_tables, 0, 0, 1) ZEND_ARG_INFO(0, connection_id) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, qualfier, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO(0, owner, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, table_types, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owner, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, table_types, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_columns, 0, 0, 1) ZEND_ARG_INFO(0, connection_id) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, qualifier, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO(0, owner, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, table_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, column_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owner, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, table_name, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, column_name, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_gettypeinfo, 0, 0, 1) @@ -184,9 +180,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_procedurecolumns, 0, 0, 1) ZEND_ARG_INFO(0, connection_id) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, qualifier, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO(0, owner, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, proc, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, column, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owner, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, proc, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, column, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif @@ -194,8 +190,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_odbc_procedures, 0, 0, 1) ZEND_ARG_INFO(0, connection_id) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, qualifier, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO(0, owner, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, owner, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 0cfa52be44..8dc9c75844 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -964,7 +964,7 @@ PHP_FUNCTION(odbc_prepare) PHP_FUNCTION(odbc_execute) { zval *pv_res, *tmp; - HashTable *pv_param_ht; + HashTable *pv_param_ht = (HashTable *) &zend_empty_array; typedef struct params_t { SQLLEN vallen; int fp; @@ -974,10 +974,10 @@ PHP_FUNCTION(odbc_execute) unsigned char otype; SQLSMALLINT ctype; odbc_result *result; - int numArgs = ZEND_NUM_ARGS(), i, ne; + int i, ne; RETCODE rc; - if (zend_parse_parameters(numArgs, "r|h", &pv_res, &pv_param_ht) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|h", &pv_res, &pv_param_ht) == FAILURE) { RETURN_THROWS(); } @@ -985,15 +985,9 @@ PHP_FUNCTION(odbc_execute) RETURN_THROWS(); } - /* XXX check for already bound parameters*/ - if (result->numparams > 0 && numArgs == 1) { - php_error_docref(NULL, E_WARNING, "No parameters to SQL statement given"); - RETURN_FALSE; - } - if (result->numparams > 0) { if ((ne = zend_hash_num_elements(pv_param_ht)) < result->numparams) { - php_error_docref(NULL, E_WARNING,"Not enough parameters (%d should be %d) given", ne, result->numparams); + php_error_docref(NULL, E_WARNING, "Not enough parameters (%d should be %d) given", ne, result->numparams); RETURN_FALSE; } @@ -1294,7 +1288,6 @@ PHP_FUNCTION(odbc_data_source) PHP_FUNCTION(odbc_exec) { zval *pv_conn; - zend_long pv_flags; char *query; size_t query_len; odbc_result *result = NULL; @@ -1304,7 +1297,7 @@ PHP_FUNCTION(odbc_exec) SQLUINTEGER scrollopts; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &pv_conn, &query, &query_len, &pv_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &pv_conn, &query, &query_len) == FAILURE) { RETURN_THROWS(); } @@ -1683,22 +1676,20 @@ PHP_FUNCTION(solid_fetch_prev) /* {{{ Fetch a row */ PHP_FUNCTION(odbc_fetch_row) { - SQLLEN rownum; odbc_result *result; RETCODE rc; zval *pv_res; - zend_long pv_row = 1; + zend_long pv_row; + zend_bool pv_row_is_null = 1; #ifdef HAVE_SQL_EXTENDED_FETCH SQLULEN crow; SQLUSMALLINT RowStatus[1]; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &pv_res, &pv_row) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l!", &pv_res, &pv_row, &pv_row_is_null) == FAILURE) { RETURN_THROWS(); } - rownum = pv_row; - if ((result = (odbc_result *)zend_fetch_resource(Z_RES_P(pv_res), "ODBC result", le_result)) == NULL) { RETURN_THROWS(); } @@ -1710,8 +1701,8 @@ PHP_FUNCTION(odbc_fetch_row) #ifdef HAVE_SQL_EXTENDED_FETCH if (result->fetch_abs) { - if (ZEND_NUM_ARGS() > 1) { - rc = SQLExtendedFetch(result->stmt,SQL_FETCH_ABSOLUTE,rownum,&crow,RowStatus); + if (!pv_row_is_null) { + rc = SQLExtendedFetch(result->stmt,SQL_FETCH_ABSOLUTE,(SQLLEN)pv_row,&crow,RowStatus); } else { rc = SQLExtendedFetch(result->stmt,SQL_FETCH_NEXT,1,&crow,RowStatus); } @@ -1723,8 +1714,8 @@ PHP_FUNCTION(odbc_fetch_row) RETURN_FALSE; } - if (ZEND_NUM_ARGS() > 1) { - result->fetched = rownum; + if (!pv_row_is_null) { + result->fetched = (SQLLEN)pv_row; } else { result->fetched++; } @@ -2645,14 +2636,14 @@ PHP_FUNCTION(odbc_rollback) static void php_odbc_lasterror(INTERNAL_FUNCTION_PARAMETERS, int mode) { odbc_connection *conn; - zval *pv_handle; + zval *pv_handle = NULL; char *ret; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &pv_handle) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &pv_handle) == FAILURE) { RETURN_THROWS(); } - if (ZEND_NUM_ARGS() == 1) { + if (pv_handle) { if (!(conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_handle), "ODBC-Link", le_conn, le_pconn))) { RETURN_THROWS(); } @@ -2757,7 +2748,7 @@ PHP_FUNCTION(odbc_tables) size_t cat_len = 0, schema_len = 0, table_len = 0, type_len = 0; RETCODE rc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!s!", &pv_conn, &cat, &cat_len, &schema, &schema_len, &table, &table_len, &type, &type_len) == FAILURE) { RETURN_THROWS(); } @@ -2782,7 +2773,7 @@ PHP_FUNCTION(odbc_tables) } /* This hack is needed to access table information in Access databases (fmk) */ - if (table && table_len && schema && schema_len == 0) { + if (schema && schema_len == 0 && table && table_len) { schema = NULL; } @@ -2825,7 +2816,7 @@ PHP_FUNCTION(odbc_columns) size_t cat_len = 0, schema_len = 0, table_len = 0, column_len = 0; RETCODE rc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!s!", &pv_conn, &cat, &cat_len, &schema, &schema_len, &table, &table_len, &column, &column_len) == FAILURE) { RETURN_THROWS(); } @@ -3161,11 +3152,7 @@ PHP_FUNCTION(odbc_procedurecolumns) size_t cat_len = 0, schema_len = 0, proc_len = 0, col_len = 0; RETCODE rc; - if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 5) { - WRONG_PARAM_COUNT; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!sss", &pv_conn, &cat, &cat_len, &schema, &schema_len, + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!s!", &pv_conn, &cat, &cat_len, &schema, &schema_len, &proc, &proc_len, &col, &col_len) == FAILURE) { RETURN_THROWS(); } @@ -3230,11 +3217,7 @@ PHP_FUNCTION(odbc_procedures) size_t cat_len = 0, schema_len = 0, proc_len = 0; RETCODE rc; - if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 4) { - WRONG_PARAM_COUNT; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!ss", &pv_conn, &cat, &cat_len, &schema, &schema_len, &proc, &proc_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!s!", &pv_conn, &cat, &cat_len, &schema, &schema_len, &proc, &proc_len) == FAILURE) { RETURN_THROWS(); } diff --git a/ext/odbc/tests/odbc_columns_001.phpt b/ext/odbc/tests/odbc_columns_001.phpt index fbbc3e2e03..374a9bf6ea 100644 --- a/ext/odbc/tests/odbc_columns_001.phpt +++ b/ext/odbc/tests/odbc_columns_001.phpt @@ -12,8 +12,13 @@ $conn = odbc_connect($dsn, $user, $pass); var_dump($result = odbc_columns($conn, '', '', '', '')); var_dump(odbc_fetch_row($result)); +var_dump($result = odbc_columns($conn)); +var_dump(odbc_fetch_row($result)); +var_dump(odbc_free_result($result)); + var_dump($result = odbc_columns($conn, NULL, NULL, NULL, NULL)); var_dump(odbc_fetch_row($result)); +var_dump(odbc_free_result($result)); var_dump($result = odbc_columns($conn, 'FOO', 'FOO', 'FOO', 'FOO')); var_dump(odbc_fetch_row($result)); @@ -23,6 +28,10 @@ var_dump(odbc_fetch_row($result)); resource(%d) of type (odbc result) bool(false) resource(%d) of type (odbc result) -bool(false) +bool(true) +bool(true) +resource(%d) of type (odbc result) +bool(true) +bool(true) resource(%d) of type (odbc result) bool(false) diff --git a/ext/odbc/tests/odbc_tables_001.phpt b/ext/odbc/tests/odbc_tables_001.phpt index 6b922f25e6..420c41cda8 100644 --- a/ext/odbc/tests/odbc_tables_001.phpt +++ b/ext/odbc/tests/odbc_tables_001.phpt @@ -12,18 +12,26 @@ $conn = odbc_connect($dsn, $user, $pass); var_dump($result = odbc_tables($conn, '', '', '', '')); var_dump(odbc_fetch_row($result)); +var_dump($result = odbc_tables($conn)); +var_dump(odbc_fetch_row($result)); +var_dump(odbc_free_result($result)); + var_dump($result = odbc_tables($conn, NULL, NULL, NULL, NULL)); var_dump(odbc_fetch_row($result)); +var_dump(odbc_free_result($result)); var_dump($result = odbc_tables($conn, 'FOO', 'FOO', 'FOO', 'FOO')); var_dump(odbc_fetch_row($result)); - ?> --EXPECTF-- resource(%d) of type (odbc result) bool(false) resource(%d) of type (odbc result) -bool(false) +bool(true) +bool(true) +resource(%d) of type (odbc result) +bool(true) +bool(true) resource(%d) of type (odbc result) bool(false) -- cgit v1.2.1