Skip to content

Commit

Permalink
Set busy_timeout (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellemo authored Oct 7, 2020
1 parent 484c9eb commit 40794b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/SQLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,15 @@ function enable_load_extension(db, enable::Bool=true)
ccall((:sqlite3_enable_load_extension, SQLite.libsqlite), Cint, (Ptr{Cvoid}, Cint), db.handle, enable)
end

"""
SQLite.busy_timeout(db, ms::Integer=0)
Set a busy handler that sleeps for a specified amount of milliseconds when a table is locked. After at least ms milliseconds of sleeping, the handler will return 0, causing sqlite to return SQLITE_BUSY.
"""
function busy_timeout(db, ms::Integer=0)
sqlite3_busy_timeout(db.handle, ms)
end



end # module
9 changes: 9 additions & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ end
# SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
# SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);


# SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
function sqlite3_busy_timeout(db::Ptr{Cvoid}, ms)
@NULLCHECK db
return ccall( (:sqlite3_busy_timeout, libsqlite),
Cint, (Ptr{Cvoid}, Cint),
db, ms)
end

function sqlite3_clear_bindings(stmt::Ptr{Cvoid})
return ccall( (:sqlite3_clear_bindings, libsqlite),
Cint, (Ptr{Cvoid},),
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,7 @@ tbl3 = (c = [7, 8, 9], a = [4, 5, 6])
@test_throws ErrorException SQLite.load!(tbl3, db, "data")


# Test busy_timeout
@test SQLite.busy_timeout(db, 300) == 0

end # @testset

0 comments on commit 40794b1

Please sign in to comment.