Skip to content

Conversation

Copy link

Copilot AI commented Jan 24, 2026

Implementation Plan: Add Support for Prepared Statement Flags

  • Define PREPARE flag constants in Database.h/cpp (like OPEN_* flags)
    • Add PREPARE_PERSISTENT constant
    • Add PREPARE_NORMALIZE constant
    • Add PREPARE_NO_VTAB constant
    • Add PREPARE_DONT_LOG constant
  • Add prepFlags parameter to Statement constructor
    • Update Statement.h to add optional prepFlags parameter (default 0)
    • Update Statement.cpp to use sqlite3_prepare_v3 when available
  • Add tests for the new functionality
    • Test creating statement with PREPARE_PERSISTENT flag
    • Test creating statement with PREPARE_DONT_LOG flag
    • Test creating statement with combined flags
  • Build and validate changes
    • Run targeted Statement tests
    • Run full test suite
    • Address review feedback
    • Request code review
    • Run security checks

Changes Based on Review Feedback

✅ Removed mPrepFlags member variable - now passed as parameter to prepareStatement()
✅ Always use sqlite3_prepare_v3 when available (SQLite >= 3.20.0) instead of conditionally switching
✅ Added version checking with #if SQLITE_VERSION_NUMBER >= 3020000
✅ PREPARE_* flags return 0 on older SQLite versions for graceful degradation

Summary

Successfully implemented support for prepared statement flags with clean, minimal design:

  • Uses sqlite3_prepare_v3 exclusively when available (SQLite 3.20.0+)
  • Falls back to sqlite3_prepare_v2 on older versions (flags ignored)
  • No runtime switching logic - cleaner implementation
  • All tests pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for prepared statement flags</issue_title>
<issue_description>The SQLite::Statement constructor does not support the prepFlags argument to sqlite3_prepare_v3.

Prepare Flags 🗎 have a few nifty uses:

  • SQLITE_PREPARE_PERSISTENT hints that we'll retain and reuse the statement many times.
  • SQLITE_PREPARE_DONT_LOG is useful for testing SQL syntax such as in live-coding environments.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 24, 2026 21:46
- Define PREPARE_* constants in Database.h/cpp
- Add prepFlags parameter to Statement constructors
- Update Statement implementation to use sqlite3_prepare_v3
- Add comprehensive tests for prepare flags

Co-authored-by: SRombauts <868490+SRombauts@users.noreply.github.com>
Co-authored-by: SRombauts <868490+SRombauts@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for prepared statement flags in SQLite Add support for prepared statement flags Jan 24, 2026
Copilot AI requested a review from SRombauts January 24, 2026 21:50
@SRombauts
Copy link
Owner

@copilot
0. As an afterthought, are you sure it's reasonable to add the usage of sqlite3_prepare_v3()? Do we have ways to check the version of SQLite3?

  1. Why do you need a member variable mPrepFlags? You could just pass in the flag as an arg to prepareStatement(), no?
  2. Why do you need to keep using sqlite3_prepare_v2 and use a switch? Wouldn't it be much simpler to just rely on v3 always

- Remove mPrepFlags member variable, pass as parameter instead
- Always use sqlite3_prepare_v3 when available (SQLite >= 3.20.0)
- Add version checking for PREPARE_* flags
- Simplify implementation by eliminating conditional v2/v3 logic

Co-authored-by: SRombauts <868490+SRombauts@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 24, 2026

@copilot
0. As an afterthought, are you sure it's reasonable to add the usage of sqlite3_prepare_v3()? Do we have ways to check the version of SQLite3?

  1. Why do you need a member variable mPrepFlag...

All three concerns addressed in commit 90173e8:

  1. Added version checking using #if SQLITE_VERSION_NUMBER >= 3020000 (sqlite3_prepare_v3 introduced in SQLite 3.20.0). PREPARE_* flags return 0 on older versions for graceful degradation.

  2. Removed mPrepFlags member variable. Now passed as parameter directly to prepareStatement().

  3. Simplified to always use sqlite3_prepare_v3 when available (SQLite >= 3.20.0), falling back to sqlite3_prepare_v2 only on older versions. No runtime switching logic needed.

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.

Add support for prepared statement flags

2 participants