-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstmt.go
60 lines (48 loc) · 1.3 KB
/
stmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package sqlite3native
import (
"context"
"database/sql/driver"
"github.com/colinking/go-sqlite3-native/internal/vm"
)
type Stmt struct {
conn *Conn
program vm.Program
}
var _ driver.Stmt = &Stmt{}
var _ driver.StmtQueryContext = &Stmt{}
var _ driver.StmtExecContext = &Stmt{}
func (s *Stmt) Query(args []driver.Value) (driver.Rows, error) {
namedValues := make([]driver.NamedValue, len(args))
for i, v := range args {
namedValues[i] = driver.NamedValue{
Ordinal: i + 1, // 1-indexed
Value: v,
}
}
return s.QueryContext(context.Background(), namedValues)
}
func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
return &Rows{
program: s.program,
execution: s.conn.vm.Execute(s.program),
}, nil
}
func (s *Stmt) Exec(args []driver.Value) (driver.Result, error) {
namedValues := make([]driver.NamedValue, len(args))
for i, v := range args {
namedValues[i] = driver.NamedValue{
Ordinal: i + 1, // 1-indexed
Value: v,
}
}
return s.ExecContext(context.Background(), namedValues)
}
func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
panic("ExecContext not implemented")
}
func (s *Stmt) NumInput() int {
return s.program.NumPlaceholders
}
func (s *Stmt) Close() error {
return nil
}