Skip to content

Fix ROLLBACK TRANSACTION on FILESTORAGE databases to close #2948 - #2949

Merged
mathiasrw merged 1 commit into
developfrom
fix/2948
Nov 1, 2026
Merged

mathiasrw merged 1 commit into
developfrom
fix/2948

Conversation

@mathiasrw

Copy link
Copy Markdown
Member

Closes #2948

Problem

ROLLBACK TRANSACTION on a FILESTORAGE database with AUTOCOMMIT OFF throws, restores nothing, and never calls the callback.

Query (after INSERT INTO t VALUES (1); COMMIT TRANSACTION; INSERT INTO t VALUES (2)) Before After
alasql('ROLLBACK TRANSACTION') TypeError: alasql.loadFile is not a function 1
alasql('SELECT * FROM t') afterwards [{a: 1}, {a: 2}] [{a: 1}]
alasql('ROLLBACK TRANSACTION', [], cb) throws, cb never called cb(1) after the rows are restored

Cause

FS.rollback in src/94filestorage.js called alasql.loadFile, which does not exist (the loader is alasql.utils.loadFile, loadFile in the bundle). Behind that, the file content was assigned to db.data without JSON.parse, and the function never returned its result.

What changed

  • FS.rollback loads the file with loadFile, parses it, and rebuilds db.data and db.tables the way FS.attachDatabase does, so a rolled back database looks like a freshly attached one.
  • The schema version is bumped after the restore, so cached statements are compiled again.
  • Without a callback the file is read synchronously and 1 is returned. With a callback the existing wait for a save in progress is kept, and the callback runs once the rows are restored.
  • An error from the loader is thrown instead of calling an undefined error handler.

Test

test/test2948.js:

  • A) sync ROLLBACK TRANSACTION returns 1 and restores the rows of the last COMMIT
  • B) ROLLBACK TRANSACTION with a callback calls it with 1 after the rows are restored
  • C) the database keeps working afterwards: insert, commit, detach, attach, same rows

Without the change in src/ (restored from develop and rebuilt), A and B fail with TypeError: alasql.loadFile is not a function. With the change, all 3 pass.

Full suite: 2543 pass, 213 skip, 0 fail.

Reported by email from a Perch Scan run.

Related: #2625 (rollback on in-memory databases).

@mathiasrw mathiasrw added this to the v4.x Focus milestone Nov 1, 2026
@mathiasrw
mathiasrw merged commit d025ccc into develop Nov 1, 2026
10 checks passed
mathiasrw added a commit that referenced this pull request Nov 1, 2026
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.

ROLLBACK TRANSACTION on a FILESTORAGE database throws alasql.loadFile is not a function

1 participant