Skip to content

Conversation

theboringhumane
Copy link

@theboringhumane theboringhumane commented Sep 17, 2025

Implement driver-side prepared statements for non-INSERT queries in the database/sql compatibility layer.

Changes:

  • Introduce stdStmt and wire it into PrepareContext for non-INSERT statements

  • Implement StmtQueryContext/StmtExecContext using underlying connection

  • Preserve INSERT behavior via stdBatch (Exec-only)

  • Add example examples/std/prepared.go and run it in examples suite

  • Add tests: prepared select, USE + prepared select, and merged funds temp test

  • Remove temporary test file; fix minor linter warning in clickhouse_std.go

Rationale:

  • Restores database/sql compatibility for prepared read queries (e.g., Stmt.QueryContext) while keeping batch INSERT semantics

Summary

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

Implement driver-side prepared statements for non-INSERT queries in the database/sql compatibility layer.

Changes:

- Introduce stdStmt and wire it into PrepareContext for non-INSERT statements

- Implement StmtQueryContext/StmtExecContext using underlying connection

- Preserve INSERT behavior via stdBatch (Exec-only)

- Add example examples/std/prepared.go and run it in examples suite

- Add tests: prepared select, USE + prepared select, and merged funds temp test

- Remove temporary test file; fix minor linter warning in clickhouse_std.go

Rationale:

- Restores database/sql compatibility for prepared read queries (e.g., Stmt.QueryContext) while keeping batch INSERT semantics
@CLAassistant
Copy link

CLAassistant commented Sep 17, 2025

CLA assistant check
All committers have signed the CLA.

@kavirajk
Copy link
Contributor

@theboringhumane thanks for the contribution. can you take care of the failing test cases?

code: 62, message: Syntax error: failed at position 58 (end of query) (line 3, col 5): . Expected one of: token, Dot, OpeningRoundBracket, FROM INFILE, SETTINGS, VALUES, FORMAT, SELECT, WITH

@theboringhumane
Copy link
Author

@theboringhumane thanks for the contribution. can you take care of the failing test cases?

code: 62, message: Syntax error: failed at position 58 (end of query) (line 3, col 5): . Expected one of: token, Dot, OpeningRoundBracket, FROM INFILE, SETTINGS, VALUES, FORMAT, SELECT, WITH

I'll take care of that. No sweat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants