Skip to content

Commit 40794b1

Browse files
authored
Set busy_timeout (#218)
1 parent 484c9eb commit 40794b1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/SQLite.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,15 @@ function enable_load_extension(db, enable::Bool=true)
541541
ccall((:sqlite3_enable_load_extension, SQLite.libsqlite), Cint, (Ptr{Cvoid}, Cint), db.handle, enable)
542542
end
543543

544+
"""
545+
SQLite.busy_timeout(db, ms::Integer=0)
546+
547+
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.
548+
"""
549+
function busy_timeout(db, ms::Integer=0)
550+
sqlite3_busy_timeout(db.handle, ms)
551+
end
552+
553+
554+
544555
end # module

src/api.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ end
114114
# SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
115115
# SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
116116

117+
118+
# SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
119+
function sqlite3_busy_timeout(db::Ptr{Cvoid}, ms)
120+
@NULLCHECK db
121+
return ccall( (:sqlite3_busy_timeout, libsqlite),
122+
Cint, (Ptr{Cvoid}, Cint),
123+
db, ms)
124+
end
125+
117126
function sqlite3_clear_bindings(stmt::Ptr{Cvoid})
118127
return ccall( (:sqlite3_clear_bindings, libsqlite),
119128
Cint, (Ptr{Cvoid},),

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,7 @@ tbl3 = (c = [7, 8, 9], a = [4, 5, 6])
314314
@test_throws ErrorException SQLite.load!(tbl3, db, "data")
315315

316316

317+
# Test busy_timeout
318+
@test SQLite.busy_timeout(db, 300) == 0
319+
317320
end # @testset

0 commit comments

Comments
 (0)