-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstmt.go
43 lines (37 loc) · 1.35 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
package mssqlx
import (
"context"
"database/sql"
)
// Stmt wraps over sql.Stmt
type Stmt struct {
*sql.Stmt
}
// Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (s *Stmt) Exec(args ...interface{}) (sql.Result, error) {
return s.ExecContext(context.Background(), args...)
}
// ExecContext executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (result sql.Result, err error) {
r, err := retryFunc("stmt_exec", func() (interface{}, error) {
return s.Stmt.ExecContext(ctx, args...)
})
if err == nil {
result = r.(sql.Result)
}
return
}
// Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmt) Query(args ...interface{}) (*sql.Rows, error) {
return s.QueryContext(context.Background(), args...)
}
// QueryContext executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (result *sql.Rows, err error) {
r, err := retryFunc("stmt_query", func() (interface{}, error) {
return s.Stmt.QueryContext(ctx, args...)
})
if err == nil {
result = r.(*sql.Rows)
}
return
}