| 1 | #include "catch.hpp" |
|---|---|
| 2 | #include "test_helpers.hpp" |
| 3 | |
| 4 | using namespace duckdb; |
| 5 | using namespace std; |
| 6 | |
| 7 | TEST_CASE("Test various errors in catalog management", "[catalog]") { |
| 8 | unique_ptr<QueryResult> result; |
| 9 | DuckDB db(nullptr); |
| 10 | Connection con(db); |
| 11 | |
| 12 | // create a table called integers |
| 13 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE integers(i INTEGER);")); |
| 14 | // create a view called vintegers |
| 15 | REQUIRE_NO_FAIL(con.Query("CREATE VIEW vintegers AS SELECT 42;")); |
| 16 | |
| 17 | // cannot replace table with CREATE OR REPLACE VIEW |
| 18 | REQUIRE_FAIL(con.Query("CREATE OR REPLACE VIEW integers AS SELECT 42;")); |
| 19 | // cannot drop a table with DROP VIEW |
| 20 | REQUIRE_FAIL(con.Query("DROP VIEW integers")); |
| 21 | |
| 22 | // cannot drop a table that does not exist |
| 23 | REQUIRE_FAIL(con.Query("DROP TABLE blabla")); |
| 24 | // cannot alter a table that does not exist |
| 25 | REQUIRE_FAIL(con.Query("ALTER TABLE blabla RENAME COLUMN i TO k")); |
| 26 | // cannot drop view with DROP TABLE |
| 27 | REQUIRE_FAIL(con.Query("DROP TABLE IF EXISTS vintegers")); |
| 28 | |
| 29 | // create index on i |
| 30 | REQUIRE_NO_FAIL(con.Query("CREATE INDEX i_index ON integers(i);")); |
| 31 | // create the same index again, this time it already exists |
| 32 | REQUIRE_FAIL(con.Query("CREATE INDEX i_index ON integers(i);")); |
| 33 | // with IF NOT EXISTS it should not fail! |
| 34 | REQUIRE_NO_FAIL(con.Query("CREATE INDEX IF NOT EXISTS i_index ON integers(i);")); |
| 35 | // drop the index |
| 36 | REQUIRE_NO_FAIL(con.Query("DROP INDEX i_index")); |
| 37 | // cannot drop the index again: it no longer exists |
| 38 | REQUIRE_FAIL(con.Query("DROP INDEX i_index")); |
| 39 | // IF NOT EXISTS does not report a failure |
| 40 | REQUIRE_NO_FAIL(con.Query("DROP INDEX IF EXISTS i_index")); |
| 41 | } |
| 42 |