backend tests progress
This commit is contained in:
@@ -145,7 +145,7 @@ sql::record postgres_connection::describe(const std::string &table)
|
||||
while (reader.fetch()) {
|
||||
char *end = nullptr;
|
||||
// Todo: Handle error
|
||||
auto index = strtoul(reader.column(0), &end, 10);
|
||||
auto index = strtoul(reader.column(0), &end, 10) - 1;
|
||||
std::string name = reader.column(1);
|
||||
|
||||
// Todo: extract size
|
||||
@@ -156,7 +156,7 @@ sql::record postgres_connection::describe(const std::string &table)
|
||||
null_opt = sql::null_option::NOT_NULL;
|
||||
}
|
||||
// f.default_value(res->column(4));
|
||||
prototype.append({name, type, utils::null_attributes, null_opt});
|
||||
prototype.append({name, type, utils::null_attributes, null_opt, index});
|
||||
}
|
||||
|
||||
return std::move(prototype);
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
drop_table_if_exists("flight");
|
||||
drop_table_if_exists("airplane");
|
||||
drop_table_if_exists("person");
|
||||
drop_table_if_exists("quotes");
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -34,7 +35,7 @@ private:
|
||||
|
||||
using namespace matador::sql;
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement", "[session][record]")
|
||||
{
|
||||
REQUIRE(!ses.table_exists("person"));
|
||||
ses.create()
|
||||
@@ -54,7 +55,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement", "[ses
|
||||
REQUIRE(!ses.table_exists("person"));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement with foreign key", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement with foreign key", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("airplane", {
|
||||
@@ -89,7 +90,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Create and drop table statement with fo
|
||||
REQUIRE(!ses.table_exists("airplane"));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -128,7 +129,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement", "[ses
|
||||
.execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement with foreign key", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement with foreign key", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("airplane", {
|
||||
@@ -168,7 +169,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute insert record statement with fo
|
||||
REQUIRE(!ses.table_exists("airplane"));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute update record statement", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute update record statement", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -214,7 +215,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute update record statement", "[ses
|
||||
ses.drop().table("person").execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -257,7 +258,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement", "[session re
|
||||
ses.drop().table("person").execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with order by", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with order by", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -291,7 +292,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with order by"
|
||||
ses.drop().table("person").execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with group by and order by", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with group by and order by", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -330,7 +331,7 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute select statement with group by
|
||||
ses.drop().table("person").execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute delete statement", "[session record]")
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Execute delete statement", "[session][record]")
|
||||
{
|
||||
ses.create()
|
||||
.table("person", {
|
||||
@@ -359,3 +360,37 @@ TEST_CASE_METHOD(SessionRecordFixture, " Execute delete statement", "[session re
|
||||
|
||||
ses.drop().table("person").execute();
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionRecordFixture, " Test quoted identifier", "[session][record]") {
|
||||
ses.create()
|
||||
.table("quotes", {
|
||||
make_column<std::string>("from", 255),
|
||||
make_column<std::string>("to", 255)
|
||||
}).execute();
|
||||
|
||||
// check table description
|
||||
std::vector<std::string> columns = { "from", "to"};
|
||||
std::vector<data_type_t> types = {data_type_t::type_varchar, data_type_t::type_varchar};
|
||||
auto fields = ses.describe_table("quotes");
|
||||
|
||||
for (const auto &field : fields) {
|
||||
REQUIRE(field.name() == columns[field.index()]);
|
||||
REQUIRE(field.type() == types[field.index()]);
|
||||
}
|
||||
|
||||
ses.insert().into("quotes", {"from", "to"}).values({"Berlin", "London"}).execute();
|
||||
|
||||
auto res = ses.select({"from", "to"}).from("quotes").fetch_one();
|
||||
|
||||
REQUIRE("Berlin" == res.at("from").str());
|
||||
REQUIRE("London" == res.at("to").str());
|
||||
|
||||
ses.update("quotes").set({{"from", "Hamburg"}, {"to", "New York"}}).where("from"_col == "Berlin").execute();
|
||||
|
||||
res = ses.select({"from", "to"}).from("quotes").fetch_one();
|
||||
|
||||
REQUIRE("Hamburg" == res.at("from").str());
|
||||
REQUIRE("New York" == res.at("to").str());
|
||||
|
||||
ses.drop().table("quotes").execute();
|
||||
}
|
||||
Reference in New Issue
Block a user