-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstmt.go
61 lines (52 loc) · 1.33 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
61
package mysqlx
import (
"context"
"database/sql/driver"
"github.com/renthraysk/mysqlx/msg"
)
type stmt struct {
c *conn
id uint32
}
func (s *stmt) Close() error {
if s.c == nil {
return nil
}
m := msg.NewDeallocate(s.c.buf[:0], s.id)
_, err := s.c.execMsg(context.Background(), m)
s.c = nil
return err
}
func (s *stmt) NumInput() int {
return -1
}
// Exec forced deprecated implementation by database/sql Stmt interface
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
e, err := msg.NewExecute(s.c.buf[:0], s.id, args)
if err != nil {
return nil, err
}
return s.c.execMsg(context.Background(), e)
}
func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
e, err := msg.NewExecuteNamed(s.c.buf[:0], s.id, args)
if err != nil {
return nil, err
}
return s.c.execMsg(ctx, e)
}
// Query forced deprecated implementation by database/sql Stmt interface
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
e, err := msg.NewExecute(s.c.buf[:0], s.id, args)
if err != nil {
return nil, err
}
return s.c.queryMsg(context.Background(), e)
}
func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
q, err := msg.NewExecuteNamed(s.c.buf[:0], s.id, args)
if err != nil {
return nil, err
}
return s.c.queryMsg(ctx, q)
}