add missing sql execute statements in connection
This commit is contained in:
+10
-10
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("Create table", "[query]") {
|
||||
TEST_CASE("Create table sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.create().table("person", {
|
||||
@@ -19,7 +19,7 @@ TEST_CASE("Create table", "[query]") {
|
||||
REQUIRE(sql == R"##(CREATE TABLE "person" ("id" BIGINT NOT NULL PRIMARY KEY, "name" VARCHAR(255), "age" INTEGER))##");
|
||||
}
|
||||
|
||||
TEST_CASE("Drop table", "[query]") {
|
||||
TEST_CASE("Drop table sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.drop().table("person").compile();
|
||||
@@ -27,7 +27,7 @@ TEST_CASE("Drop table", "[query]") {
|
||||
REQUIRE(sql == R"(DROP TABLE "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Select", "[query]") {
|
||||
TEST_CASE("Select sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"}).from("person").compile();
|
||||
@@ -35,7 +35,7 @@ TEST_CASE("Select", "[query]") {
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Insert", "[query]") {
|
||||
TEST_CASE("Insert sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.insert().into("person", {
|
||||
@@ -45,7 +45,7 @@ TEST_CASE("Insert", "[query]") {
|
||||
REQUIRE(sql == R"(INSERT INTO "person" ("id", "name", "age") VALUES (7, 'george', 65))");
|
||||
}
|
||||
|
||||
TEST_CASE("Update", "[query]") {
|
||||
TEST_CASE("Update sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.update("person").set({
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("Update", "[query]") {
|
||||
REQUIRE(sql == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
|
||||
}
|
||||
|
||||
TEST_CASE("Delete", "[query]") {
|
||||
TEST_CASE("Delete sql statement string", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.remove().from("person").compile();
|
||||
@@ -65,7 +65,7 @@ TEST_CASE("Delete", "[query]") {
|
||||
REQUIRE(sql == R"(DELETE FROM "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Where", "[query]") {
|
||||
TEST_CASE("Select sql statement string with where clause", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
auto sql = query.select({"id", "name", "age"})
|
||||
@@ -83,7 +83,7 @@ TEST_CASE("Where", "[query]") {
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" WHERE ("id" = ? AND "age" > 50))");
|
||||
}
|
||||
|
||||
TEST_CASE("OrderBy", "[query]") {
|
||||
TEST_CASE("Select sql statement string with order by", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
@@ -94,7 +94,7 @@ TEST_CASE("OrderBy", "[query]") {
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" ORDER BY "name" ASC)");
|
||||
}
|
||||
|
||||
TEST_CASE("GroupBy", "[query]") {
|
||||
TEST_CASE("Select sql statement string with group by", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
@@ -105,7 +105,7 @@ TEST_CASE("GroupBy", "[query]") {
|
||||
REQUIRE(sql == R"(SELECT "id", "name", "age" FROM "person" GROUP BY "age")");
|
||||
}
|
||||
|
||||
TEST_CASE("Limit", "[query]") {
|
||||
TEST_CASE("Select sql statement string with offset and limit", "[query]") {
|
||||
dialect d;
|
||||
query_builder query(d);
|
||||
const auto sql = query.select({"id", "name", "age"})
|
||||
|
||||
+86
-1
@@ -6,7 +6,31 @@
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE("CSelect", "[connection]") {
|
||||
TEST_CASE("Execute create table statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
c.create()
|
||||
.table("person", {
|
||||
make_pk_column<unsigned long>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<unsigned short>("age")
|
||||
}).execute();
|
||||
|
||||
REQUIRE(true);
|
||||
// REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute drop table statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
c.drop()
|
||||
.table("person").execute();
|
||||
|
||||
REQUIRE(true);
|
||||
// REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with where clause", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.select({"id", "name", "color"})
|
||||
@@ -15,4 +39,65 @@ TEST_CASE("CSelect", "[connection]") {
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with order by", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.select({"id", "name", "color"})
|
||||
.from("person")
|
||||
.where("id"_col == 8)
|
||||
.order_by("name").desc()
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 ORDER BY "name" DESC)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with group by and order by", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.select({"id", "name", "color"})
|
||||
.from("person")
|
||||
.where("id"_col == 8)
|
||||
.group_by("color")
|
||||
.order_by("name").asc()
|
||||
.fetch_all();
|
||||
|
||||
REQUIRE(res.sql == R"(SELECT "id", "name", "color" FROM "person" WHERE "id" = 8 GROUP BY "color" ORDER BY "name" ASC)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute insert statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.insert()
|
||||
.into("person", {"id", "name", "color"})
|
||||
.values({7, "george", "green"})
|
||||
.execute();
|
||||
|
||||
REQUIRE(res.second == R"(INSERT INTO "person" ("id", "name", "color") VALUES (7, 'george', 'green'))");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute update statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.update("person")
|
||||
.set({
|
||||
{"name", "george"},
|
||||
{"color", "green"}
|
||||
})
|
||||
.where("id"_col == 9)
|
||||
.execute();
|
||||
|
||||
REQUIRE(res.second == R"(UPDATE "person" SET "name"='george', "color"='green' WHERE "id" = 9)");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute delete statement", "[connection]") {
|
||||
connection c;
|
||||
|
||||
auto res = c.remove()
|
||||
.from("person", "p")
|
||||
.where("id"_col == 9)
|
||||
.execute();
|
||||
|
||||
REQUIRE(res.second == R"(DELETE FROM "person" p WHERE "id" = 9)");
|
||||
}
|
||||
Reference in New Issue
Block a user