Skip to content

Make SQLite a fully private dependency (no SQLite type in installed headers) - #9737

Merged
timosachsenberg merged 2 commits into
developfrom
feature/sqlite-full-type-hiding
Jul 14, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
feature/sqlite-full-type-hiding

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

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 same OpenMS_private_headers (non-installed header) mechanism.

What changed

C API — SqliteConnector + Internal::SqliteHelper (the root leak)

  • 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. Added SqliteHelper::getNativeHandle(SqliteConnector&) and a prepareStatement(SqliteConnector&, …) convenience overload.

SQLiteCpp C++ API — SQLite::Database/Statement

  • OMSFileStore.h / OMSFileLoad.h are Internal:: helpers → de-installed (moved to OpenMS_private_headers). Removed 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 → parameter changed to void*, cast inside the .cpp.
  • MzMLSqliteSwathHandler.h: dropped 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, which is exactly the guarantee this PR enforces.

Verification

  • libOpenMS + pyOpenMS build clean (WITH_OPENTIMS + WITH_THERMO_RAW on, so every changed file compiled).
  • 14 SQLite-related class tests pass: SqliteConnector, OSWFile(+Inference), OpenSwath{Export,OSWWriter,PercolatorScoring}, TransitionPQPFile, BrukerTimsImagingFile, MzMLSqlite{Handler,SwathHandler}, OMSFile, SqMassFile, SpectrumAccessSqMass, CachedMzML.
  • Confirmed no actual SQLite type remains in any installed header (only doc-comment mentions).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Updated the SQLite connector so SQLite implementation details and native SQLite types are no longer exposed in installed/public headers.
    • Internal SQLite logic was consolidated behind a SQLite-free connector surface, while keeping existing file read/write, querying, and metadata workflows working as before.
    • Added internal-only support headers to separate adapter internals from the public API.
  • Tests

    • Adjusted connector tests to focus on the public, SQLite-free interface and removed checks that depended on direct exposure of native SQLite types.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

SQLite privacy boundary

Layer / File(s) Summary
Public and private header contracts
src/openms/include/OpenMS/FORMAT/..., src/openms/include/OpenMS/ANALYSIS/OPENSWATH/...
Installed headers remove SQLite declarations, expose nativeHandle(), and classify SQLite-related headers as private.
Connector helper implementation and tests
src/openms/include/OpenMS/FORMAT/SqliteConnector_impl.h, src/openms/source/FORMAT/SqliteConnector.cpp, src/tests/.../SqliteConnector_test.cpp
SQLite lifecycle and SQL helpers move behind Internal::SqliteHelper; tests validate the opaque API and retained error behavior.
OpenSWATH SQLite call-site migration
src/openms/source/ANALYSIS/OPENSWATH/*
OpenSWATH readers, writers, and scoring paths use private helper functions for handles, preparation, execution, and schema checks.
mzML SQLite handler migration
src/openms/source/FORMAT/HANDLERS/*
mzML spectrum, chromatogram, and SWATH handlers pass connector references internally and use private statement preparation.
OSW and imaging reader migration
src/openms/source/FORMAT/OSWFile.cpp, src/openms/source/FORMAT/BrukerTimsImagingFile.cpp
OSW and imaging SQL paths use Internal::SqliteHelper without changing their query or parsing logic.

Suggested reviewers: cbielow, singjc

Poem

A rabbit hops where SQLite hid,
Behind a veil, its types are slid.
Handles turn opaque and neat,
Helpers make the queries fleet.
“No public paws on private code!”
Cheers the bunny down the road.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: making SQLite a fully private dependency and removing SQLite types from installed headers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/sqlite-full-type-hiding

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ae0562 and b70cb5e.

📒 Files selected for processing (18)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/TransitionPQPFile.h
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteHandler.h
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteSwathHandler.h
  • src/openms/include/OpenMS/FORMAT/SqliteConnector.h
  • src/openms/include/OpenMS/FORMAT/SqliteConnector_impl.h
  • src/openms/include/OpenMS/FORMAT/sources.cmake
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWParquetWriter.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/OpenSwathPercolatorScoring.cpp
  • src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp
  • src/openms/source/FORMAT/BrukerTimsImagingFile.cpp
  • src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp
  • src/openms/source/FORMAT/HANDLERS/MzMLSqliteSwathHandler.cpp
  • src/openms/source/FORMAT/OSWFile.cpp
  • src/openms/source/FORMAT/SqliteConnector.cpp
  • src/tests/class_tests/openms/source/SqliteConnector_test.cpp
  • src/topp/FeatureFinderMetaboIdent.cpp
💤 Files with no reviewable changes (2)
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteSwathHandler.h
  • src/topp/FeatureFinderMetaboIdent.cpp

Comment on lines +48 to 54
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)));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C5 '\bsqlite3_open(_v2)?\s*\(' src/openms

Repository: 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 250

Repository: 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]}")
PY

Repository: 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.

Comment on lines +156 to +183
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));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.cpp

Repository: OpenMS/OpenMS

Length of output: 4757


🏁 Script executed:

sed -n '145,190p' src/openms/source/FORMAT/SqliteConnector.cpp | cat -n

Repository: 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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b70cb5e and 684ab49.

📒 Files selected for processing (7)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/TransitionPQPFile.h
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLSqliteHandler.h
  • src/openms/include/OpenMS/FORMAT/SqliteConnector.h
  • src/openms/include/OpenMS/FORMAT/SqliteConnector_impl.h
  • src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp
  • src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp
  • src/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

Comment on lines +49 to +51
// 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
// 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

@timosachsenberg
timosachsenberg merged commit 76464d1 into develop Jul 14, 2026
18 checks passed
@timosachsenberg
timosachsenberg deleted the feature/sqlite-full-type-hiding branch July 14, 2026 13:40
timosachsenberg added a commit that referenced this pull request Jul 15, 2026
, #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]>
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.

2 participants