doc.go: you can use Conn.Raw to get *SQLiteConn (#882)

This can be easier that registering a new driver, in some cases.
Add a test to verify that this works.
This commit is contained in:
Evan Jones
2020-11-16 09:42:00 -05:00
committed by GitHub
parent 784c625194
commit 4f7abea96e
2 changed files with 43 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ package sqlite3
import (
"bytes"
"context"
"database/sql"
"database/sql/driver"
"errors"
@@ -2352,3 +2353,32 @@ func benchmarkStmtRows(b *testing.B) {
}
}
}
func TestConnRawIsSQLiteConn(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatal("Failed to open db:", err)
}
defer db.Close()
conn, err := db.Conn(context.Background())
if err != nil {
t.Fatal("Failed to get conn:", err)
}
defer conn.Close()
err = conn.Raw(func(driverConn interface{}) error {
sqliteConn, ok := driverConn.(*SQLiteConn)
if !ok {
t.Errorf("driverConn type=%T; expected to be *SQLiteConn", driverConn)
return nil
}
// call a private SQLite API to confirm the raw conn "works"
if sqliteConn.AuthEnabled() {
t.Error("sqliteConn.AuthEnabled()=true; expected false")
}
return nil
})
if err != nil {
t.Error("conn.Raw() returned err:", err)
}
}