Skip to content

Commit 3d05797

Browse files
committed
minor fix
1 parent e4565b3 commit 3d05797

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/easy_sqlite3/bindings.nim

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,10 @@ proc getParameterIndex*(st: ref Statement, name: string): int =
446446
if result == 0:
447447
raise newException(SQLiteError, "Unknown parameter " & name)
448448
449+
{.push inline.}
450+
449451
proc `[]=`*(st: ref Statement, idx: int, blob: openarray[byte]) =
450-
st.raw.check_sqlite_stmt sqlite3_bind_blob64(st.raw, idx, blob.unsafeAddr,
451-
blob.len, TransientDestructor)
452+
st.raw.check_sqlite_stmt sqlite3_bind_blob64(st.raw, idx, blob.unsafeAddr, blob.len, TransientDestructor)
452453
453454
proc `[]=`*(st: ref Statement, idx: int, val: SomeFloat) =
454455
st.raw.check_sqlite_stmt sqlite3_bind_double(st.raw, idx, float64 val)
@@ -465,7 +466,7 @@ proc `[]=`*(st: ref Statement, idx: int, val: string) =
465466
proc reset*(st: ref Statement) =
466467
st.raw.check_sqlite_stmt sqlite3_reset(st.raw)
467468
468-
proc step*(st: ref Statement): bool =
469+
proc step*(st: ref Statement): bool {.inline.} =
469470
let res = sqlite3_step(st.raw)
470471
case res:
471472
of sr_row: true
@@ -489,12 +490,10 @@ proc getColumn*(st: ref Statement, idx: int, T: typedesc[seq[byte]]): seq[byte]
489490
result = newSeq[byte]l
490491
copyMem(addr result[0], p, l)
491492

492-
proc getColumn*(st: ref Statement, idx: int, T: typedesc[
493-
SomeFloat]): SomeFloat =
493+
proc getColumn*(st: ref Statement, idx: int, T: typedesc[SomeFloat]): SomeFloat =
494494
cast[T](sqlite3_column_double(st.raw, idx))
495495
496-
proc getColumn*(st: ref Statement, idx: int, T: typedesc[
497-
SomeOrdinal]): SomeOrdinal =
496+
proc getColumn*(st: ref Statement, idx: int, T: typedesc[SomeOrdinal]): SomeOrdinal =
498497
cast[T](sqlite3_column_int64(st.raw, idx))
499498
500499
proc getColumn*(st: ref Statement, idx: int, T: typedesc[string]): string =
@@ -515,6 +514,8 @@ proc unpack*[T: tuple](st: ref Statement, _: typedesc[T]): T =
515514
value = st.getColumn(idx, type(value))
516515
idx.inc
517516
517+
{.pop.}
518+
518519
proc exec*(db: var Database, sql: string): int {.discardable.} =
519520
var st = db.fetchStatement(sql)
520521
defer: st.reset()

tests/test_basic.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ test "full":
3333
db.create_table()
3434
for name, value in dataset:
3535
db.insert_data name, value
36+
db.exec "VACUUM"
3637
for name, value in db.iterate_data():
3738
check name in dataset
3839
check dataset[name] == value

tests/test_thread.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ proc connectDatabase(): Database =
2828

2929
var gdb = connectDatabase()
3030
gdb.create_table()
31+
gdb.exec "VACUUM"
3132

3233
const COUNT = 100000
3334

@@ -38,7 +39,7 @@ proc worker_fn() {.thread.} =
3839
for _ in 0..<COUNT:
3940
let val = r.rand(1048576)
4041
# increase the chance of collision
41-
if val < 1024:
42+
if val > 1024:
4243
sleep(1)
4344
when useMemFs:
4445
tdb.insert_data(val)

0 commit comments

Comments
 (0)