Skip to content

Commit

Permalink
Merge pull request #557 from sparklemotion/flavorjones-use-close-v2
Browse files Browse the repository at this point in the history
Use sqlite3_close_v2 to close databases.
  • Loading branch information
flavorjones authored Sep 15, 2024
2 parents 480f3e7 + da90865 commit ccddd85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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

0 comments on commit ccddd85

Please sign in to comment.