mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-03 22:23:10 +00:00
switch to sqlite3_prepare_v3 and supply default prepFlags
for long-lived prepared statements in datastore/sqlite_datastore.nim use `prepFlags = SQLITE_PREPARE_PERSISTENT` closes #13
This commit is contained in:
parent
96695fed47
commit
fb5ce62532
@ -161,23 +161,27 @@ template open*(
|
|||||||
proc prepare*[Params, Res](
|
proc prepare*[Params, Res](
|
||||||
T: type SQLiteStmt[Params, Res],
|
T: type SQLiteStmt[Params, Res],
|
||||||
env: SQLite,
|
env: SQLite,
|
||||||
stmt: string): ?!T =
|
stmt: string,
|
||||||
|
prepFlags: cuint = 0): ?!T =
|
||||||
|
|
||||||
var
|
var
|
||||||
s: RawStmtPtr
|
s: RawStmtPtr
|
||||||
|
|
||||||
checkErr sqlite3_prepare_v2(env, stmt.cstring, stmt.len.cint, addr s, nil)
|
checkErr sqlite3_prepare_v3(
|
||||||
|
env, stmt.cstring, stmt.len.cint, prepFlags, addr s, nil)
|
||||||
|
|
||||||
success T(s)
|
success T(s)
|
||||||
|
|
||||||
template prepare*(
|
template prepare*(
|
||||||
env: SQLite,
|
env: SQLite,
|
||||||
q: string): RawStmtPtr =
|
q: string,
|
||||||
|
prepFlags: cuint = 0): RawStmtPtr =
|
||||||
|
|
||||||
var
|
var
|
||||||
s: RawStmtPtr
|
s: RawStmtPtr
|
||||||
|
|
||||||
checkErr sqlite3_prepare_v2(env, q.cstring, q.len.cint, addr s, nil)
|
checkErr sqlite3_prepare_v3(
|
||||||
|
env, q.cstring, q.len.cint, prepFlags, addr s, nil)
|
||||||
|
|
||||||
s
|
s
|
||||||
|
|
||||||
|
|||||||
@ -227,11 +227,17 @@ proc new*(
|
|||||||
if not readOnly:
|
if not readOnly:
|
||||||
checkExec(env.val, createStmtStr)
|
checkExec(env.val, createStmtStr)
|
||||||
|
|
||||||
deleteStmt = ? DeleteStmt.prepare(env.val, deleteStmtStr)
|
deleteStmt = ? DeleteStmt.prepare(
|
||||||
putStmt = ? PutStmt.prepare(env.val, putStmtStr)
|
env.val, deleteStmtStr, SQLITE_PREPARE_PERSISTENT)
|
||||||
|
|
||||||
containsStmt = ? ContainsStmt.prepare(env.val, containsStmtStr)
|
putStmt = ? PutStmt.prepare(
|
||||||
getStmt = ? GetStmt.prepare(env.val, getStmtStr)
|
env.val, putStmtStr, SQLITE_PREPARE_PERSISTENT)
|
||||||
|
|
||||||
|
containsStmt = ? ContainsStmt.prepare(
|
||||||
|
env.val, containsStmtStr, SQLITE_PREPARE_PERSISTENT)
|
||||||
|
|
||||||
|
getStmt = ? GetStmt.prepare(
|
||||||
|
env.val, getStmtStr, SQLITE_PREPARE_PERSISTENT)
|
||||||
|
|
||||||
# if a readOnly/existing database does not satisfy the expected schema
|
# if a readOnly/existing database does not satisfy the expected schema
|
||||||
# `pepare()` will fail and `new` will return an error with message
|
# `pepare()` will fail and `new` will return an error with message
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user