1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | static void TestAddition(Connection &con, string type) { |
8 | unique_ptr<QueryResult> result; |
9 | |
10 | result = con.Query("SELECT 1::" + type + " + 1::TINYINT" ); |
11 | REQUIRE(CHECK_COLUMN(result, 0, {2})); |
12 | result = con.Query("SELECT 1::" + type + " + 1::SMALLINT" ); |
13 | REQUIRE(CHECK_COLUMN(result, 0, {2})); |
14 | result = con.Query("SELECT 1::" + type + " + 1::INT" ); |
15 | REQUIRE(CHECK_COLUMN(result, 0, {2})); |
16 | result = con.Query("SELECT 1::" + type + " + 1::BIGINT" ); |
17 | REQUIRE(CHECK_COLUMN(result, 0, {2})); |
18 | result = con.Query("SELECT 1::" + type + " + 1::REAL" ); |
19 | REQUIRE(CHECK_COLUMN(result, 0, {Value::FLOAT(2.0f)})); |
20 | result = con.Query("SELECT 1::" + type + " + 1::DOUBLE" ); |
21 | REQUIRE(CHECK_COLUMN(result, 0, {Value::DOUBLE(2.0)})); |
22 | REQUIRE_FAIL(con.Query("SELECT 1::" + type + " + 1::VARCHAR" )); |
23 | } |
24 | |
25 | TEST_CASE("Test type resolution of functions" , "[function]" ) { |
26 | DuckDB db(nullptr); |
27 | Connection con(db); |
28 | con.EnableQueryVerification(); |
29 | |
30 | // type resolution of addition |
31 | TestAddition(con, "TINYINT" ); |
32 | TestAddition(con, "SMALLINT" ); |
33 | TestAddition(con, "INTEGER" ); |
34 | TestAddition(con, "BIGINT" ); |
35 | TestAddition(con, "REAL" ); |
36 | TestAddition(con, "DOUBLE" ); |
37 | } |
38 | |
39 | TEST_CASE("Test type resolution of function with parameter expressions" , "[function]" ) { |
40 | DuckDB db(nullptr); |
41 | Connection con(db); |
42 | unique_ptr<QueryResult> result; |
43 | con.EnableQueryVerification(); |
44 | |
45 | // can deduce type of prepared parameter here |
46 | auto prepared = con.Prepare("select 1 + $1" ); |
47 | REQUIRE(prepared->error.empty()); |
48 | |
49 | result = prepared->Execute(1); |
50 | REQUIRE(CHECK_COLUMN(result, 0, {2})); |
51 | } |
52 | |