Skip to content

Commit 786b5d4

Browse files
committed
Query parameters unit test
1 parent 7642eaa commit 786b5d4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ut/client_ut.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,3 +1488,45 @@ TEST(SimpleClientTest, issue_335_reconnects_count) {
14881488
<< "\tThere was no attempt to connect to endpoint " << endpoint;
14891489
}
14901490
}
1491+
1492+
TEST_P(ClientCase, QueryParameters) {
1493+
const std::string table_name = "test_clickhouse_cpp_query_parameter";
1494+
client_->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS " + table_name + " (id UInt64, name String)");
1495+
{
1496+
Query query("insert into " + table_name + " values ({id: UInt64}, {name: String})");
1497+
1498+
query.SetParam("id", "1").SetParam("name", "NAME");
1499+
client_->Execute(query);
1500+
1501+
query.SetParam("id", "123").SetParam("name", "FromParam");
1502+
client_->Execute(query);
1503+
1504+
query.SetParam("id", "333")
1505+
.SetParam("name", std::string("A\000A\001A\002A\003A\004A\005A\006A\007A\010A\011A\012A\013A\014A\015A\016A\017A\020A\021A\022A"
1506+
"\023A\024A\025A\026A\027A\030A\031A\032A\033A\034"
1507+
"A\035A\036A\037A",
1508+
65));
1509+
client_->Execute(query);
1510+
1511+
unsigned char big_string[128 - 32];
1512+
for (unsigned int i = 0; i < sizeof(big_string); i++) big_string[i] = i + 32;
1513+
query.SetParam("id", "444").SetParam("name", std::string((char*)big_string, sizeof(big_string)));
1514+
client_->Execute(query);
1515+
1516+
query.SetParam("id", "555").SetParam("name", "utf8Русский");
1517+
client_->Execute(query);
1518+
}
1519+
1520+
Query query("SELECT id, name, length(name) FROM " + table_name + " where id > {a: Int32}");
1521+
query.SetParam("a", "4");
1522+
size_t total_count = 0;
1523+
SelectCallback cb([&total_count](const Block& block) {
1524+
total_count += block.GetRowCount();
1525+
//std::cout << PrettyPrintBlock{block} << std::endl;
1526+
});
1527+
query.OnData(cb);
1528+
client_->Select(query);
1529+
EXPECT_EQ(4u, total_count);
1530+
1531+
client_->Execute("DROP TEMPORARY TABLE " + table_name);
1532+
}

0 commit comments

Comments
 (0)