added test for date and time, sql read and write functionality
This commit is contained in:
@@ -26,9 +26,6 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
|
||||
const table tab("types");
|
||||
|
||||
// auto r = query::create().table(tab).columns({
|
||||
// column("id", basic_type::UInt32)
|
||||
// });
|
||||
auto res = query::create()
|
||||
.table(tab)
|
||||
.columns({
|
||||
@@ -46,8 +43,8 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
column("val_double", basic_type::Double),
|
||||
column("val_string", basic_type::Text),
|
||||
column("val_varchar", basic_type::Varchar, 63),
|
||||
// column("val_date", basic_type::type_date),
|
||||
// column("val_time", basic_type::type_time),
|
||||
column("val_date", basic_type::Date),
|
||||
column("val_time", basic_type::Time),
|
||||
column("val_blob", basic_type::Blob),
|
||||
})
|
||||
.constraints({
|
||||
@@ -66,7 +63,7 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
"val_bool",
|
||||
"val_float", "val_double",
|
||||
"val_string", "val_varchar",
|
||||
// "val_date", "val_time",
|
||||
"val_date", "val_time",
|
||||
"val_blob"};
|
||||
|
||||
const auto fields = db.describe("types");
|
||||
@@ -89,41 +86,43 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||
double d{2.71828};
|
||||
std::string str{"long text"};
|
||||
std::string varchar{"good day"};
|
||||
// auto md{matador::date()};
|
||||
// auto mt{matador::time::now()};
|
||||
date_type_t md{2025, 11, 27};
|
||||
time_type_t mt{12, 34, 56};
|
||||
blob bin{0x01,0x02,0x03,0x04};
|
||||
|
||||
res = query::insert()
|
||||
.into("types", cols)
|
||||
.values({id, c, s, i, ll, uc, us, ui, ull, b, f, d, str, varchar, /*md, mt, */bin})
|
||||
.values({id, c, s, i, ll, uc, us, ui, ull, b, f, d, str, varchar, md, mt, bin})
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(res.value() == 1);
|
||||
|
||||
auto row = query::select(cols)
|
||||
auto result = query::select(cols)
|
||||
.from("types")
|
||||
.fetch_one(db);
|
||||
|
||||
REQUIRE(row.is_ok());
|
||||
REQUIRE(row.value().has_value());
|
||||
REQUIRE(result.is_ok());
|
||||
REQUIRE(result.value().has_value());
|
||||
|
||||
REQUIRE(id == (*row)->at<uint32_t>("id"));
|
||||
REQUIRE(c == (*row)->at<int8_t>("val_char"));
|
||||
REQUIRE(s == (*row)->at<int16_t>("val_short"));
|
||||
REQUIRE(i == (*row)->at<int32_t>("val_int"));
|
||||
REQUIRE(ll == (*row)->at<int64_t>("val_long_long"));
|
||||
REQUIRE(uc == (*row)->at<uint8_t>("val_uchar"));
|
||||
REQUIRE(us == (*row)->at<unsigned short>("val_ushort"));
|
||||
REQUIRE(ui == (*row)->at<unsigned int>("val_uint"));
|
||||
REQUIRE(ull == (*row)->at<uint64_t>("val_ulong_long"));
|
||||
REQUIRE((*row)->at<bool>("val_bool"));
|
||||
REQUIRE(f == (*row)->at<float>("val_float"));
|
||||
REQUIRE(d == (*row)->at<double>("val_double"));
|
||||
REQUIRE(str == (*row)->at<std::string>("val_string"));
|
||||
REQUIRE(varchar == (*row)->at<std::string>("val_varchar"));
|
||||
// REQUIRE(md == (*row)->at<matador::date>("val_date"));
|
||||
// REQUIRE(mt == (*row)->at<matador::time>("val_time"));
|
||||
REQUIRE(bin == (*row)->at<blob>("val_blob"));
|
||||
const auto &row = result.value().value();
|
||||
REQUIRE(id == row.at<uint32_t>("id"));
|
||||
REQUIRE(c == row.at<int8_t>("val_char"));
|
||||
REQUIRE(s == row.at<int16_t>("val_short"));
|
||||
REQUIRE(i == row.at<int32_t>("val_int"));
|
||||
REQUIRE(ll == row.at<int64_t>("val_long_long"));
|
||||
REQUIRE(uc == row.at<uint8_t>("val_uchar"));
|
||||
REQUIRE(us == row.at<unsigned short>("val_ushort"));
|
||||
REQUIRE(ui == row.at<unsigned int>("val_uint"));
|
||||
REQUIRE(ull == row.at<uint64_t>("val_ulong_long"));
|
||||
REQUIRE(row.at<bool>("val_bool"));
|
||||
REQUIRE(f == row.at<float>("val_float"));
|
||||
REQUIRE(d == row.at<double>("val_double"));
|
||||
REQUIRE(str == row.at<std::string>("val_string"));
|
||||
REQUIRE(varchar == row.at<std::string>("val_varchar"));
|
||||
REQUIRE(md == row.at<date_type_t>("val_date"));
|
||||
const auto mtres = row.at<time_type_t>("val_time");
|
||||
REQUIRE(mt == row.at<time_type_t>("val_time"));
|
||||
REQUIRE(bin == row.at<blob>("val_blob"));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][record]")
|
||||
|
||||
Reference in New Issue
Block a user