Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw out-of-memory error on a closed DB #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/SQLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ const StmtWrapper = Ref{StmtHandle}

# Normal constructor from filename
function sqliteexception(handle::DBHandle)
isopen(handle) || throw(SQLiteException("DB is closed"))
SQLiteException(unsafe_string(C.sqlite3_errmsg(handle)))
end
function sqliteexception(handle::DBHandle, stmt::StmtHandle)
isopen(handle) || throw(SQLiteException("DB is closed"))
errstr = unsafe_string(C.sqlite3_errmsg(handle))
stmt_text_handle = C.sqlite3_expanded_sql(stmt)
stmt_text = unsafe_string(stmt_text_handle)
Expand Down Expand Up @@ -77,7 +79,8 @@ DBInterface.connect(::Type{DB}) = DB()
DBInterface.connect(::Type{DB}, f::AbstractString) = DB(f)
DBInterface.close!(db::DB) = _close_db!(db)
Base.close(db::DB) = _close_db!(db)
Base.isopen(db::DB) = db.handle != C_NULL
Base.isopen(db::DB) = isopen(db.handle)
Base.isopen(handle::DBHandle) = handle != C_NULL

function finalize_statements!(db::DB)
# close stmts
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1019,4 +1019,11 @@ end
tbl_b = DBInterface.execute(db_b, "select myfunc(1) as x") |> columntable
@test tbl_a.x == [2]
@test tbl_b.x == [10]

# Throw an error when interfacing with a closed database
close(db_b)
@test_throws SQLiteException("DB is closed") DBInterface.execute(
db_b,
"select myfunc(1) as x",
)
end