Skip to content

feat: SQLDescribeParam state guard + SQLNativeSql/W pass-through#730

Merged
sfc-gh-makowalski merged 4 commits intomainfrom
describe-param-after-prepare
Mar 31, 2026
Merged

feat: SQLDescribeParam state guard + SQLNativeSql/W pass-through#730
sfc-gh-makowalski merged 4 commits intomainfrom
describe-param-after-prepare

Conversation

@sfc-gh-makowalski
Copy link
Copy Markdown
Contributor

@sfc-gh-makowalski sfc-gh-makowalski commented Mar 26, 2026

Summary

Combines two small features into one PR:

SQLDescribeParam state restriction

  • Restrict SQLDescribeParam to only allow Prepared, NoResultSet{prepared:true},
    and Done{prepared:true} states, returning HY010 otherwise
  • Removes stale TODO comments, replaces with accurate doc comments

SQLNativeSql / SQLNativeSqlW implementation

  • Implement pass-through SQLNativeSql and SQLNativeSqlW C API functions
  • Connection-level validation: null input (HY009), negative length (HY090),
    disconnected state (08003)
  • Truncation handling with 01004 (String data right truncated)
  • Add SQLNativeSqlW to exports.def

SQLNumParams parser edge-case tests

  • Add 3 new tests: ? inside single-quoted literals, line comments, escaped quotes
  • Add documentation block listing tested vs non-tested (DM/infrastructure) SQLSTATEs

Made-with: Cursor

@sfc-gh-makowalski sfc-gh-makowalski force-pushed the describe-param-after-prepare branch from b981e36 to 0e200b9 Compare March 26, 2026 15:02
@sfc-gh-makowalski sfc-gh-makowalski force-pushed the auto-ipd-core branch 2 times, most recently from 0c33eca to 6396dd7 Compare March 27, 2026 07:08
@sfc-gh-makowalski sfc-gh-makowalski force-pushed the describe-param-after-prepare branch 2 times, most recently from 42d0a7c to 3a87155 Compare March 27, 2026 08:13
@sfc-gh-makowalski sfc-gh-makowalski changed the title feat: restrict SQLDescribeParam to prepared statement states feat: SQLDescribeParam state guard + SQLNativeSql/W pass-through Mar 27, 2026
@github-actions github-actions Bot added the tests label Mar 27, 2026
@sfc-gh-makowalski sfc-gh-makowalski force-pushed the describe-param-after-prepare branch from 9310151 to 469d4e9 Compare March 27, 2026 08:45
@sfc-gh-makowalski sfc-gh-makowalski marked this pull request as ready for review March 27, 2026 08:45
@sfc-gh-makowalski sfc-gh-makowalski requested a review from a team as a code owner March 27, 2026 08:45
@sfc-gh-makowalski sfc-gh-makowalski force-pushed the describe-param-after-prepare branch from 469d4e9 to 292d6d9 Compare March 27, 2026 09:27
Count parameter markers (?) during SQLPrepare, ignoring those inside
string literals and line comments. Populate the IPD with default
records (SQL_VARCHAR, nullable unknown) so SQLNumParams works after
bare SQLPrepare without requiring SQLBindParameter first.

- SQL_RESET_PARAMS now only clears APD (bindings), preserving IPD
  (prepare metadata) per ODBC spec
- Add 07002 (COUNT field incorrect) detection: execute fails when
  IPD has parameter markers but APD has insufficient bindings
- Enable 07002 E2E test deferred from PR #416
- Add CountFieldIncorrect error variant mapped to SQLSTATE 07002

Made-with: Cursor
Also fix exec_direct_impl to populate IPD from parameter markers before
checking binding counts. Without this, stale IPD records from a prior
SQLBindParameter caused spurious 07002 errors when SQLExecDirect was
called after SQL_RESET_PARAMS on a query with no parameter markers.

Made-with: Cursor
SQLDescribeParam should only succeed when the statement is in a
prepared-related state (Prepared, NoResultSet{prepared}, Done{prepared}).
Reject Executed (from ExecDirect), Fetching, and Created states with
HY010 per ODBC spec. This matches the reference driver behavior.

describe_param_tests.cpp remain gated by StmtDefaultDSNFixture's
SQLConnect dependency (SKIP_NEW_DRIVER_NOT_IMPLEMENTED). Individual
test skips are kept as documentation until SQLConnect lands.

Made-with: Cursor
Add connection-level SQL translation function that passes SQL text
through unchanged (Snowflake does not perform ODBC escape sequence
translation). Handles:
- Pass-through copy of input to output buffer
- Truncation detection with SQL_SUCCESS_WITH_INFO + 01004
- Null output buffer (returns length only via TextLength2Ptr)
- Zero TextLength1 (returns empty string)
- Validation: null InStatementText (HY009), negative lengths (HY090),
  disconnected state (08003), null handle (SQL_INVALID_HANDLE)

Add SQLNativeSqlW to exports.def.

Also add SQLNumParams parser edge case tests (markers in string
literals, line comments, escaped quotes) and document which Microsoft
spec SQLSTATEs are out of scope for testing.

Made-with: Cursor
@sfc-gh-makowalski sfc-gh-makowalski force-pushed the describe-param-after-prepare branch from 76ebfc6 to 1d61f03 Compare March 31, 2026 08:58
Base automatically changed from auto-ipd-core to main March 31, 2026 10:20
@sfc-gh-makowalski sfc-gh-makowalski added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit 4f3a41c Mar 31, 2026
49 of 85 checks passed
@sfc-gh-makowalski sfc-gh-makowalski deleted the describe-param-after-prepare branch March 31, 2026 14:25
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