Skip to content

Commit

Permalink
Add test case with prepared statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Aug 26, 2024
1 parent c5d67dd commit 5f5702e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/common-tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -3646,12 +3646,38 @@ TEST_CASE_METHOD(common_tests, "Basic logging support", "[core][logging]")

{
auto_table_creator tableCreator(tc_.table_creator_1(sql));

int id = 1;
std::string name = "b";
sql << "insert into soci_test (name,id) values (:name,:id)", use(name, "name"), use(id, "id");

CHECK(sql.get_last_query() == "insert into soci_test (name,id) values (:name,:id)");
CHECK(sql.get_last_query_with_context() == "insert into soci_test (name,id) values (:name,:id) with :name=\"b\", :id=1");

statement stmt = (sql.prepare << "insert into soci_test(name, id) values (:name, :id)");
{
id = 5;
name = "alice";
stmt.exchange(use(name));
stmt.exchange(use(id));
stmt.define_and_bind();
stmt.execute(true);
stmt.bind_clean_up();
CHECK(sql.get_last_query() == "insert into soci_test(name, id) values (:name, :id)");
CHECK(sql.get_last_query_with_context() == "insert into soci_test(name, id) values (:name, :id) with :name=\"alice\", :id=5");
}
{
id = 42;
name = "bob";
stmt.exchange(use(name));
stmt.exchange(use(id));
stmt.define_and_bind();
stmt.execute(true);
stmt.bind_clean_up();
CHECK(sql.get_last_query() == "insert into soci_test(name, id) values (:name, :id)");
CHECK(sql.get_last_query_with_context() == "insert into soci_test(name, id) values (:name, :id) with :name=\"bob\", :id=42");
}

}

sql.set_log_stream(&log);
Expand Down

0 comments on commit 5f5702e

Please sign in to comment.