Skip to content

Fix UNKNOWN default values in ext/odbc #6154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ PHP 8.0 UPGRADE NOTES
. Several alias functions have been marked as deprecated.
. oci_internal_debug() and its alias ociinternaldebug() have been removed.

- ODBC:
. The unused flags parameter of odbc_exec() has been removed.

- OpenSSL:
. openssl_x509_read() and openssl_csr_sign() will now return an
OpenSSLCertificate object rather than a resource. Return value checks using
Expand Down
24 changes: 12 additions & 12 deletions ext/odbc/odbc.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it makes sense to drop this unused parameter, but there should be a note about that in UPGRADING.


/**
* @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 */
Expand All @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand All @@ -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
Expand All @@ -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
Expand Down
38 changes: 17 additions & 21 deletions ext/odbc/odbc_arginfo.h
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -184,18 +180,18 @@ 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

#if !defined(HAVE_SOLID) && !defined(HAVE_SOLID_30) && !defined(HAVE_SOLID_35)
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

Expand Down
57 changes: 20 additions & 37 deletions ext/odbc/php_odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -974,26 +974,20 @@ 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();
}

if ((result = (odbc_result *)zend_fetch_resource(Z_RES_P(pv_res), "ODBC result", le_result)) == NULL) {
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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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++;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down
11 changes: 10 additions & 1 deletion ext/odbc/tests/odbc_columns_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
Loading