-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make ext/odbc default value handling more consistent #13910
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
Make ext/odbc default value handling more consistent #13910
Conversation
@@ -1594,12 +1578,12 @@ PHP_FUNCTION(odbc_fetch_row) | |||
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { | |||
RETURN_FALSE; | |||
} | |||
|
|||
if (!pv_row_is_null) { | |||
#ifdef HAVE_SQL_EXTENDED_FETCH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like an omission. The result of the affected functions already used the same #ifdef
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
When HAVE_SQL_EXTENDED_FETCH is not defined, the $row parameter is always ignored. Previously, some of the functions didn't accept it at all. I think this behavior was not ideal, it would be better to emit a warning or even better, a specific ValueError if the feature is not supported, but the parameter has any value but the default one (null). I can add this error if we can agree on it.
I think you need to throw a value error for invalid numbers. In this case, values less than or equal to 0
have no meaning.
By the way, this is outside the scope of this PR, but it seems that SQLExtendedFetch
is deprecated in ODBC3.
https://learn.microsoft.com/sql/odbc/reference/syntax/sqlextendedfetch-function?view=sql-server-ver16
Related to the comment you made earlier, I wonder how useful the whole EXTENDED_FETCH ifdef mess really is - could we remove it and simplify some stuff? Looking at |
It would be a bit unkind to remove it just because it has few or no users. In particular, since this has no impact on processing speed, I think should leave it in unless have a strong reason not to. |
That's fair, seeing as I care about a minority database (though I don't think many people are using Db2 directly via the ODBC extension). That ifdef cluster does seem to be a bit of a refactoring burden though. |
I see. What does the burden of refactoring involve? I found it a little hard to read as to what was inside the else block, is it something similar to that? |
It was based off of the code review comment left by Máté. |
Yes, this would be the ideal case, but it would break existing code calling these functions by explicitly using the current default values (
Hmm, I'm honestly not sure whether anyone is using those DBs... But I agree with Saki that let's not get rid of those IFDEFs. At least I don't care about it enough ^^ |
Ah, yes, that's certainly true. I agree to do nothing now. |
} | ||
#else | ||
if (!pv_row_is_null && pv_row < 1) { | ||
php_error_docref(NULL, E_WARNING, "Argument #3 ($row) must be greater than or equal to 1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that it's still possible to warn in case of odbc_fetch_row()
because null
is already the default value since PHP 8.0 (9b50fd2#diff-36f2362bf160e8a01f19ba44e282f7a2f69b460d57a5b23d9e71c59af5de8810R1689).
I'm merging this now so that I can then rebase the resource to object PR on top of this. Should you find any problem with this approach I implemented, I'll take care of it in a followup. |
These changes are carved off from https://github.com/php/php-src/pull/12040/files. I noticed that there are some inconsistencies between
odbc_fetch_object()
/odbc_fetch_array()
,odbc_fetch_into()
, as well asodbc_fetch_row()
, specifically in how they handle the$row
parameter.Now, I tried to align their behaviour the following way:
null
the default value. Previously, the default values were one of the following:-1
,0
, ornull
...0
value behave the same way as the default. Previously,odbc_fetch_row()
returned afalse
return value indicating there is no more rows when0
was passed, but the rest of the functions returned the next available row instead.This change causes a slight BC break forodbc_fetch_row()
though...HAVE_SQL_EXTENDED_FETCH
is not defined, the$row
parameter is always ignored. Previously, some of the functions didn't accept it at all. I think this behavior was not ideal, it would be better to emit a warning or even better, a specificValueError
if the feature is not supported, but the parameter has any value but the default one (null
). I can add this error if we can agree on it.