sqlite3_go18.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2019 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. //go:build cgo && go1.8
  6. // +build cgo,go1.8
  7. package sqlite3
  8. import (
  9. "database/sql/driver"
  10. "context"
  11. )
  12. // Ping implement Pinger.
  13. func (c *SQLiteConn) Ping(ctx context.Context) error {
  14. if c.db == nil {
  15. // must be ErrBadConn for sql to close the database
  16. return driver.ErrBadConn
  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. return c.query(ctx, query, args)
  23. }
  24. // ExecContext implement ExecerContext.
  25. func (c *SQLiteConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
  26. return c.exec(ctx, query, args)
  27. }
  28. // PrepareContext implement ConnPrepareContext.
  29. func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
  30. return c.prepare(ctx, query)
  31. }
  32. // BeginTx implement ConnBeginTx.
  33. func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
  34. return c.begin(ctx)
  35. }
  36. // QueryContext implement QueryerContext.
  37. func (s *SQLiteStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
  38. return s.query(ctx, args)
  39. }
  40. // ExecContext implement ExecerContext.
  41. func (s *SQLiteStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
  42. return s.exec(ctx, args)
  43. }