1#include "catch.hpp"
2#include "test_helpers.hpp"
3
4using namespace duckdb;
5using namespace std;
6
7TEST_CASE("Test table info api", "[api]") {
8 DuckDB db(nullptr);
9 Connection con(db), con2(db);
10
11 //! table is not found!
12 auto info = con.TableInfo("test");
13 REQUIRE(info.get() == nullptr);
14
15 // after creating, the table can be found
16 REQUIRE_NO_FAIL(con.Query("CREATE TABLE test(i INTEGER)"));
17 info = con.TableInfo("test");
18 REQUIRE(info.get() != nullptr);
19 REQUIRE(info->table == "test");
20 REQUIRE(info->columns.size() == 1);
21 REQUIRE(info->columns[0].name == "i");
22
23 // table info is transaction sensitive
24 REQUIRE_NO_FAIL(con.Query("BEGIN TRANSACTION"));
25 // dropping the table in a transaction will result in the table being gone
26 REQUIRE_NO_FAIL(con.Query("DROP TABLE test"));
27 info = con.TableInfo("test");
28 REQUIRE(info.get() == nullptr);
29
30 // but not in a separate connection!
31 info = con2.TableInfo("test");
32 REQUIRE(info.get() != nullptr);
33
34 // rolling back brings back the table info again
35 REQUIRE_NO_FAIL(con.Query("ROLLBACK"));
36 info = con.TableInfo("test");
37 REQUIRE(info.get() != nullptr);
38}
39