porting query tests

This commit is contained in:
Jaremy Creechley 2023-09-21 19:19:29 -07:00
parent d6d5978d5c
commit 0971986863
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 19 additions and 11 deletions

View File

@ -38,7 +38,7 @@ proc `$`*(id: KeyId): string = $(id.data)
proc new*(tp: typedesc[KeyId], id: cstring): KeyId =
## copy cstring including null terminator
KeyId(data: DataBuffer.new(id.pointer, 0, id.len()))
KeyId(data: DataBuffer.new(id.toOpenArray(0, id.len()-1), {dbNullTerminate}))
proc new*(tp: typedesc[KeyId], id: string): KeyId =
## copy cstring including null terminator

View File

@ -208,7 +208,9 @@ proc query*(
let
dataLen = sqlite3_column_bytes(s, QueryStmtDataCol)
data =
if blob.isSome: DataBuffer.new(blob.get(), 0, dataLen - 1)
if blob.isSome:
let arr = cast[ptr UncheckedArray[byte]](blob)
DataBuffer.new(arr.toOpenArray(0, dataLen-1))
else: DataBuffer.new(0)
echo "SQLITE ROW: yield"

View File

@ -40,13 +40,6 @@ proc `[]`*(db: DataBuffer, idx: int): var byte =
raise newException(IndexDefect, "index out of bounds")
db[].buf[idx]
proc `==`*(a, b: DataBuffer): bool =
if a.isNil and b.isNil: return true
elif a.isNil or b.isNil: return false
elif a[].size != b[].size: return false
elif a[].buf == b[].buf: return true
else: a.hash() == b.hash()
template `==`*[T: char | byte](a: DataBuffer, b: openArray[T]): bool =
if a.isNil: false
elif a[].size != b.len: false
@ -73,8 +66,8 @@ proc new*[T: byte | char](tp: type DataBuffer, data: openArray[T], opts: set[Dat
copyMem(result[].buf, baseAddr data, data.len())
result[].size = data.len()
proc new*(tp: type DataBuffer, data: pointer, first, last: int): DataBuffer =
DataBuffer.new(toOpenArray(cast[ptr UncheckedArray[byte]](data), first, last))
# proc new*(tp: type DataBuffer, data: pointer, first, last: int): DataBuffer =
# DataBuffer.new(toOpenArray(cast[ptr UncheckedArray[byte]](data), first, last))
proc baseAddr*(db: DataBuffer): pointer =
db[].buf
@ -122,6 +115,19 @@ proc `$`*(data: DataBuffer): string =
data.toString()
proc `==`*(a, b: DataBuffer): bool =
echo "DB == ", a.toString, " ", b.toString
echo "DB == len: ", a.len, " ", b.len
echo "DB == size: ", a[].size, " ", b[].size
echo "DB == cap: ", a[].cap, " ", b[].cap
echo "DB == ", a[].buf.pointer.repr, " ", b[].buf.pointer.repr
echo "DB == ", a[].hash, " ", b[].hash
if a.isNil and b.isNil: return true
elif a.isNil or b.isNil: return false
elif a[].size != b[].size: return false
elif a[].buf == b[].buf: return true
else: a.hash() == b.hash()
converter toBuffer*(err: ref CatchableError): DataBuffer =
## convert exception to an object with StringBuffer
##