feat(core): add parameterized query interface to database_backend#559
Merged
Conversation
Add select_prepared() and execute_prepared() virtual methods with default fallback implementations that expand placeholders via string interpolation. This establishes the interface for wire-level prepared statements while maintaining backward compatibility. Supports both $N (PostgreSQL-style) and ? (SQLite-style) placeholders in the fallback. Backends should override these methods with native prepared statement implementations for true SQL injection protection. Fix pre-existing broken markdown anchors in docs/README.kr.md. Part of #557
Contributor
Benchmark ResultsNo comparison reports available. Baseline may not be established yet. |
This was referenced Apr 10, 2026
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
Add select_prepared() and execute_prepared() virtual methods with default fallback implementations that expand placeholders via string interpolation. This establishes the interface for wire-level prepared statements while maintaining backward compatibility. Supports both $N (PostgreSQL-style) and ? (SQLite-style) placeholders in the fallback. Backends should override these methods with native prepared statement implementations for true SQL injection protection. Fix pre-existing broken markdown anchors in docs/README.kr.md. Part of #557
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Summary
Adds
select_prepared()andexecute_prepared()virtual methods to thedatabase_backendinterface, establishing the foundation for wire-level prepared statement support. Default implementations fall back to string interpolation for backward compatibility.Change Type
Affected Components
database/core/database_backend.h— New virtual methods + fallback helpersWhy
Problem Solved
All SQL execution currently relies on string-level escaping via
value_formatterto prevent SQL injection. This PR establishes the interface for true parameterized queries where SQL and values travel separately. The default fallback ensures zero breakage for existing backends — they compile without changes.Related Issues
libpq/sqlite3prepared statements) will followunified_database_systemto use prepared path by default) will followWhere
Files Changed
database/core/database_backend.hselect_prepared,execute_prepared,expand_params,value_to_sqldocs/README.kr.mdHow
Implementation Details
New virtual methods (with default fallback):
Fallback mechanism:
expand_params()substitutes$N(PostgreSQL, reverse order to avoid$1/$10collision) and?(SQLite, left-to-right)value_to_sql()convertsdatabase_valuevariant to SQL literal with basic escapingFuture override pattern (Phase 2):
Breaking Changes
None — new methods have default implementations. Existing backends compile without modification.
Test Plan