1 | #include "catch.hpp" |
2 | #include "duckdb/common/file_system.hpp" |
3 | #include "test_helpers.hpp" |
4 | |
5 | using namespace duckdb; |
6 | using namespace std; |
7 | |
8 | TEST_CASE("Test storage of default values" , "[storage]" ) { |
9 | unique_ptr<QueryResult> result; |
10 | auto storage_database = TestCreatePath("storage_test" ); |
11 | auto config = GetTestConfig(); |
12 | |
13 | // make sure the database does not exist |
14 | DeleteDatabase(storage_database); |
15 | { |
16 | // create a database and insert values |
17 | DuckDB db(storage_database, config.get()); |
18 | Connection con(db); |
19 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE test (a INTEGER DEFAULT 1, b INTEGER);" )); |
20 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (11)" )); |
21 | } |
22 | // reload the database from disk |
23 | { |
24 | DuckDB db(storage_database, config.get()); |
25 | Connection con(db); |
26 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
27 | REQUIRE(CHECK_COLUMN(result, 0, {1})); |
28 | REQUIRE(CHECK_COLUMN(result, 1, {11})); |
29 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (12), (13)" )); |
30 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
31 | REQUIRE(CHECK_COLUMN(result, 0, {1, 1, 1})); |
32 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13})); |
33 | } |
34 | // reload the database from disk |
35 | { |
36 | DuckDB db(storage_database, config.get()); |
37 | Connection con(db); |
38 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
39 | REQUIRE(CHECK_COLUMN(result, 0, {1, 1, 1})); |
40 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13})); |
41 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (14), (15)" )); |
42 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
43 | REQUIRE(CHECK_COLUMN(result, 0, {1, 1, 1, 1, 1})); |
44 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13, 14, 15})); |
45 | } |
46 | DeleteDatabase(storage_database); |
47 | } |
48 | |
49 | TEST_CASE("Test storage of default values with sequences" , "[storage]" ) { |
50 | unique_ptr<QueryResult> result; |
51 | auto storage_database = TestCreatePath("storage_test" ); |
52 | auto config = GetTestConfig(); |
53 | |
54 | // make sure the database does not exist |
55 | DeleteDatabase(storage_database); |
56 | { |
57 | // create a database and insert values |
58 | DuckDB db(storage_database, config.get()); |
59 | Connection con(db); |
60 | REQUIRE_NO_FAIL(con.Query("CREATE SEQUENCE seq;" )); |
61 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE test (a INTEGER DEFAULT nextval('seq'), b INTEGER);" )); |
62 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (11)" )); |
63 | } |
64 | // reload the database from disk |
65 | { |
66 | DuckDB db(storage_database, config.get()); |
67 | Connection con(db); |
68 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
69 | REQUIRE(CHECK_COLUMN(result, 0, {1})); |
70 | REQUIRE(CHECK_COLUMN(result, 1, {11})); |
71 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (12), (13)" )); |
72 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
73 | REQUIRE(CHECK_COLUMN(result, 0, {1, 2, 3})); |
74 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13})); |
75 | } |
76 | // reload the database from disk |
77 | { |
78 | DuckDB db(storage_database, config.get()); |
79 | Connection con(db); |
80 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
81 | REQUIRE(CHECK_COLUMN(result, 0, {1, 2, 3})); |
82 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13})); |
83 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test (b) VALUES (14), (15)" )); |
84 | result = con.Query("SELECT * FROM test ORDER BY b" ); |
85 | REQUIRE(CHECK_COLUMN(result, 0, {1, 2, 3, 4, 5})); |
86 | REQUIRE(CHECK_COLUMN(result, 1, {11, 12, 13, 14, 15})); |
87 | } |
88 | DeleteDatabase(storage_database); |
89 | } |
90 | |