File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ package sqlitex
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/agentio/sqlite/sqliteh"
7+ "github.com/agentio/sqlite/sqlitepool"
8+ )
9+
10+ type ExecOptions struct {
11+ Args []any
12+ ResultFunc func (stmt sqliteh.Stmt ) error
13+ }
14+
15+ func ExecuteTransient (conn * sqlitepool.Rx , query string , options * ExecOptions ) error {
16+ stmt := conn .Prepare (query )
17+ for i , a := range options .Args {
18+ switch v := a .(type ) {
19+ case nil :
20+ stmt .BindNull (i + 1 )
21+ case int64 :
22+ stmt .BindInt64 (i + 1 , v )
23+ case float64 :
24+ stmt .BindDouble (i + 1 , v )
25+ case string :
26+ stmt .BindText64 (i + 1 , v )
27+ case []byte :
28+ stmt .BindBlob64 (i , v )
29+ default :
30+ return fmt .Errorf ("unhandled type %T (fixme)" , a )
31+ }
32+ }
33+ running := true
34+ for running {
35+ if row , err := stmt .Step (nil ); err != nil {
36+ return err
37+ } else if ! row {
38+ running = false
39+ } else if options .ResultFunc != nil {
40+ err = options .ResultFunc (stmt )
41+ if err != nil {
42+ return err
43+ }
44+ }
45+ }
46+ return stmt .Reset ()
47+ }
You can’t perform that action at this time.
0 commit comments