Commit e2dd408b authored by gwenn's avatar gwenn

Go 1.8: Ping and BeginTx

To be continued
parent eb1ee648
language: go language: go
sudo: false sudo: false
go: go:
- 1.7.4 - 1.8
- tip - tip
addons: addons:
apt: apt:
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
package sqlite package sqlite
import ( import (
"context"
"database/sql" "database/sql"
"database/sql/driver" "database/sql/driver"
"errors" "errors"
"fmt"
"io" "io"
"log" "log"
"os" "os"
...@@ -105,6 +107,14 @@ func Unwrap(db *sql.DB) *Conn { ...@@ -105,6 +107,14 @@ func Unwrap(db *sql.DB) *Conn {
return nil return nil
} }
func (c *conn) Ping(ctx context.Context) error {
if c.c.IsClosed() {
return driver.ErrBadConn
}
_, err := c.Exec("PRAGMA schema_verion", []driver.Value{})
return err
}
// PRAGMA schema_version may be used to detect when the database schema is altered // PRAGMA schema_version may be used to detect when the database schema is altered
func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) { func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
...@@ -157,6 +167,31 @@ func (c *conn) Begin() (driver.Tx, error) { ...@@ -157,6 +167,31 @@ func (c *conn) Begin() (driver.Tx, error) {
return c, nil return c, nil
} }
func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if c.c.IsClosed() {
return nil, driver.ErrBadConn
}
if !c.c.GetAutocommit() {
return nil, errors.New("Nested transcations are not supported")
}
if err := c.c.SetQueryOnly("", opts.ReadOnly); err != nil {
return nil, err
}
switch sql.IsolationLevel(opts.Isolation) {
case sql.LevelDefault, sql.LevelSerializable:
if err := c.c.FastExec("PRAGMA read_uncommitted=0"); err != nil {
return nil, err
}
case sql.LevelReadUncommitted:
if err := c.c.FastExec("PRAGMA read_uncommitted=1"); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("Isolation level %d is not supported.", opts.Isolation)
}
return c.Begin()
}
func (c *conn) Commit() error { func (c *conn) Commit() error {
return c.c.Commit() return c.c.Commit()
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment