-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstmt.go
More file actions
45 lines (37 loc) · 1.04 KB
/
stmt.go
File metadata and controls
45 lines (37 loc) · 1.04 KB
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
package sqlmock
import "database/sql/driver"
// Stmt implements driver.Stmt and delegates calls to the mock connection.
type Stmt struct {
query string
conn *Conn
}
// Close closes the prepared statement.
func (s *Stmt) Close() error {
return nil
}
// NumInput reports variable argument support for this statement.
func (s *Stmt) NumInput() int {
return -1
}
// Exec converts args into named values and delegates execution to the connection.
func (s *Stmt) Exec(args []driver.Value) (driver.Result, error) {
named := make([]driver.NamedValue, len(args))
for i, v := range args {
named[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.conn.ExecContext(nil, s.query, named)
}
// Query converts args into named values and delegates querying to the connection.
func (s *Stmt) Query(args []driver.Value) (driver.Rows, error) {
named := make([]driver.NamedValue, len(args))
for i, v := range args {
named[i] = driver.NamedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.conn.QueryContext(nil, s.query, named)
}