[go: up one dir, main page]

Skip to content
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

ODBC HY010 when binding parameter that is larger than the column definition #9372

Closed
jfowler8708 opened this issue Aug 18, 2022 · 2 comments
Closed

Comments

@jfowler8708
Copy link

Description

The following code:

<?php
$connection = new \PDO("odbc:DRIVER={ODBC Driver 17 for SQL Server};host=<host>", "<username>", "<password>");
$query = "select itm_code from item where itm_number = :itemNumber";
$parameters = [":itemNumber" => "123456"]; // itm_number column defined as varchar(5) parameter is char(6)
$prepared = $connection->prepare($query);
$results = $prepared->execute($parameters);
?>

Resulted in this output:

SQLSTATE[HY010]: Function sequence error: [unixODBC][Driver Manager]Function sequence error (SQLExecute[0] at /build/php8.1-8.1.9/ext/pdo_odbc/odbc_stmt.c:254)

The error only happens when the bound parameter is larger than the column as defined. Does not happen when using literals within the query string. I would expect to just receive 0 results not an error.

PHP Version

PHP 8.1.9

Operating System

Debain 10.11

@cmb69
Copy link
Member
cmb69 commented Aug 19, 2022

Yeah, that is a known issue. We definitely need to fix the error handling. I'm not sure about actually trying to fix this issue, especially since apparently only some drivers have an issue with binding such overlong values.

cmb69 added a commit to cmb69/php-src that referenced this issue Sep 14, 2022
If `SQLPutData()` *fails*, we should not call `SQLParamData()` again,
because that yields the confusing `HY010` (Function sequence error).
Instead we properly handle `SQLPutData()` errors.

For the given case (paramter length > column length), some drivers let
`SQLPutData()` fail, while others do not.  Either behavior seems to
conform to the ODBC specification.  Anyhow, we do not want to silently
truncate the given parameter, since that would break the behavior for
drivers which do not fail, but still don't simply truncate the given
parameter.  So it is finally up to userland to avoid passing overlong
parameters – with this patch they at least get useful information about
the actual issue.
@cmb69
Copy link
Member
cmb69 commented Sep 14, 2022

I'm not sure about actually trying to fix this issue, especially since apparently only some drivers have an issue with binding such overlong values.

After some further investigation, I don't think that we can silently truncate overlong parameters, since this would break the behavior for drivers not reporting failure on SQLPutData(), because they now might yield different results; e.g. the MySQL ODBC driver would have an empty result for the given script (without any reported error), but could have a non-empty result if we used "12345" as parameter. As such, we're stuck with fixing the error handling.

@cmb69 cmb69 linked a pull request Sep 14, 2022 that will close this issue
cmb69 added a commit to cmb69/php-src that referenced this issue Oct 18, 2022
If `SQLPutData()` *fails*, we should not call `SQLParamData()` again,
because that yields the confusing `HY010` (Function sequence error).
Instead we properly handle `SQLPutData()` errors.

For the given case (paramter length > column length), some drivers let
`SQLPutData()` fail, while others do not.  Either behavior seems to
conform to the ODBC specification.  Anyhow, we do not want to silently
truncate the given parameter, since that would break the behavior for
drivers which do not fail, but still don't simply truncate the given
parameter.  So it is finally up to userland to avoid passing overlong
parameters – with this patch they at least get useful information about
the actual issue.
@cmb69 cmb69 closed this as completed in f5aaa8f Oct 19, 2022
cmb69 added a commit that referenced this issue Oct 19, 2022
* PHP-8.2:
  Fix GH-9372: HY010 when binding overlong parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants