Skip to content

odbc: make odbc_sql_error() formattable, drop odbc_colattribute_failed - #23612

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/odbc-sql-error-varargs
Open

odbc: make odbc_sql_error() formattable, drop odbc_colattribute_failed#23612
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/odbc-sql-error-varargs

Conversation

@iliaal

@iliaal iliaal commented Sep 7, 2026

Copy link
Copy Markdown
Member

Follow-up to #23601, per your suggestion there. odbc_sql_error() takes a format now, so the two SQLColAttribute sites can name the column and the ad-hoc helper is gone. The other 50 callers pass a plain literal and needed no change; the printf attribute covers them.

I left the SQLError in odbc_cursor() alone. It reads SQLSTATE S1015 and synthesizes a cursor name from that, so it wants its own change rather than a swap. Routing the SQLColAttribute failures through odbc_sql_error() also populates the connection's last-error state, so odbc_error() and odbc_errormsg() now report them, hence the NEWS line.

@iliaal
iliaal requested a review from NattyNarwhal as a code owner September 7, 2026 22:53
iliaal added a commit to iliaal/php-src that referenced this pull request Sep 7, 2026
odbc_colattribute_failed() existed only because odbc_sql_error() could not
take a column number. Make the reporter variadic so callers can format the
context into it, and route the two SQLColAttribute sites through it. Those
failures now also populate the connection's last-error state, so
odbc_error() and odbc_errormsg() report them.

Closes phpGH-23612
@iliaal
iliaal force-pushed the fix/odbc-sql-error-varargs branch from 5092a7f to 08c3eaf Compare September 7, 2026 22:53

@NattyNarwhal NattyNarwhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, just one minor nit. I can take a look at converting SQLError usage to SQLGetDiagRec next, or if you also want to tackle that, feel free.

Comment thread ext/odbc/php_odbc_includes.h Outdated
void odbc_bindcols(odbc_result *result);

#define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
#define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, const char *func

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we could probably drop the macro here

odbc_colattribute_failed() existed only because odbc_sql_error() could not
take a column number. Make the reporter variadic so callers can format the
context into it, and route the two SQLColAttribute sites through it. Those
failures now also populate the connection's last-error state, so
odbc_error() and odbc_errormsg() report them.

Closes phpGH-23612
@iliaal
iliaal force-pushed the fix/odbc-sql-error-varargs branch from 08c3eaf to a9356d8 Compare September 8, 2026 00:25
@iliaal
iliaal requested a review from NattyNarwhal September 8, 2026 00:26

@NattyNarwhal NattyNarwhal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM; the additional allocation from this isn't ideal, but I'm not sure how we could avoid it without using the stack for part of it (seems a bit clumsy?) or having both the va_list and our additional params (not possible afaik).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants