implemented sqlite fetch
This commit is contained in:
+67
-16
@@ -9,7 +9,7 @@
|
||||
using namespace matador::sql;
|
||||
using namespace matador::test;
|
||||
|
||||
TEST_CASE("Execute create table statement", "[session]") {
|
||||
TEST_CASE("Execute create and drop table statement", "[session]") {
|
||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
||||
session s(pool);
|
||||
|
||||
@@ -22,30 +22,81 @@ TEST_CASE("Execute create table statement", "[session]") {
|
||||
|
||||
REQUIRE(res.second == R"(CREATE TABLE "person" ("id" BIGINT NOT NULL, "name" VARCHAR(255), "age" INTEGER, CONSTRAINT PK_person PRIMARY KEY (id)))");
|
||||
|
||||
REQUIRE(s.drop().table("person").execute().first == 0);
|
||||
// REQUIRE(res.first == 1);
|
||||
res = s.drop().table("person").execute();
|
||||
|
||||
// res = s.create().table<product>("product").execute();
|
||||
|
||||
// REQUIRE(res.second == R"(CREATE TABLE "product" ("product_name" VARCHAR(255) PRIMARY KEY, "supplier_id" BIGINT NOT NULL FOREIGN KEY, "category_id" BIGINT NOT NULL FOREIGN KEY, "quantity_per_unit" VARCHAR(255), "unit_price" BIGINT, "units_in_stock" BIGINT, "units_in_order" BIGINT, "reorder_level" BIGINT, "discontinued" BOOLEAN))");
|
||||
|
||||
// res = s.drop().table("person").execute();
|
||||
// REQUIRE(res.first == 1);
|
||||
REQUIRE(res.second == R"(DROP TABLE "person")");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute create table statement with foreign keys", "[session]") {
|
||||
// res = s.create().table<product>("product").execute();
|
||||
|
||||
// REQUIRE(res.second == R"(CREATE TABLE "product" ("product_name" VARCHAR(255) PRIMARY KEY, "supplier_id" BIGINT NOT NULL FOREIGN KEY, "category_id" BIGINT NOT NULL FOREIGN KEY, "quantity_per_unit" VARCHAR(255), "unit_price" BIGINT, "units_in_stock" BIGINT, "units_in_order" BIGINT, "reorder_level" BIGINT, "discontinued" BOOLEAN))");
|
||||
|
||||
// res = s.drop().table("person").execute();
|
||||
// REQUIRE(res.first == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Execute drop table statement", "[session]") {
|
||||
TEST_CASE("Execute insert record statement", "[session]") {
|
||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
||||
session s(pool);
|
||||
|
||||
const auto res = s.drop()
|
||||
.table("person")
|
||||
.execute();
|
||||
auto res = s
|
||||
.create()
|
||||
.table("person", {
|
||||
make_pk_column<unsigned long>("id"),
|
||||
make_column<std::string>("name", 255),
|
||||
make_column<unsigned short>("age")
|
||||
})
|
||||
.execute();
|
||||
|
||||
REQUIRE(res.second == R"(DROP TABLE "person")");
|
||||
REQUIRE(res.first == 0);
|
||||
|
||||
res = s
|
||||
.insert()
|
||||
.into("person", {"id", "name", "age"})
|
||||
.values({7, "george", 45})
|
||||
.execute();
|
||||
|
||||
REQUIRE(res.first == 1);
|
||||
REQUIRE(res.second == R"(INSERT INTO "person" ("id", "name", "age") VALUES (7, 'george', 45))");
|
||||
|
||||
auto result = s
|
||||
.select({"id", "name", "age"})
|
||||
.from("person")
|
||||
.fetch_all();
|
||||
|
||||
for (const auto& i : result) {
|
||||
REQUIRE(i.size() == 3);
|
||||
REQUIRE(i.at(0).name() == "id");
|
||||
REQUIRE(i.at(0).type() == data_type_t::type_long_long);
|
||||
REQUIRE(i.at(1).name() == "name");
|
||||
REQUIRE(i.at(1).type() == data_type_t::type_varchar);
|
||||
REQUIRE(i.at(2).name() == "age");
|
||||
REQUIRE(i.at(2).type() == matador::sql::data_type_t::type_int);
|
||||
}
|
||||
s.drop().table("person").execute();
|
||||
|
||||
// using namespace matador::test;
|
||||
// product p;
|
||||
// p.discontinued = false;
|
||||
// p.reorder_level = 1;
|
||||
// p.units_in_order = 2;
|
||||
// p.units_in_stock = 100;
|
||||
// p.unit_price = 49;
|
||||
// p.quantity_per_unit = "pcs";
|
||||
// p.category = make_foreign<matador::test::category>();
|
||||
// p.category->id = 7;
|
||||
// p.supplier = make_foreign<matador::test::supplier>();;
|
||||
// p.supplier->id = 13;
|
||||
// p.product_name = "candle";
|
||||
//
|
||||
// res = s.insert().into<product>("product").values(p).execute();
|
||||
//
|
||||
// REQUIRE(res.second == R"(INSERT INTO "product" ("product_name", "supplier_id", "category_id", "quantity_per_unit", "unit_price", "units_in_stock", "units_in_order", "reorder_level", "discontinued") VALUES ('candle', 13, 7, 'pcs', 49, 100, 2, 1, 0))");
|
||||
//
|
||||
// res = s.insert().into("product", p).execute();
|
||||
//
|
||||
// REQUIRE(res.second == R"(INSERT INTO "product" ("product_name", "supplier_id", "category_id", "quantity_per_unit", "unit_price", "units_in_stock", "units_in_order", "reorder_level", "discontinued") VALUES ('candle', 13, 7, 'pcs', 49, 100, 2, 1, 0))");
|
||||
}
|
||||
|
||||
TEST_CASE("Execute select statement with where clause", "[session]") {
|
||||
@@ -114,7 +165,7 @@ TEST_CASE("Execute insert statement", "[session]") {
|
||||
p.quantity_per_unit = "pcs";
|
||||
p.category = make_foreign<matador::test::category>();
|
||||
p.category->id = 7;
|
||||
p.supplier = make_foreign<matador::test::supplier>();;
|
||||
p.supplier = make_foreign<matador::test::supplier>();
|
||||
p.supplier->id = 13;
|
||||
p.product_name = "candle";
|
||||
|
||||
@@ -151,7 +202,7 @@ TEST_CASE("Execute update statement", "[session]") {
|
||||
p.quantity_per_unit = "pcs";
|
||||
p.category = make_foreign<matador::test::category>();
|
||||
p.category->id = 7;
|
||||
p.supplier = make_foreign<matador::test::supplier>();;
|
||||
p.supplier = make_foreign<matador::test::supplier>();
|
||||
p.supplier->id = 13;
|
||||
p.product_name = "candle";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user