From: davecramer (@davecramer) <noreply+davecramer@github.com>
To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>
Subject: Re: [postgresql-interfaces/psqlodbc] PR #237 (changes requested): Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
Date: Thu, 05 Nov 2026 17:48:53 +0000
Message-ID: <gh-postgresql-interfaces-psqlodbc-237-r5789437143@github.com> (raw)
In-Reply-To: <gh-postgresql-interfaces-psqlodbc-237@github.com>
References: <gh-postgresql-interfaces-psqlodbc-237@github.com>
Thanks for finding this. The diagnosis is right: `Statement_sqlstate[]` is indexed by `errornum - LOWEST_STMT_ERROR`, and `STMT_STRING_CONVERSION_ERROR` (added to the enum in 5eeb934) had no entry, so it fell off the end of the table and the bounds check mapped it to `STMT_EXEC_ERROR`, HY000. I checked the table against the enum entry by entry, and appending it at the end puts it at the right index.
One change before merging: the third column is the SQLSTATE that ODBC 2.x applications get, which is why the other entries pair `HY000` with `S1000` and so on. 22018 doesn't exist in ODBC 2; its ODBC 2 equivalent is 22005 (Error in assignment). See the suggestion on the line.
For the record, not a blocker: the error is raised when fetched text can't be converted between the server's encoding and the client's (`bindcol_localize_*` / `bindcol_hybrid_*`, from `SQLFetch` into bound columns and from `SQLGetData`). ODBC defines 22018 for character data that isn't a valid literal of a numeric, datetime or interval type, so an encoding failure is closer to SQL's 22021 (character not in repertoire), which isn't in ODBC's list for these functions. 22018 is a reasonable choice and much better than a general error.