Skip to content

Commit ad412a1

Browse files
committed
A few useful additions
1 parent 6a370c2 commit ad412a1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/SQLite.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ sqliteprepare(db,sql,stmt,null) = @CHECK db sqlite3_prepare_v2(db.handle,sql,stm
8888
include("UDF.jl")
8989
export @sr_str, @register, register
9090

91+
"""
92+
`SQLite.clear!(stmt::SQLite.Stmt)`
93+
94+
clears any bound values to a prepared SQL statement.
95+
"""
96+
function clear!(stmt::Stmt)
97+
sqlite3_clear_bindings(stmt.handle)
98+
return
99+
end
100+
91101
"""
92102
`SQLite.bind!(stmt::SQLite.Stmt, values)`
93103
@@ -103,6 +113,13 @@ Additional methods exist for working individual SQL parameters:
103113
"""
104114
function bind! end
105115

116+
function bind!(stmt::Stmt, values::Tuple)
117+
nparams = sqlite3_bind_parameter_count(stmt.handle)
118+
@assert nparams == length(values) "you must provide values for all placeholders"
119+
for i in 1:nparams
120+
@inbounds bind!(stmt, i, values[i])
121+
end
122+
end
106123
function bind!(stmt::Stmt, values::Vector)
107124
nparams = sqlite3_bind_parameter_count(stmt.handle)
108125
@assert nparams == length(values) "you must provide values for all placeholders"

src/api.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ end
124124
# SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
125125
# SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
126126

127-
# SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
127+
function sqlite3_clear_bindings(stmt::Ptr{Void})
128+
return ccall( (:sqlite3_clear_bindings, sqlite3_lib),
129+
Cint, (Ptr{Void},),
130+
stmt)
131+
end
128132

129133
function sqlite3_step(stmt::Ptr{Void})
130134
return ccall( (:sqlite3_step, sqlite3_lib),

0 commit comments

Comments
 (0)