File: test_table_info.cpp

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (38 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (4)
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);
}