From 6f9ae6acacea382d7092c8c4c22a472a6c55595b Mon Sep 17 00:00:00 2001 From: metab0t Date: Fri, 10 Jun 2022 17:58:36 +0800 Subject: [PATCH] Recover SQlite.isready for statemaent --- src/SQLite.jl | 3 +++ test/runtests.jl | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/SQLite.jl b/src/SQLite.jl index 529a532..121501b 100644 --- a/src/SQLite.jl +++ b/src/SQLite.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 7d04fb8..5b6289c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -852,10 +852,12 @@ 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 @@ -863,10 +865,12 @@ 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