Skip to content

Commit

Permalink
Recover SQlite.isready for statemaent
Browse files Browse the repository at this point in the history
  • Loading branch information
metab0t committed Jun 10, 2022
1 parent f592a8a commit 6f9ae6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SQLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ function _set_stmt_handle(stmt::Stmt, handle)
stmt.stmt_wrapper[] = handle
end

# check if the statement is ready (not finalized due to _close_stmt!(Stmt) called)
isready(stmt::Stmt) = _get_stmt_handle(stmt) != C_NULL

function _close_stmt!(stmt::Stmt)
C.sqlite3_finalize(_get_stmt_handle(stmt))
_set_stmt_handle(stmt, C_NULL)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -852,21 +852,25 @@ end
@testset "explicit finalization by finalize_statements!(db)" begin
SQLite.load!(tbl, db, "test_table")
stmt = SQLite.Stmt(db, "SELECT a, b FROM test_table")
@test SQLite.isready(stmt)
@test SQLite.execute(stmt) == 100
# test cannot drop the table locked by the statement
@test_throws SQLiteException SQLite.drop!(db, "test_table")
SQLite.finalize_statements!(db)
@test !SQLite.isready(stmt)
SQLite.drop!(db, "test_table")
DBInterface.close!(stmt) # test can call close!() 2nd time
end

@testset "explicit finalization by close!(stmt)" begin
SQLite.load!(tbl, db, "test_table2")
stmt = SQLite.Stmt(db, "SELECT a, b FROM test_table2")
@test SQLite.isready(stmt)
@test SQLite.execute(stmt) == 100
# test cannot drop the table locked by the statement
@test_throws SQLiteException SQLite.drop!(db, "test_table2")
DBInterface.close!(stmt)
@test !SQLite.isready(stmt)
SQLite.drop!(db, "test_table2")
DBInterface.close!(stmt) # test can call close!() 2nd time
end
Expand Down

0 comments on commit 6f9ae6a

Please sign in to comment.