sqlite3_go18.go 1.8 KB

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