2017-07-06 08:43:30 +02:00
|
|
|
// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by an MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-10-23 07:28:10 +02:00
|
|
|
// +build cgo
|
2017-07-06 08:43:30 +02:00
|
|
|
// +build go1.8
|
|
|
|
|
|
|
|
package sqlite3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ping implement Pinger.
|
|
|
|
func (c *SQLiteConn) Ping(ctx context.Context) error {
|
|
|
|
if c.db == nil {
|
2019-08-23 18:40:30 +02:00
|
|
|
// must be ErrBadConn for sql to close the database
|
|
|
|
return driver.ErrBadConn
|
2017-07-06 08:43:30 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryContext implement QueryerContext.
|
|
|
|
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
|
|
|
|
list := make([]namedValue, len(args))
|
|
|
|
for i, nv := range args {
|
|
|
|
list[i] = namedValue(nv)
|
|
|
|
}
|
|
|
|
return c.query(ctx, query, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecContext implement ExecerContext.
|
|
|
|
func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
|
|
|
|
list := make([]namedValue, len(args))
|
|
|
|
for i, nv := range args {
|
|
|
|
list[i] = namedValue(nv)
|
|
|
|
}
|
|
|
|
return c.exec(ctx, query, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrepareContext implement ConnPrepareContext.
|
|
|
|
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
|
|
|
|
return c.prepare(ctx, query)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BeginTx implement ConnBeginTx.
|
|
|
|
func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
|
|
|
|
return c.begin(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryContext implement QueryerContext.
|
|
|
|
func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
|
|
|
|
list := make([]namedValue, len(args))
|
|
|
|
for i, nv := range args {
|
|
|
|
list[i] = namedValue(nv)
|
|
|
|
}
|
|
|
|
return s.query(ctx, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecContext implement ExecerContext.
|
|
|
|
func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
|
|
|
|
list := make([]namedValue, len(args))
|
|
|
|
for i, nv := range args {
|
|
|
|
list[i] = namedValue(nv)
|
|
|
|
}
|
|
|
|
return s.exec(ctx, list)
|
|
|
|
}
|