Step, reset statements.

This commit is contained in:
Nuno Cruces
2023-01-17 15:01:30 +00:00
parent 469696867b
commit e59118d548
4 changed files with 33 additions and 4 deletions

8
api.go
View File

@@ -35,8 +35,10 @@ func newConn(module api.Module) *Conn {
close: getFun("sqlite3_close"),
prepare: getFun("sqlite3_prepare_v3"),
finalize: getFun("sqlite3_finalize"),
exec: getFun("sqlite3_exec"),
reset: getFun("sqlite3_reset"),
step: getFun("sqlite3_step"),
exec: getFun("sqlite3_exec"),
clearBindings: getFun("sqlite3_clear_bindings"),
bindInteger: getFun("sqlite3_bind_int64"),
bindFloat: getFun("sqlite3_bind_double"),
bindText: getFun("sqlite3_bind_text64"),
@@ -64,8 +66,10 @@ type sqliteAPI struct {
close api.Function
prepare api.Function
finalize api.Function
exec api.Function
reset api.Function
step api.Function
exec api.Function
clearBindings api.Function
bindInteger api.Function
bindFloat api.Function
bindText api.Function

View File

@@ -42,8 +42,10 @@ zig cc --target=wasm32-wasi -flto -g0 -O2 \
-Wl,--export=sqlite3_close \
-Wl,--export=sqlite3_prepare_v3 \
-Wl,--export=sqlite3_finalize \
-Wl,--export=sqlite3_exec \
-Wl,--export=sqlite3_reset \
-Wl,--export=sqlite3_step \
-Wl,--export=sqlite3_exec \
-Wl,--export=sqlite3_clear_bindings \
-Wl,--export=sqlite3_bind_int64 \
-Wl,--export=sqlite3_bind_double \
-Wl,--export=sqlite3_bind_text64 \

View File

@@ -152,7 +152,8 @@ func (c *Conn) error(rc uint64) error {
serr.msg = c.getString(uint32(r[0]), 512)
}
if serr.str == serr.msg {
switch serr.msg {
case "not an error", serr.str:
serr.msg = ""
}

22
stmt.go
View File

@@ -20,6 +20,28 @@ func (s *Stmt) Close() error {
return s.c.error(r[0])
}
func (s *Stmt) Reset() error {
r, err := s.c.api.reset.Call(context.TODO(), uint64(s.handle))
if err != nil {
return err
}
return s.c.error(r[0])
}
func (s *Stmt) Step() (row bool, err error) {
r, err := s.c.api.step.Call(context.TODO(), uint64(s.handle))
if err != nil {
return false, err
}
if r[0] == _ROW {
return true, nil
}
if r[0] == _DONE {
return false, nil
}
return false, s.c.error(r[0])
}
func (s *Stmt) BindBool(param int, value bool) error {
if value {
return s.BindInt64(param, 1)