pg.ddx.io  GitHub: postgresql-interfaces/psqlodbc (issues + PRs as email threads)  
help / color / mirror / Atom feed
[postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
6+ messages / 2 participants
[nested] [flat]

* [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-05 07:48  "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>
  0 siblings, 0 replies; 6+ messages in thread

From: laofeijio2020ojbk2022 (@laofeijio2020ojbk2022) @ 2026-11-05 07:48 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>

Statement_sqlstate[] was missing an entry for STMT_STRING_CONVERSION_ERROR, so when a string conversion error occurred the SQLSTATE lookup fell back to the generic HY000 (STMT_EXEC_ERROR) instead of the specific 22018 (invalid character value for cast specification).

Add the missing array element so SQLFetch/SQLGetData string conversion errors report 22018 per ODBC Appendix A.

inline patch 1: statement.c (+2/-1 lines) download inline-1.patchdiff --git a/statement.c b/statement.c index 76c9ba7b..e2c4b14d 100644 --- a/statement.c +++ b/statement.c @@ -1317,7 +1317,8 @@ static const struct { STMT_COUNT_FIELD_INCORRECT, "07002", "07002" }, { STMT_INVALID_NULL_ARG, "HY009", "S1009" }, { STMT_NO_RESPONSE, "08S01", "08S01" }, - { STMT_COMMUNICATION_ERROR, "08S01", "08S01" } + { STMT_COMMUNICATION_ERROR, "08S01", "08S01" }, + { STMT_STRING_CONVERSION_ERROR, "22018", "22018" } /* invalid character value for cast specification */ }; static PG_ErrorInfo *
^ permalink raw [nested|flat] 6+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] PR #237 (changes requested): Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-05 17:48  "davecramer (@davecramer)" <noreply+davecramer@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: davecramer (@davecramer) @ 2026-11-05 17:48 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@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.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-05 17:48  "davecramer (@davecramer)" <noreply+davecramer@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: davecramer (@davecramer) @ 2026-11-05 17:48 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>

(on statement.c)

22018 is ODBC 3.x only; ODBC 2.x applications expect 22005 here.

```suggestion
	{ STMT_STRING_CONVERSION_ERROR, "22018", "22005" } /* invalid character value for cast specification */
```

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-05 20:59  "davecramer (@davecramer)" <noreply+davecramer@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: davecramer (@davecramer) @ 2026-11-05 20:59 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>

One more request: could you add a regression test, so the mapping stays covered?

The error comes from the Unicode driver when it fetches text into `SQL_C_CHAR` and the client's locale encoding differs from the connection's (UTF-8). It converts the value to the locale's encoding, and that fails for a character the locale can't represent (`localize_needed` in `setup_getdataclass`, convert.c). So a test could:

1. Call `setlocale(LC_ALL, "C")`, or another locale that can't represent the character, before `test_connect()`.
2. Fetch a text value containing such a character into `SQL_C_CHAR`, for example `SELECT '€'::text` read with `SQLGetData`.
3. Check that the call returns `SQL_ERROR` with SQLSTATE 22018.

`test/src/wchar-char-test.c` shows the pattern for locale-dependent tests. It sets the locale before connecting, and prints fixed output and exits when it can't run in that environment, for example with the ANSI driver (`IsAnsi()`) or on a platform where it can't control the locale. The new test would need the same, with its expected output in `test/expected/` and an entry in `test/tests`.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-06 02:10  "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: laofeijio2020ojbk2022 (@laofeijio2020ojbk2022) @ 2026-11-06 02:10 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>

@laofeijio2020ojbk2022 closed this.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR
@ 2026-11-06 02:13  "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: laofeijio2020ojbk2022 (@laofeijio2020ojbk2022) @ 2026-11-06 02:13 UTC (permalink / raw)
  To: postgresql-interfaces/psqlodbc <noreply+postgresql-interfaces-psqlodbc@github.com>

@laofeijio2020ojbk2022 reopened this.

^ permalink  raw  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-06 02:13 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 07:48 [postgresql-interfaces/psqlodbc] PR #237: Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>
2026-11-05 17:48 ` Re: [postgresql-interfaces/psqlodbc] PR #237 (changes requested): Fix SQLSTATE fallback for STMT_STRING_CONVERSION_ERROR "davecramer (@davecramer)" <noreply+davecramer@github.com>
2026-11-05 17:48 ` "davecramer (@davecramer)" <noreply+davecramer@github.com>
2026-11-05 20:59 ` "davecramer (@davecramer)" <noreply+davecramer@github.com>
2026-11-06 02:10 ` "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>
2026-11-06 02:13 ` "laofeijio2020ojbk2022 (@laofeijio2020ojbk2022)" <noreply+laofeijio2020ojbk2022@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox