diff --git a/api.go b/api.go index fd97206..62375d1 100644 --- a/api.go +++ b/api.go @@ -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 diff --git a/build_deps.sh b/build_deps.sh index 976698b..f0b999d 100755 --- a/build_deps.sh +++ b/build_deps.sh @@ -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 \ diff --git a/conn.go b/conn.go index d079e4e..a961c9c 100644 --- a/conn.go +++ b/conn.go @@ -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 = "" } diff --git a/stmt.go b/stmt.go index f6a6b52..ff5f489 100644 --- a/stmt.go +++ b/stmt.go @@ -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)