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