-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
11,507 additions
and
11,208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "duckdb/parser/statement/pragma_statement.hpp" | ||
#include "duckdb/parser/transformer.hpp" | ||
|
||
using namespace duckdb; | ||
using namespace std; | ||
|
||
unique_ptr<PragmaStatement> Transformer::TransformShow(PGNode *node) { | ||
// we transform SHOW x into PRAGMA SHOW('x') | ||
|
||
auto stmt = reinterpret_cast<PGVariableShowStmt *>(node); | ||
|
||
auto result = make_unique<PragmaStatement>(); | ||
auto &info = *result->info; | ||
|
||
if (string(stmt->name) == "tables") { | ||
// show all tables | ||
info.name = "show_tables"; | ||
info.pragma_type = PragmaType::NOTHING; | ||
} else { | ||
// show one specific table | ||
info.name = "show"; | ||
info.pragma_type = PragmaType::CALL; | ||
info.parameters.push_back(Value(stmt->name)); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "catch.hpp" | ||
#include "test_helpers.hpp" | ||
|
||
using namespace duckdb; | ||
using namespace std; | ||
|
||
TEST_CASE("Test SHOW/DESCRIBE tables", "[pragma]") { | ||
unique_ptr<QueryResult> result; | ||
DuckDB db(nullptr); | ||
Connection con(db); | ||
|
||
REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i INTEGER, j INTEGER)")); | ||
REQUIRE_NO_FAIL(con.Query("CREATE VIEW v1 AS SELECT DATE '1992-01-01' AS k")); | ||
|
||
// SHOW and DESCRIBE are aliases | ||
result = con.Query("SHOW TABLES"); | ||
REQUIRE(CHECK_COLUMN(result, 0, {"integers", "v1"})); | ||
result = con.Query("DESCRIBE TABLES"); | ||
REQUIRE(CHECK_COLUMN(result, 0, {"integers", "v1"})); | ||
// internally they are equivalent to PRAGMA SHOW_TABLES(); | ||
result = con.Query("PRAGMA show_tables"); | ||
REQUIRE(CHECK_COLUMN(result, 0, {"integers", "v1"})); | ||
|
||
result = con.Query("SHOW integers"); | ||
// Field | Type | Null | Key | Default | Extra | ||
REQUIRE(CHECK_COLUMN(result, 0, {"i", "j"})); | ||
REQUIRE(CHECK_COLUMN(result, 1, {"INTEGER", "INTEGER"})); | ||
REQUIRE(CHECK_COLUMN(result, 2, {"YES", "YES"})); | ||
REQUIRE(CHECK_COLUMN(result, 3, {Value(), Value()})); | ||
REQUIRE(CHECK_COLUMN(result, 4, {"NULL", "NULL"})); | ||
REQUIRE(CHECK_COLUMN(result, 5, {Value(), Value()})); | ||
// equivalent to PRAGMA SHOW('integers') | ||
result = con.Query("PRAGMA SHOW('integers')"); | ||
// Field | Type | Null | Key | Default | Extra | ||
REQUIRE(CHECK_COLUMN(result, 0, {"i", "j"})); | ||
REQUIRE(CHECK_COLUMN(result, 1, {"INTEGER", "INTEGER"})); | ||
REQUIRE(CHECK_COLUMN(result, 2, {"YES", "YES"})); | ||
REQUIRE(CHECK_COLUMN(result, 3, {Value(), Value()})); | ||
REQUIRE(CHECK_COLUMN(result, 4, {"NULL", "NULL"})); | ||
REQUIRE(CHECK_COLUMN(result, 5, {Value(), Value()})); | ||
|
||
// we can also describe views | ||
result = con.Query("DESCRIBE v1"); | ||
// Field | Type | Null | Key | Default | Extra | ||
REQUIRE(CHECK_COLUMN(result, 0, {"k"})); | ||
REQUIRE(CHECK_COLUMN(result, 1, {"DATE"})); | ||
REQUIRE(CHECK_COLUMN(result, 2, {"YES"})); | ||
REQUIRE(CHECK_COLUMN(result, 3, {Value()})); | ||
REQUIRE(CHECK_COLUMN(result, 4, {Value()})); | ||
REQUIRE(CHECK_COLUMN(result, 5, {Value()})); | ||
} |
Oops, something went wrong.