Skip to content

Fix transaction, statement lifecycle and cursor bugs in the driver - #28

Merged
wojta merged 6 commits into
masterfrom
optimize-code
Aug 3, 2026
Merged

Fix transaction, statement lifecycle and cursor bugs in the driver#28
wojta merged 6 commits into
masterfrom
optimize-code

Conversation

@wojta

@wojta wojta commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Motivation

Started as a cleanup of suspendCoroutine cancellation warnings. Auditing call sites turned up real correctness bugs, most seriously: every transaction after first silently committed instead of rolling back.

Notes

Each fix ships with a test that fails against the old code:

  • Nested transactions never closed out: endTransaction restored itself instead of enclosing transaction, so second and later transaction { } blocks skipped both BEGIN and ROLLBACK and silently committed.
  • Statement leak: executeQuery had no cleanup path. It now owns statement lifetime via try/finally, with check so transaction-cached statements stay owned by endTransaction. Removes SQLITE_BUSY warnings on close.
  • execute always returned 0 instead of rows affected.
  • executeAsFlow was not cold: cursor was created eagerly and captured, so second collection yielded nothing. Now a plain flow { }; old callbackFlow registered no callbacks.
  • Wrong externals: get/exec/prepare/bind callbacks had err misnamed self and typed non-null. Corrected against sqlite3.d.ts. reset deliberately left as Nothing?; upstream really does always pass null.
  • Cleanups: suspendCancellableCoroutine throughout, dead cursor state removed, nullable helper dropped (it was an identity function).

Commits are ordered so each one builds and passes on its own.

Heads-up

  • execute returning real counts is a user-visible change from old constant 0.
  • Statement lifetime now ends when mapper's QueryResult completes. SQLDelight accessors consume cursor inside mapper and are unaffected, but a custom mapper holding cursor past that point would break.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2025.2.3
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@wojta
wojta merged commit 7c863c4 into master Aug 3, 2026
6 checks passed
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.

1 participant