You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlite3_go18.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // +build cgo
  6. // +build 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. 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. }