1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | TEST_CASE("Test basic TIME functionality" , "[time]" ) { |
8 | unique_ptr<QueryResult> result; |
9 | DuckDB db(nullptr); |
10 | Connection con(db); |
11 | con.EnableQueryVerification(); |
12 | |
13 | // create and insert into table |
14 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE times(i TIME)" )); |
15 | REQUIRE_NO_FAIL(con.Query( |
16 | "INSERT INTO times VALUES ('00:01:20'), ('20:08:10.998'), ('20:08:10.33'), ('20:08:10.001'), (NULL)" )); |
17 | |
18 | // check that we can select times |
19 | result = con.Query("SELECT * FROM times" ); |
20 | REQUIRE(result->sql_types[0] == SQLType::TIME); |
21 | REQUIRE(CHECK_COLUMN(result, 0, |
22 | {Value::TIME(0, 1, 20, 0), Value::TIME(20, 8, 10, 998), Value::TIME(20, 8, 10, 330), |
23 | Value::TIME(20, 8, 10, 001), Value()})); |
24 | |
25 | // check that we can convert times to string |
26 | result = con.Query("SELECT cast(i AS VARCHAR) FROM times" ); |
27 | REQUIRE(CHECK_COLUMN( |
28 | result, 0, {Value("00:01:20" ), Value("20:08:10.998" ), Value("20:08:10.330" ), Value("20:08:10.001" ), Value()})); |
29 | } |
30 | |