1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | TEST_CASE("Test string casts" , "[cast]" ) { |
8 | unique_ptr<QueryResult> result; |
9 | DuckDB db(nullptr); |
10 | Connection con(db); |
11 | con.EnableQueryVerification(); |
12 | |
13 | // boolean -> string |
14 | result = con.Query("SELECT (1=1)::VARCHAR, (1=0)::VARCHAR, NULL::BOOLEAN::VARCHAR" ); |
15 | REQUIRE(CHECK_COLUMN(result, 0, {"true" })); |
16 | REQUIRE(CHECK_COLUMN(result, 1, {"false" })); |
17 | REQUIRE(CHECK_COLUMN(result, 2, {Value()})); |
18 | // tinyint -> string |
19 | result = con.Query("SELECT 1::TINYINT::VARCHAR, 12::TINYINT::VARCHAR, (-125)::TINYINT::VARCHAR" ); |
20 | REQUIRE(CHECK_COLUMN(result, 0, {"1" })); |
21 | REQUIRE(CHECK_COLUMN(result, 1, {"12" })); |
22 | REQUIRE(CHECK_COLUMN(result, 2, {"-125" })); |
23 | // smallint -> string |
24 | result = con.Query("SELECT 1::SMALLINT::VARCHAR, 12442::SMALLINT::VARCHAR, (-32153)::SMALLINT::VARCHAR" ); |
25 | REQUIRE(CHECK_COLUMN(result, 0, {"1" })); |
26 | REQUIRE(CHECK_COLUMN(result, 1, {"12442" })); |
27 | REQUIRE(CHECK_COLUMN(result, 2, {"-32153" })); |
28 | // integer -> string |
29 | result = con.Query("SELECT 1::INTEGER::VARCHAR, 12442952::INTEGER::VARCHAR, (-2000000111)::INTEGER::VARCHAR" ); |
30 | REQUIRE(CHECK_COLUMN(result, 0, {"1" })); |
31 | REQUIRE(CHECK_COLUMN(result, 1, {"12442952" })); |
32 | REQUIRE(CHECK_COLUMN(result, 2, {"-2000000111" })); |
33 | // bigint -> string |
34 | result = |
35 | con.Query("SELECT 1::BIGINT::VARCHAR, 1244295295289253::BIGINT::VARCHAR, (-2000000111551166)::BIGINT::VARCHAR" ); |
36 | REQUIRE(CHECK_COLUMN(result, 0, {"1" })); |
37 | REQUIRE(CHECK_COLUMN(result, 1, {"1244295295289253" })); |
38 | REQUIRE(CHECK_COLUMN(result, 2, {"-2000000111551166" })); |
39 | // float -> string |
40 | result = con.Query("SELECT 2::FLOAT::VARCHAR, 0.5::FLOAT::VARCHAR, (-128.5)::FLOAT::VARCHAR" ); |
41 | REQUIRE(CHECK_COLUMN(result, 0, {"2.0" })); |
42 | REQUIRE(CHECK_COLUMN(result, 1, {"0.5" })); |
43 | REQUIRE(CHECK_COLUMN(result, 2, {"-128.5" })); |
44 | // double -> string |
45 | result = con.Query("SELECT 2::DOUBLE::VARCHAR, 0.5::DOUBLE::VARCHAR, (-128.5)::DOUBLE::VARCHAR" ); |
46 | REQUIRE(CHECK_COLUMN(result, 0, {"2.0" })); |
47 | REQUIRE(CHECK_COLUMN(result, 1, {"0.5" })); |
48 | REQUIRE(CHECK_COLUMN(result, 2, {"-128.5" })); |
49 | } |
50 | |