1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2024-11-24 08:12:13 +02:00
go-sqlxmock/statement_go18.go
Nikita Koryabkin 5a7ddb9845 added tests
2019-12-03 12:47:50 +03:00

27 lines
807 B
Go

// +build go1.8
package sqlmock
import (
"context"
"database/sql/driver"
)
// Deprecated: Drivers should implement ExecerContext instead.
func (stmt *statement) Exec(args []driver.Value) (driver.Result, error) {
return stmt.conn.ExecContext(context.Background(), stmt.query, convertValueToNamedValue(args))
}
// Deprecated: Drivers should implement StmtQueryContext instead (or additionally).
func (stmt *statement) Query(args []driver.Value) (driver.Rows, error) {
return stmt.conn.QueryContext(context.Background(), stmt.query, convertValueToNamedValue(args))
}
func convertValueToNamedValue(args []driver.Value) []driver.NamedValue {
namedArgs := make([]driver.NamedValue, len(args))
for i, v := range args {
namedArgs[i] = driver.NamedValue{Ordinal: i + 1, Value: v}
}
return namedArgs
}