aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2016-11-03 23:05:34 +0900
committerYasuhiro Matsumoto <mattn.jp@gmail.com>2016-11-03 23:05:34 +0900
commit6796d46c3a2736edc88418f6de515c76e29f4aa9 (patch)
tree4c85190a9ed6e6f213b8664b3a70cfec1c82a114
parentremove -Wno-c99-extension (diff)
downloadgolite-6796d46c3a2736edc88418f6de515c76e29f4aa9.tar.gz
golite-6796d46c3a2736edc88418f6de515c76e29f4aa9.tar.xz
implement go18 Pinger
-rw-r--r--sqlite3_context.go14
-rw-r--r--sqlite3_test.go16
2 files changed, 30 insertions, 0 deletions
diff --git a/sqlite3_context.go b/sqlite3_context.go
new file mode 100644
index 0000000..26e4998
--- /dev/null
+++ b/sqlite3_context.go
@@ -0,0 +1,14 @@
+package sqlite3
+
+import (
+ "context"
+ "errors"
+)
+
+// Ping implement Pinger.
+func (c *SQLiteConn) Ping(ctx context.Context) error {
+ if c.db == nil {
+ return errors.New("Connection was closed")
+ }
+ return nil
+}
diff --git a/sqlite3_test.go b/sqlite3_test.go
index cf826dd..fc5c99c 100644
--- a/sqlite3_test.go
+++ b/sqlite3_test.go
@@ -1315,6 +1315,22 @@ func TestDeclTypes(t *testing.T) {
}
}
+func TestPinger(t *testing.T) {
+ db, err := sql.Open("sqlite3", ":memory:")
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = db.Ping()
+ if err != nil {
+ t.Fatal(err)
+ }
+ db.Close()
+ err = db.Ping()
+ if err == nil {
+ t.Fatal("Should be closed")
+ }
+}
+
var customFunctionOnce sync.Once
func BenchmarkCustomFunctions(b *testing.B) {