本站源代码
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.

71 lines
1.9KB

  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 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. }
上海开阖软件有限公司 沪ICP备12045867号-1