Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conn_go18.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (cn *conn) Ping(ctx context.Context) error {
if finish := cn.watchCancel(ctx); finish != nil {
defer finish()
}
rows, err := cn.simpleQuery("SELECT 'lib/pq ping test';")
rows, err := cn.simpleQuery(";")
if err != nil {
return driver.ErrBadConn // https://golang.org/pkg/database/sql/driver/#Pinger
}
Expand Down
7 changes: 7 additions & 0 deletions go19_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func TestPing(t *testing.T) {
if rows.Err() != nil {
t.Fatal(err)
}
// Fail the transaction and make sure we can still ping.
if _, err := tx.Query("INVALID SQL"); err == nil {
t.Fatal("expected error")
}
if err := conn.PingContext(ctx); err != nil {
t.Fatal(err)
}
if err := tx.Rollback(); err != nil {
t.Fatal(err)
}
Expand Down