1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | TEST_CASE("Test SHOW/DESCRIBE tables" , "[pragma]" ) { |
8 | unique_ptr<QueryResult> result; |
9 | DuckDB db(nullptr); |
10 | Connection con(db); |
11 | |
12 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i INTEGER, j INTEGER)" )); |
13 | REQUIRE_NO_FAIL(con.Query("CREATE VIEW v1 AS SELECT DATE '1992-01-01' AS k" )); |
14 | |
15 | // SHOW and DESCRIBE are aliases |
16 | result = con.Query("SHOW TABLES" ); |
17 | REQUIRE(CHECK_COLUMN(result, 0, {"integers" , "v1" })); |
18 | result = con.Query("DESCRIBE TABLES" ); |
19 | REQUIRE(CHECK_COLUMN(result, 0, {"integers" , "v1" })); |
20 | // internally they are equivalent to PRAGMA SHOW_TABLES(); |
21 | result = con.Query("PRAGMA show_tables" ); |
22 | REQUIRE(CHECK_COLUMN(result, 0, {"integers" , "v1" })); |
23 | |
24 | result = con.Query("SHOW integers" ); |
25 | // Field | Type | Null | Key | Default | Extra |
26 | REQUIRE(CHECK_COLUMN(result, 0, {"i" , "j" })); |
27 | REQUIRE(CHECK_COLUMN(result, 1, {"INTEGER" , "INTEGER" })); |
28 | REQUIRE(CHECK_COLUMN(result, 2, {"YES" , "YES" })); |
29 | REQUIRE(CHECK_COLUMN(result, 3, {Value(), Value()})); |
30 | REQUIRE(CHECK_COLUMN(result, 4, {Value(), Value()})); |
31 | REQUIRE(CHECK_COLUMN(result, 5, {Value(), Value()})); |
32 | // equivalent to PRAGMA SHOW('integers') |
33 | result = con.Query("PRAGMA SHOW('integers')" ); |
34 | // Field | Type | Null | Key | Default | Extra |
35 | REQUIRE(CHECK_COLUMN(result, 0, {"i" , "j" })); |
36 | REQUIRE(CHECK_COLUMN(result, 1, {"INTEGER" , "INTEGER" })); |
37 | REQUIRE(CHECK_COLUMN(result, 2, {"YES" , "YES" })); |
38 | REQUIRE(CHECK_COLUMN(result, 3, {Value(), Value()})); |
39 | REQUIRE(CHECK_COLUMN(result, 4, {Value(), Value()})); |
40 | REQUIRE(CHECK_COLUMN(result, 5, {Value(), Value()})); |
41 | |
42 | // we can also describe views |
43 | result = con.Query("DESCRIBE v1" ); |
44 | // Field | Type | Null | Key | Default | Extra |
45 | REQUIRE(CHECK_COLUMN(result, 0, {"k" })); |
46 | REQUIRE(CHECK_COLUMN(result, 1, {"DATE" })); |
47 | REQUIRE(CHECK_COLUMN(result, 2, {"YES" })); |
48 | REQUIRE(CHECK_COLUMN(result, 3, {Value()})); |
49 | REQUIRE(CHECK_COLUMN(result, 4, {Value()})); |
50 | REQUIRE(CHECK_COLUMN(result, 5, {Value()})); |
51 | } |
52 | |