MCPcopy
hub / github.com/jackc/pgx / ensureDBValid

Function ensureDBValid

stdlib/sql_test.go:115–137  ·  view source on GitHub ↗

Do a simple query to ensure the DB is still usable. This is of less use in stdlib as the connection pool should cover broken connections.

(t testing.TB, db *sql.DB)

Source from the content-addressed store, hash-verified

113// Do a simple query to ensure the DB is still usable. This is of less use in stdlib as the connection pool should
114// cover broken connections.
115func ensureDBValid(t testing.TB, db *sql.DB) {
116 var sum, rowCount int32
117
118 rows, err := db.Query("select generate_series(1,$1)", 10)
119 require.NoError(t, err)
120 defer rows.Close()
121
122 for rows.Next() {
123 var n int32
124 rows.Scan(&n)
125 sum += n
126 rowCount++
127 }
128
129 require.NoError(t, rows.Err())
130
131 if rowCount != 10 {
132 t.Error("Select called onDataRow wrong number of times")
133 }
134 if sum != 55 {
135 t.Error("Wrong values returned")
136 }
137}
138
139type preparer interface {
140 Prepare(query string) (*sql.Stmt, error)

Callers 9

TestSQLOpenFromPoolFunction · 0.85
TestNormalLifeCycleFunction · 0.85
TestStmtExecFunction · 0.85
TestQueryCloseRowsEarlyFunction · 0.85

Calls 6

QueryMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected