sqlite3_go18.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // +build go1.8
  6. package sqlite3
  7. import (
  8. "database/sql/driver"
  9. "errors"
  10. "context"
  11. )
  12. // Ping implement Pinger.
  13. func (c *SQLiteConn) Ping(ctx context.Context) error {
  14. if c.db == nil {
  15. return errors.New("Connection was closed")
  16. }
  17. return nil
  18. }
  19. // QueryContext implement QueryerContext.
  20. func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
  21. list := make([]namedValue, len(args))
  22. for i, nv := range args {
  23. list[i] = namedValue(nv)
  24. }
  25. return c.query(ctx, query, list)
  26. }
  27. // ExecContext implement ExecerContext.
  28. func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
  29. list := make([]namedValue, len(args))
  30. for i, nv := range args {
  31. list[i] = namedValue(nv)
  32. }
  33. return c.exec(ctx, query, list)
  34. }
  35. // PrepareContext implement ConnPrepareContext.
  36. func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
  37. return c.prepare(ctx, query)
  38. }
  39. // BeginTx implement ConnBeginTx.
  40. func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
  41. return c.begin(ctx)
  42. }
  43. // QueryContext implement QueryerContext.
  44. func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
  45. list := make([]namedValue, len(args))
  46. for i, nv := range args {
  47. list[i] = namedValue(nv)
  48. }
  49. return s.query(ctx, list)
  50. }
  51. // ExecContext implement ExecerContext.
  52. func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
  53. list := make([]namedValue, len(args))
  54. for i, nv := range args {
  55. list[i] = namedValue(nv)
  56. }
  57. return s.exec(ctx, list)
  58. }