Work on prepared statements.
(Still not working 100%, but getting close.) Additionally, start on the README, fix some type member visibility, add some additional tests, tag some FIXMEs for where type conversions will take place, and add `#rewind` for the query iterator. FossilOrigin-Name: 490f27a4792d5243d82d90dcb12be1074c945c74d7fa63dd5baaf942ac42d7c9
This commit is contained in:
parent
7850a79372
commit
6d34b081bb
10 changed files with 344 additions and 14 deletions
23
tests/queries/t_can_prepare_a_statement.nim
Normal file
23
tests/queries/t_can_prepare_a_statement.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# vim: set et sta sw=4 ts=4 :
|
||||
|
||||
discard """
|
||||
output: "d.thing\nCamel\nLampshade\nDelicious Cake\n"
|
||||
"""
|
||||
|
||||
import kuzu
|
||||
|
||||
let db = newKuzuDatabase()
|
||||
let conn = db.connect
|
||||
|
||||
var q = conn.query( "CREATE NODE TABLE Doop ( id SERIAL, thing STRING, PRIMARY KEY(id) )" )
|
||||
|
||||
var p = conn.prepare( "CREATE (d:Doop {thing: $thing})" )
|
||||
assert typeOf( p ) is KuzuPreparedStatement
|
||||
|
||||
for thing in @[ "Camel", "Lampshade", "Delicious Cake" ]:
|
||||
q = p.execute( (thing: thing) )
|
||||
assert typeOf( q ) is KuzuQueryResult
|
||||
|
||||
q = conn.query( "MATCH (d:Doop) RETURN d.thing" )
|
||||
echo $q
|
||||
|
||||
23
tests/queries/t_can_rewind_iteration.nim
Normal file
23
tests/queries/t_can_rewind_iteration.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# vim: set et sta sw=4 ts=4 :
|
||||
|
||||
discard """
|
||||
output: "Camel\nLampshade\nCamel\nLampshade\n"
|
||||
"""
|
||||
|
||||
import kuzu
|
||||
|
||||
let db = newKuzuDatabase()
|
||||
let conn = db.connect
|
||||
|
||||
var q = conn.query( "CREATE NODE TABLE Doop ( id SERIAL, thing STRING, PRIMARY KEY(id) )" )
|
||||
|
||||
for thing in @[ "Camel", "Lampshade" ]:
|
||||
q = conn.query( "CREATE (d:Doop {thing: '" & thing & "'})" )
|
||||
|
||||
for tpl in conn.query( "MATCH (d:Doop) RETURN d.thing" ):
|
||||
echo $tpl
|
||||
|
||||
q.rewind
|
||||
|
||||
for tpl in conn.query( "MATCH (d:Doop) RETURN d.thing" ):
|
||||
echo $tpl
|
||||
20
tests/queries/t_raises_on_unknown_varbind.nim
Normal file
20
tests/queries/t_raises_on_unknown_varbind.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# vim: set et sta sw=4 ts=4 :
|
||||
|
||||
import
|
||||
std/re
|
||||
import kuzu
|
||||
|
||||
let db = newKuzuDatabase()
|
||||
let conn = db.connect
|
||||
|
||||
var q = conn.query( "CREATE NODE TABLE Doop ( id SERIAL, thing STRING, PRIMARY KEY(id) )" )
|
||||
|
||||
var p = conn.prepare( "CREATE (d:Doop {thing: $thing})" )
|
||||
assert typeOf( p ) is KuzuPreparedStatement
|
||||
|
||||
try:
|
||||
discard p.execute( (nope: "undefined var in statement!") )
|
||||
except KuzuQueryException as err:
|
||||
assert err.msg.contains( re"""Parameter nope not found.""" )
|
||||
|
||||
|
||||
20
tests/queries/t_raises_with_invalid_prepared_statement.nim
Normal file
20
tests/queries/t_raises_with_invalid_prepared_statement.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# vim: set et sta sw=4 ts=4 :
|
||||
|
||||
import
|
||||
std/re
|
||||
import kuzu
|
||||
|
||||
let db = newKuzuDatabase()
|
||||
let conn = db.connect
|
||||
|
||||
var q = conn.query( "CREATE NODE TABLE Doop ( id SERIAL, thing STRING, PRIMARY KEY(id) )" )
|
||||
|
||||
var p = conn.prepare( "CREAET (d:Doop {thing: $thing})" )
|
||||
assert typeOf( p ) is KuzuPreparedStatement
|
||||
|
||||
try:
|
||||
discard p.execute
|
||||
except KuzuQueryException as err:
|
||||
assert err.msg.contains( re""".*Error executing prepared statement:.*CREAET""" )
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue