github.com/CanonicalLtd/go-sqlite3@v1.6.0/sqlite3_go18.go (about)

     1  // Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
     2  //
     3  // Use of this source code is governed by an MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  // +build go1.8
     7  
     8  package sqlite3
     9  
    10  import (
    11  	"database/sql/driver"
    12  	"errors"
    13  
    14  	"context"
    15  )
    16  
    17  // Ping implement Pinger.
    18  func (c *SQLiteConn) Ping(ctx context.Context) error {
    19  	if c.db == nil {
    20  		return errors.New("Connection was closed")
    21  	}
    22  	return nil
    23  }
    24  
    25  // QueryContext implement QueryerContext.
    26  func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
    27  	list := make([]namedValue, len(args))
    28  	for i, nv := range args {
    29  		list[i] = namedValue(nv)
    30  	}
    31  	return c.query(ctx, query, list)
    32  }
    33  
    34  // ExecContext implement ExecerContext.
    35  func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
    36  	list := make([]namedValue, len(args))
    37  	for i, nv := range args {
    38  		list[i] = namedValue(nv)
    39  	}
    40  	return c.exec(ctx, query, list)
    41  }
    42  
    43  // PrepareContext implement ConnPrepareContext.
    44  func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
    45  	return c.prepare(ctx, query)
    46  }
    47  
    48  // BeginTx implement ConnBeginTx.
    49  func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
    50  	return c.begin(ctx)
    51  }
    52  
    53  // QueryContext implement QueryerContext.
    54  func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
    55  	list := make([]namedValue, len(args))
    56  	for i, nv := range args {
    57  		list[i] = namedValue(nv)
    58  	}
    59  	return s.query(ctx, list)
    60  }
    61  
    62  // ExecContext implement ExecerContext.
    63  func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
    64  	list := make([]namedValue, len(args))
    65  	for i, nv := range args {
    66  		list[i] = namedValue(nv)
    67  	}
    68  	return s.exec(ctx, list)
    69  }