postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: jarvis24young (@jarvis24young) <[email protected]>
To: postgresql-interfaces/psqlodbc <[email protected]>
Subject: [postgresql-interfaces/psqlodbc] PR #186: Pass SQLSetDescRec field values correctly
Date: Tue, 12 May 2026 01:32:18 +0000
Message-ID: <[email protected]> (raw)

## 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`.

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://postgresql-interfaces/psqlodbc
  Cc: [email protected], [email protected]
  Subject: Re: [postgresql-interfaces/psqlodbc] PR #186: Pass SQLSetDescRec field values correctly
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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