Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# sqlite3-ruby Changelog

## next / unreleased

### Improved

- Use `sqlite3_close_v2` to close databases in a deferred manner if there are unclosed prepared statements. Previously closing a database while statements were open resulted in a `BusyException`. See https://www.sqlite.org/c3ref/close.html for more context. @flavorjones


## 2.0.4 / 2024-08-13

### Dependencies
Expand Down
4 changes: 2 additions & 2 deletions ext/sqlite3/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ deallocate(void *ctx)
sqlite3RubyPtr c = (sqlite3RubyPtr)ctx;
sqlite3 *db = c->db;

if (db) { sqlite3_close(db); }
if (db) { sqlite3_close_v2(db); }
xfree(c);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ sqlite3_rb_close(VALUE self)
TypedData_Get_Struct(self, sqlite3Ruby, &database_type, ctx);

db = ctx->db;
CHECK(db, sqlite3_close(ctx->db));
CHECK(db, sqlite3_close_v2(ctx->db));

ctx->db = NULL;

Expand Down
4 changes: 1 addition & 3 deletions test/test_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,7 @@ def call action, a, b, c, d

def test_close_with_open_statements
s = @db.prepare("select 'foo'")
assert_raises(SQLite3::BusyException) do
@db.close
end
@db.close # refute_raises(SQLite3::BusyException)
ensure
s&.close
end
Expand Down