Message-ID: From: "jarvis24young (@jarvis24young)" To: "postgresql-interfaces/psqlodbc" Date: Tue, 12 May 2026 01:32:18 +0000 Subject: [postgresql-interfaces/psqlodbc] PR #186: Pass SQLSetDescRec field values correctly List-Id: X-GitHub-Author-Id: 48787405 X-GitHub-Author-Login: jarvis24young X-GitHub-Issue: 186 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-State: merged X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/pull/186 Content-Type: text/plain; charset=utf-8 ## Summary `PGAPI_SetDescRec()` forwards its arguments to `PGAPI_SetDescField()`, whose descriptor setters expect scalar descriptor values to be encoded in the `SQLPOINTER` argument, while pointer descriptor fields must receive the application pointer itself. The old code passed addresses of local variables for both cases: - scalar fields such as `SQL_DESC_TYPE`, `SQL_DESC_OCTET_LENGTH`, `SQL_DESC_PRECISION`, and `SQL_DESC_SCALE` received `&Type`, `&Length`, etc. - `SQL_DESC_DATA_PTR` received `&Data` instead of `Data` This could leave an ARD record with an invalid C type or a data pointer to a stack slot rather than the caller's output buffer. This patch passes scalar values in the same form already expected by `PGAPI_SetDescField()`, and passes `SQL_DESC_DATA_PTR` as the caller's data buffer pointer. ## Regression test The existing `descrec` test now also covers `SQLSetDescRec()` on the application row descriptor: 1. Get the statement ARD with `SQLGetStmtAttr(SQL_ATTR_APP_ROW_DESC)`. 2. Bind column 1 through `SQLSetDescRec(..., SQL_C_CHAR, ..., value, &ind, &ind)`. 3. Execute `SELECT 42` and fetch the row. 4. Verify the application buffer receives `42` and the indicator is `2`. Before the fix, the same black-box sequence failed at `SQLFetch` with SQLSTATE `07006` because the descriptor type was not stored as `SQL_C_CHAR`. ## Verification WSL ASan/UBSan build: ```text ./runsuite descrec --inputdir=. TAP version 13 1..1 ok 1 - descrec ``` Also ran `git diff --check`.