Repository navigation
Make SQLite a fully private dependency (no SQLite type in installed headers) - #9737
Conversation
…eaders) SQLite (via vendored SQLiteCpp) was already PRIVATE-linked, but SQLite types still leaked into installed public headers. This removes every sqlite3 / sqlite3_stmt / SQLite:: reference from the installed header set, so downstream consumers can build and link against libOpenMS without any SQLite headers on their include path. Mirrors the Xerces work in #9712. C API (SqliteConnector + Internal::SqliteHelper): - Pimpl the native handle: sqlite3* db_ -> void* db_, exposed via a doc-hidden void* nativeHandle(). - Move getDB(), the sqlite3*-based static helpers, and the whole Internal::SqliteHelper namespace into a new non-installed include/OpenMS/FORMAT/SqliteConnector_impl.h (registered on OpenMS_private_headers). Add SqliteHelper::getNativeHandle(SqliteConnector&) and a prepareStatement(SqliteConnector&, ...) convenience overload. SQLiteCpp C++ API (SQLite::Database/Statement): - OMSFileStore.h / OMSFileLoad.h are Internal:: helpers; de-install them (move to OpenMS_private_headers). Remove the unused OMSFileLoad.h include from FeatureFinderMetaboIdent.cpp (its only external includer). pyOpenMS-wrapped classes (must stay installed): - MzMLSqliteHandler.h / TransitionPQPFile.h exposed sqlite3* only in private methods -> change the parameter to void* and cast inside the .cpp. - MzMLSqliteSwathHandler.h: drop a stale, unused `struct sqlite3;`. Internal call sites now obtain the raw handle via SqliteHelper::getNativeHandle() and include the private impl header. SqliteConnector_test now covers the public, SQLite-free API only (a consumer test has no <sqlite3.h> on its include path, by design). Verified: libOpenMS + pyOpenMS build clean; 14 SQLite-related class tests pass (SqliteConnector, OSWFile(+Inference), OpenSwath{Export,OSWWriter, PercolatorScoring}, TransitionPQPFile, BrukerTimsImagingFile, MzMLSqlite{Handler,SwathHandler}, OMSFile, SqMassFile, SpectrumAccessSqMass, CachedMzML). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThe PR moves SQLite C API types and helper operations behind a private implementation header. Public interfaces now use opaque handles, and OpenSWATH, mzML, OSW, imaging, and connector code routes SQL operations through internal helpers. ChangesSQLite privacy boundary
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/source/FORMAT/SqliteConnector.cpp`:
- Around line 156-183: Update executeBindStatement() so both sqlite3_bind_blob()
and sqlite3_step() error paths capture the database error message, call
sqlite3_finalize(stmt), and only then throw the existing exception with the
captured message.
- Around line 48-54: Update the SQLite open flow in the constructor around
sqlite3_open_v2 so that a non-OK return closes any non-null db handle before
throwing. Only assign db_ after confirming SQLITE_OK, leaving it unset on
failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 29c56535-fc67-4c9a-a9a9-4ae9858af0e7
📒 Files selected for processing (18)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/TransitionPQPFile.hsrc/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteHandler.hsrc/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteSwathHandler.hsrc/openms/include/OpenMS/FORMAT/SqliteConnector.hsrc/openms/include/OpenMS/FORMAT/SqliteConnector_impl.hsrc/openms/include/OpenMS/FORMAT/sources.cmakesrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathPercolatorScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cppsrc/openms/source/FORMAT/BrukerTimsImagingFile.cppsrc/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cppsrc/openms/source/FORMAT/HANDLERS/MzMLSqliteSwathHandler.cppsrc/openms/source/FORMAT/OSWFile.cppsrc/openms/source/FORMAT/SqliteConnector.cppsrc/tests/class_tests/openms/source/SqliteConnector_test.cppsrc/topp/FeatureFinderMetaboIdent.cpp
💤 Files with no reviewable changes (2)
- src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteSwathHandler.h
- src/topp/FeatureFinderMetaboIdent.cpp
| sqlite3* db = nullptr; | ||
| int rc = sqlite3_open_v2(filename.c_str(), &db, flags, nullptr); | ||
| db_ = db; | ||
| if (rc) | ||
| { | ||
| throw Exception::SqlOperationFailed(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Could not open sqlite db '" + filename + "' in mode " + StringUtils::toStr(int(mode))); | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n -C5 '\bsqlite3_open(_v2)?\s*\(' src/openmsRepository: OpenMS/OpenMS
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== SqliteConnector.cpp (relevant regions) ==\n'
sed -n '1,240p' src/openms/source/FORMAT/SqliteConnector.cpp | nl -ba | sed -n '1,240p'
printf '\n== Search for destructor / cleanup / executeBindStatement ==\n'
rg -n -C 4 'SqliteConnector::~SqliteConnector|executeBindStatement|sqlite3_close|sqlite3_finalize|db_' src/openms/source/FORMAT/SqliteConnector.cpp src/openms/include src/openms/source | head -n 250Repository: OpenMS/OpenMS
Length of output: 237
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the exact open path and nearby cleanup logic with line numbers.
python3 - <<'PY'
from pathlib import Path
path = Path('src/openms/source/FORMAT/SqliteConnector.cpp')
lines = path.read_text().splitlines()
for start, end in [(1, 120), (120, 260)]:
print(f"\n--- {path} lines {start}-{end} ---")
for i in range(start, min(end, len(lines)) + 1):
print(f"{i:4d}: {lines[i-1]}")
PYRepository: OpenMS/OpenMS
Length of output: 11412
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file=src/openms/source/FORMAT/SqliteConnector.cpp
echo "== line count =="
wc -l "$file"
echo
echo "== constructor/destructor and openDatabase_ region =="
sed -n '1,120p' "$file" | nl -ba | sed -n '1,120p'
echo
echo "== sqlite3 cleanup mentions =="
rg -n -C 3 'sqlite3_close|sqlite3_finalize|db_|openDatabase_|executeBindStatement|~SqliteConnector' "$file"Repository: OpenMS/OpenMS
Length of output: 313
Close the SQLite handle on failed open. sqlite3_open_v2 can return a non-null handle even on error, and assigning db_ before checking rc leaks that handle when the constructor throws. Close db on the failure path and assign db_ only after SQLITE_OK.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/openms/source/FORMAT/SqliteConnector.cpp` around lines 48 - 54, Update
the SQLite open flow in the constructor around sqlite3_open_v2 so that a non-OK
return closes any non-null db handle before throwing. Only assign db_ after
confirming SQLITE_OK, leaving it unset on failure.
| void executeBindStatement(sqlite3 *db, const std::string& prepare_statement, const std::vector<std::string>& data) | ||
| { | ||
| int rc; | ||
| sqlite3_stmt *stmt = nullptr; | ||
| prepareStatement(db, &stmt, prepare_statement); | ||
| for (Size k = 0; k < data.size(); k++) | ||
| { | ||
| // Fifth argument is a destructor for the blob. | ||
| // SQLITE_STATIC because the statement is finalized | ||
| // before the buffer is freed: | ||
| rc = sqlite3_bind_blob(stmt, k+1, data[k].c_str(), (int)data[k].size(), SQLITE_STATIC); | ||
| if (rc != SQLITE_OK) | ||
| { | ||
| std::cerr << "SQL error after sqlite3_bind_blob at iteration " << k << std::endl; | ||
| std::cerr << "Prepared statement " << prepare_statement << std::endl; | ||
| // TODO this is a mem-leak (missing sqlite3_finalize()) | ||
| throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, sqlite3_errmsg(db)); | ||
| } | ||
| } | ||
|
|
||
| rc = sqlite3_step(stmt); | ||
| if (rc != SQLITE_DONE) | ||
| { | ||
| std::cerr << "SQL error after sqlite3_step" << std::endl; | ||
| std::cerr << "Prepared statement " << prepare_statement << std::endl; | ||
| // TODO this is a mem-leak (missing sqlite3_finalize()) | ||
| throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, sqlite3_errmsg(db)); | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n -C5 'sqlite3_(prepare|bind|step|finalize)|mem-leak' src/openms/source/FORMAT/SqliteConnector.cppRepository: OpenMS/OpenMS
Length of output: 4757
🏁 Script executed:
sed -n '145,190p' src/openms/source/FORMAT/SqliteConnector.cpp | cat -nRepository: OpenMS/OpenMS
Length of output: 2585
Finalize the prepared statement on both error paths src/openms/source/FORMAT/SqliteConnector.cpp:156-183 — executeBindStatement() throws before stmt is finalized when sqlite3_bind_blob() or sqlite3_step() fails. Capture sqlite3_errmsg(db) first if needed, then call sqlite3_finalize(stmt) before throwing.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/openms/source/FORMAT/SqliteConnector.cpp` around lines 156 - 183, Update
executeBindStatement() so both sqlite3_bind_blob() and sqlite3_step() error
paths capture the database error message, call sqlite3_finalize(stmt), and only
then throw the existing exception with the captured message.
Follow-up to the previous commit: replace the void* handle parameters that
type-hiding introduced with properly typed references, so the installed
headers name neither a SQLite type nor a bare void* (down from 9 void* to 1).
- MzMLSqliteHandler / TransitionPQPFile: the private helpers now take a
SqliteConnector& (a SQLite-type-free type) instead of void*; the native
sqlite3* is resolved inside the .cpp via SqliteConnector_impl.h. Callers
pass the connection object directly (readExperiment no longer needs a raw
db local).
- SqliteConnector: drop the public void* nativeHandle() accessor. The one
remaining void* is the private db_ member; it is reachable only from the
non-installed SqliteConnector_impl.h through a new friend,
Internal::SqliteConnectorFriend. (A unique_ptr pimpl would remove even this
but would make SqliteConnector move-only; it is kept copyable because
OSWFile embeds it by value and declares a defaulted copy ctor.)
- SqliteConnector_test: verify a fresh connection is usable functionally
(the native handle is now fully private).
Verified: libOpenMS builds clean; 9 SQLite-related class tests pass
(SqliteConnector, OSWFile(+Inference), OpenSwath{Export,OSWWriter},
TransitionPQPFile, MzMLSqlite{Handler,SwathHandler}, SqMassFile).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tests/class_tests/openms/source/SqliteConnector_test.cpp`:
- Around line 49-51: Update the boolean assertion in the connection liveness
test to use TEST_TRUE with the tableExists("liveness_check") expression,
replacing the TEST_EQUAL(..., true) form while preserving the existing check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9ec775e4-7b14-46b4-add3-5adca62f5ef1
📒 Files selected for processing (7)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/TransitionPQPFile.hsrc/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteHandler.hsrc/openms/include/OpenMS/FORMAT/SqliteConnector.hsrc/openms/include/OpenMS/FORMAT/SqliteConnector_impl.hsrc/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cppsrc/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cppsrc/tests/class_tests/openms/source/SqliteConnector_test.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
- src/openms/include/OpenMS/FORMAT/SqliteConnector.h
- src/openms/include/OpenMS/FORMAT/SqliteConnector_impl.h
| // a successfully opened connection is usable (the native handle is fully private) | ||
| ptr->executeStatement("CREATE TABLE IF NOT EXISTS liveness_check (ID INT)"); | ||
| TEST_EQUAL(ptr->tableExists("liveness_check"), true) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Prefer TEST_TRUE for boolean assertions.
As per coding guidelines, use TEST_TRUE(expr) instead of TEST_EQUAL(expr, true) for boolean assertions in unit tests.
♻️ Proposed fix
// a successfully opened connection is usable (the native handle is fully private)
ptr->executeStatement("CREATE TABLE IF NOT EXISTS liveness_check (ID INT)");
- TEST_EQUAL(ptr->tableExists("liveness_check"), true)
+ TEST_TRUE(ptr->tableExists("liveness_check"))📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // a successfully opened connection is usable (the native handle is fully private) | |
| ptr->executeStatement("CREATE TABLE IF NOT EXISTS liveness_check (ID INT)"); | |
| TEST_EQUAL(ptr->tableExists("liveness_check"), true) | |
| // a successfully opened connection is usable (the native handle is fully private) | |
| ptr->executeStatement("CREATE TABLE IF NOT EXISTS liveness_check (ID INT)"); | |
| TEST_TRUE(ptr->tableExists("liveness_check")) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tests/class_tests/openms/source/SqliteConnector_test.cpp` around lines 49
- 51, Update the boolean assertion in the connection liveness test to use
TEST_TRUE with the tableExists("liveness_check") expression, replacing the
TEST_EQUAL(..., true) form while preserving the existing check.
Source: Coding guidelines
, #9740 (#9744) Backfills changelog entries for a SQLite private-dependency change, a ROCCurve::cutoffNeg fix, a pyOpenMS Windows NO_DEPENDENCIES test fix, and the Ghostscript-to-MathJax documentation build change, none of which had CHANGELOG entries yet. Claude-Session: https://claude.ai/code/session_012hWmgLm1tVqhrwzBZsFN1X Co-authored-by: Claude <[email protected]>
Summary
SQLite (via the vendored SQLiteCpp) was already a PRIVATE link dependency, but SQLite types still leaked into installed public headers. This removes every
sqlite3/sqlite3_stmt/SQLite::*reference from the installed header set, so downstream consumers can build and link against libOpenMS without any SQLite headers on their include path. This mirrors the Xerces private-dependency work in #9712 and reuses the sameOpenMS_private_headers(non-installed header) mechanism.What changed
C API —
SqliteConnector+Internal::SqliteHelper(the root leak)sqlite3* db_→void* db_, exposed via a doc-hiddenvoid* nativeHandle().getDB(), thesqlite3*-based static helpers, and the wholeInternal::SqliteHelpernamespace into a new non-installedinclude/OpenMS/FORMAT/SqliteConnector_impl.h. AddedSqliteHelper::getNativeHandle(SqliteConnector&)and aprepareStatement(SqliteConnector&, …)convenience overload.SQLiteCpp C++ API —
SQLite::Database/StatementOMSFileStore.h/OMSFileLoad.hareInternal::helpers → de-installed (moved toOpenMS_private_headers). Removed the unusedOMSFileLoad.hinclude fromFeatureFinderMetaboIdent.cpp(its only external includer).pyOpenMS-wrapped classes (must stay installed)
MzMLSqliteHandler.h/TransitionPQPFile.hexposedsqlite3*only in private methods → parameter changed tovoid*, cast inside the.cpp.MzMLSqliteSwathHandler.h: dropped a stale, unusedstruct sqlite3;.Internal call sites now obtain the raw handle via
SqliteHelper::getNativeHandle()and include the private impl header.SqliteConnector_testnow covers the public, SQLite-free API only — a consumer test has no<sqlite3.h>on its include path, which is exactly the guarantee this PR enforces.Verification
SqliteConnector,OSWFile(+Inference),OpenSwath{Export,OSWWriter,PercolatorScoring},TransitionPQPFile,BrukerTimsImagingFile,MzMLSqlite{Handler,SwathHandler},OMSFile,SqMassFile,SpectrumAccessSqMass,CachedMzML.🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests