This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
/
connection_go18.go
78 lines (60 loc) · 2 KB
/
connection_go18.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// +build go1.8
package avatica
import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
)
func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if opts.ReadOnly {
return nil, errors.New("Read-only transactions are not supported")
}
var isolation isoLevel
switch sql.IsolationLevel(opts.Isolation) {
case sql.LevelDefault:
isolation = isolationUseCurrent
case sql.LevelReadUncommitted:
isolation = isolationReadUncommitted
case sql.LevelReadCommitted:
isolation = isolationReadComitted
case sql.LevelWriteCommitted:
return nil, errors.New("LevelWriteCommitted isolation level is not supported")
case sql.LevelRepeatableRead:
isolation = isolationRepeatableRead
case sql.LevelSnapshot:
return nil, errors.New("LevelSnapshot isolation level is not supported")
case sql.LevelSerializable:
isolation = isolationSerializable
case sql.LevelLinearizable:
return nil, errors.New("LevelLinearizable isolation level is not supported")
default:
return nil, fmt.Errorf("Unsupported transaction isolation level: %d", opts.Isolation)
}
return c.begin(ctx, isolation)
}
func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
return c.prepare(ctx, query)
}
func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
list, err := driverNamedValueToNamedValue(args)
if err != nil {
return nil, fmt.Errorf("could not execute statement: %s", err)
}
return c.exec(ctx, query, list)
}
func (c *conn) Ping(ctx context.Context) error {
_, err := c.ExecContext(ctx, "SELECT 1", []driver.NamedValue{})
if err != nil {
return fmt.Errorf("Error pinging database: %s", err)
}
return nil
}
func (c *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
list, err := driverNamedValueToNamedValue(args)
if err != nil {
return nil, fmt.Errorf("could not execute query: %s", err)
}
return c.query(ctx, query, list)
}