added returning to update statement and added error code implementation for query
This commit is contained in:
@@ -142,9 +142,9 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto & [join_table, clause] : data.joins) {
|
||||
REQUIRE(join_table->table_name() == expected_join_data[index].first);
|
||||
REQUIRE(evaluator.evaluate(*clause) == expected_join_data[index].second);
|
||||
for (const auto &join : data.joins) {
|
||||
REQUIRE(join.join_table->table_name() == expected_join_data[index].first);
|
||||
REQUIRE(evaluator.evaluate(*join.condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ TEST_CASE("insert query builder test", "[query][insert_query_builder]") {
|
||||
const auto& stmts = *build_result;
|
||||
REQUIRE(stmts.size() == 1);
|
||||
|
||||
const auto sql = stmts.front().str(db);
|
||||
const auto step = stmts.front();
|
||||
|
||||
REQUIRE(std::holds_alternative<executable_query>(step.query));
|
||||
const auto sql = std::get<executable_query>(step.query).str(db);
|
||||
REQUIRE(sql == R"(INSERT INTO "airplanes" ("id", "brand", "model") VALUES (1, 'Boeing', 'A380'))");
|
||||
}
|
||||
|
||||
@@ -139,6 +139,16 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65 WHERE "id" > 9 ORDER BY "id" ASC LIMIT 3 OFFSET 2)");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][update][returning]") {
|
||||
const auto result = query::update("person")
|
||||
.set({{"id", 7U}, {"name", "george"}, {"age", 65U}})
|
||||
.where("name"_col == "george")
|
||||
.returning("id"_col, "name"_col, "age"_col)
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65 WHERE "name" = 'george' RETURNING "id", "name", "age")");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][update][limit]") {
|
||||
const auto result = query::update("person")
|
||||
.set({{"id", 7U}, {"name", "george"}, {"age", 65U}})
|
||||
@@ -199,6 +209,16 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with placeholder", "[q
|
||||
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (9, 'george', ?))");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test insert sql statement with returning", "[query][insert][returning]") {
|
||||
const auto result = query::insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({9, "george", _})
|
||||
.returning("id"_col, "name"_col, "age"_col)
|
||||
.str(*db);
|
||||
|
||||
REQUIRE(result == R"(INSERT INTO "person" ("id", "name", "age") VALUES (9, 'george', ?) RETURNING "id", "name", "age")");
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Test select sql statement string with order by", "[query]") {
|
||||
const auto result = query::select({"id", "name", "age"})
|
||||
.from("person")
|
||||
|
||||
Reference in New Issue
Block a user