MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestJDBCDatabaseMetaDataQueries

Function TestJDBCDatabaseMetaDataQueries

tests/integration/jdbc_test.go:191–249  ·  view source on GitHub ↗

TestJDBCDatabaseMetaDataQueries tests queries similar to what JDBC DatabaseMetaData methods generate (getTables, getSchemas, etc.).

(t *testing.T)

Source from the content-addressed store, hash-verified

189// TestJDBCDatabaseMetaDataQueries tests queries similar to what JDBC
190// DatabaseMetaData methods generate (getTables, getSchemas, etc.).
191func TestJDBCDatabaseMetaDataQueries(t *testing.T) {
192 // These are representative of what the PostgreSQL JDBC driver generates
193 // for DatabaseMetaData calls
194 metadataQueries := []struct {
195 name string
196 sql string
197 }{
198 {
199 "getTables",
200 `SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME,
201 CASE c.relkind WHEN 'r' THEN 'TABLE' WHEN 'v' THEN 'VIEW' END AS TABLE_TYPE
202 FROM pg_catalog.pg_class c
203 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
204 WHERE c.relkind IN ('r','v')
205 AND n.nspname NOT IN ('pg_catalog', 'information_schema')
206 ORDER BY TABLE_SCHEM, TABLE_NAME
207 LIMIT 20`,
208 },
209 {
210 "getSchemas",
211 `SELECT nspname AS TABLE_SCHEM, NULL AS TABLE_CATALOG
212 FROM pg_catalog.pg_namespace
213 WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'
214 ORDER BY TABLE_SCHEM`,
215 },
216 {
217 "getCatalogs",
218 `SELECT datname AS TABLE_CAT FROM pg_catalog.pg_database ORDER BY 1`,
219 },
220 {
221 "getTypeInfo",
222 `SELECT typname FROM pg_catalog.pg_type LIMIT 20`,
223 },
224 }
225
226 for _, q := range metadataQueries {
227 t.Run(q.name, func(t *testing.T) {
228 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
229 defer cancel()
230
231 conn := pgxConnect(t)
232 defer func() { _ = conn.Close(ctx) }()
233
234 rows, err := conn.Query(ctx, q.sql)
235 if err != nil {
236 t.Fatalf("Query failed: %v", err)
237 }
238 count := 0
239 for rows.Next() {
240 count++
241 }
242 if err := rows.Err(); err != nil {
243 t.Fatalf("Row iteration error: %v", err)
244 }
245 rows.Close()
246 t.Logf("%s returned %d rows", q.name, count)
247 })
248 }

Callers

nothing calls this directly

Calls 6

pgxConnectFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected