Commit 96e70462 authored by gwenn's avatar gwenn

Remove old (go 1.7) code

parent 9f7bc846
...@@ -15,5 +15,5 @@ install: ...@@ -15,5 +15,5 @@ install:
before_script: before_script:
- go get github.com/bmizerany/assert - go get github.com/bmizerany/assert
script: script:
- GODEBUG=cgocheck=2 go test -v -tags all github.com/gwenn/gosqlite # - GODEBUG=cgocheck=2 go test -v -tags all github.com/gwenn/gosqlite
- GODEBUG=cgocheck=0 go test -v -tags all github.com/gwenn/gosqlite - GODEBUG=cgocheck=0 go test -v -tags all github.com/gwenn/gosqlite
...@@ -15,7 +15,6 @@ import ( ...@@ -15,7 +15,6 @@ import (
"os" "os"
"reflect" "reflect"
"time" "time"
"unsafe"
) )
func init() { func init() {
...@@ -112,53 +111,21 @@ func (c *conn) Ping(ctx context.Context) error { ...@@ -112,53 +111,21 @@ func (c *conn) Ping(ctx context.Context) error {
if c.c.IsClosed() { if c.c.IsClosed() {
return driver.ErrBadConn return driver.ErrBadConn
} }
_, err := c.Exec("PRAGMA schema_verion", []driver.Value{}) _, err := c.ExecContext(ctx, "PRAGMA schema_verion", []driver.NamedValue{})
return err 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) {
if c.c.IsClosed() { panic("ExecContext was not called.")
return nil, driver.ErrBadConn
}
if len(args) == 0 {
if query == "unwrap" {
return nil, ConnError{c: c.c}
}
if err := c.c.FastExec(query); err != nil {
return nil, err
}
return c.c.result(), nil
}
// https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices
var iargs []interface{}
h := (*reflect.SliceHeader)(unsafe.Pointer(&iargs))
h.Data = uintptr(unsafe.Pointer(&args[0]))
h.Len = len(args)
h.Cap = cap(args)
if err := c.c.Exec(query, iargs...); err != nil {
return nil, err
}
return c.c.result(), nil
} }
func (c *conn) Prepare(query string) (driver.Stmt, error) { func (c *conn) Prepare(query string) (driver.Stmt, error) {
if c.c.IsClosed() { panic("use PrepareContext")
return nil, driver.ErrBadConn
}
s, err := c.c.Prepare(query)
if err != nil {
return nil, err
}
return &stmt{s: s}, nil
} }
func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { func (c *conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
return c.Prepare(query)
}
func (c *conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
if c.c.IsClosed() { if c.c.IsClosed() {
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
...@@ -166,8 +133,7 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam ...@@ -166,8 +133,7 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam
if err != nil { if err != nil {
return nil, err return nil, err
} }
st := stmt{s: s} return &stmt{s: s}, nil
return st.QueryContext(ctx, args)
} }
func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { func (c *conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
...@@ -277,24 +243,11 @@ func (s *stmt) NumInput() int { ...@@ -277,24 +243,11 @@ func (s *stmt) NumInput() int {
} }
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
if err := s.bind(args); err != nil { panic("Using ExecContext")
return nil, err
}
if err := s.s.exec(); err != nil {
return nil, err
}
return s.s.c.result(), nil
} }
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
if s.rowsRef { panic("Use QueryContext")
return nil, errors.New("previously returned Rows still not closed")
}
if err := s.bind(args); err != nil {
return nil, err
}
s.rowsRef = true
return &rowsImpl{s, nil, nil}, nil
} }
func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
...@@ -310,6 +263,9 @@ func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive ...@@ -310,6 +263,9 @@ func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive
} }
func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { func (s *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
if s.rowsRef {
return nil, errors.New("previously returned Rows still not closed")
}
if err := s.s.bindNamedValue(args); err != nil { if err := s.s.bindNamedValue(args); err != nil {
return nil, err return nil, err
} }
......
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