Skip to content

Commit 9873efe

Browse files
committed
Throw correct error instead of out-of-memory error.
1 parent 7a00040 commit 9873efe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/SQLite.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ const StmtWrapper = Ref{StmtHandle}
2020

2121
# Normal constructor from filename
2222
function sqliteexception(handle::DBHandle)
23+
isopen(handle) || throw(SQLiteException("DB is closed"))
2324
SQLiteException(unsafe_string(C.sqlite3_errmsg(handle)))
2425
end
2526
function sqliteexception(handle::DBHandle, stmt::StmtHandle)
27+
isopen(handle) || throw(SQLiteException("DB is closed"))
2628
errstr = unsafe_string(C.sqlite3_errmsg(handle))
2729
stmt_text_handle = C.sqlite3_expanded_sql(stmt)
2830
stmt_text = unsafe_string(stmt_text_handle)
@@ -77,7 +79,8 @@ DBInterface.connect(::Type{DB}) = DB()
7779
DBInterface.connect(::Type{DB}, f::AbstractString) = DB(f)
7880
DBInterface.close!(db::DB) = _close_db!(db)
7981
Base.close(db::DB) = _close_db!(db)
80-
Base.isopen(db::DB) = db.handle != C_NULL
82+
Base.isopen(db::DB) = isopen(db.handle)
83+
Base.isopen(handle::DBHandle) = handle != C_NULL
8184

8285
function finalize_statements!(db::DB)
8386
# close stmts

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,11 @@ end
10191019
tbl_b = DBInterface.execute(db_b, "select myfunc(1) as x") |> columntable
10201020
@test tbl_a.x == [2]
10211021
@test tbl_b.x == [10]
1022+
1023+
# Throw an error when interfacing with a closed database
1024+
close(db_b)
1025+
@test_throws SQLiteException("DB is closed") DBInterface.execute(
1026+
db_b,
1027+
"select myfunc(1) as x",
1028+
)
10221029
end

0 commit comments

Comments
 (0)