diff --git a/TODO.txt b/TODO.txt index d21a4706..9e00e79d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -14,6 +14,10 @@ Usability Iterators for sync resultset iteration Better interface for connection_params data structure Consideration of timezones + Types + Decimal + Bit + Geometry Consider if header-only is a good idea Technical debt Concept checking diff --git a/test/common/test_common.hpp b/test/common/test_common.hpp index da3b1f52..0445baaa 100644 --- a/test/common/test_common.hpp +++ b/test/common/test_common.hpp @@ -56,6 +56,12 @@ inline std::string_view makesv(const char (&value) [N]) return std::string_view(value, N-1); // discard null terminator } +template +inline std::string_view makesv(const std::uint8_t (&value) [N]) +{ + return std::string_view(reinterpret_cast(value), N); +} + } } diff --git a/test/integration/db_setup.sql b/test/integration/db_setup.sql index faa6f80c..e8d73150 100644 --- a/test/integration/db_setup.sql +++ b/test/integration/db_setup.sql @@ -277,6 +277,31 @@ INSERT INTO types_binary VALUES ("empty", "", "", "", "", "", "") ; +CREATE TABLE types_not_implemented( + id VARCHAR(50) NOT NULL PRIMARY KEY, + field_bit BIT(8), + field_decimal DECIMAL, + field_geometry GEOMETRY +); +INSERT INTO types_not_implemented VALUES + ("regular", 0xfe, 300, POINT(1, 2)) +; + +CREATE TABLE types_flags( + id VARCHAR(50) NOT NULL, + field_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + field_primary_key INT NOT NULL AUTO_INCREMENT, + field_not_null CHAR(8) NOT NULL DEFAULT "", + field_unique INT, + field_indexed INT, + PRIMARY KEY (field_primary_key, id), + UNIQUE KEY (field_unique), + KEY (field_indexed) +); +INSERT INTO types_flags VALUES + ("default", NULL, 50, "char", 21, 42) +; + -- Users DROP USER IF EXISTS empty_password_user; CREATE USER empty_password_user IDENTIFIED BY ''; diff --git a/test/integration/metadata_validator.hpp b/test/integration/metadata_validator.hpp index 6c10109b..46592f3c 100644 --- a/test/integration/metadata_validator.hpp +++ b/test/integration/metadata_validator.hpp @@ -25,6 +25,14 @@ public: decimals_(decimals), type_(type), col_(col), flags_(std::move(flags)) { } + meta_validator(std::string table, std::string org_table, + std::string field, std::string org_field, field_type type, collation col, + std::vector flags={}, unsigned decimals=0): + table_(std::move(table)), org_table_(std::move(org_table)), + field_(std::move(field)), org_field_(std::move(org_field)), + decimals_(decimals), type_(type), col_(col), flags_(std::move(flags)) + { + } void validate(const field_metadata& value) const; private: std::string table_; diff --git a/test/integration/query.cpp b/test/integration/query.cpp index 2947c1de..64908cfe 100644 --- a/test/integration/query.cpp +++ b/test/integration/query.cpp @@ -605,7 +605,14 @@ TEST_F(QueryTest, FetchAllAsync_SeveralRows) EXPECT_EQ(rows, (makerows(2, 1, "f0", 2, "f1"))); } - +// Some system-level query tests +TEST_F(QueryTest, QueryAndFetch_AliasedTableAndField_MetadataCorrect) +{ + auto result = conn.query("SELECT field_varchar AS field_alias FROM empty_table table_alias"); + meta_validator validator ("table_alias", "empty_table", "field_alias", + "field_varchar", field_type::varchar, collation::utf8_general_ci); + validate_meta(result.fields(), {validator}); +} } // anon namespace diff --git a/test/integration/query_types.cpp b/test/integration/query_types.cpp index 17a4a81d..8f516624 100644 --- a/test/integration/query_types.cpp +++ b/test/integration/query_types.cpp @@ -469,14 +469,36 @@ INSTANTIATE_TEST_SUITE_P(BINARY, QueryTypesTest, Values( QueryTypesParams("types_binary", "field_longblob", "empty", "", field_type::blob) )); +// These types do not have a more concrete representation in the library yet. +// Check we get them as strings and we get the metadata correctly +std::uint8_t geometry_value [] = { + 0x00, 0x00, 0x00, + 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 +}; + +INSTANTIATE_TEST_SUITE_P(NOT_IMPLEMENTED_TYPES, QueryTypesTest, Values( + QueryTypesParams("types_not_implemented", "field_bit", "regular", "\xfe", field_type::bit, flags_unsigned), + QueryTypesParams("types_not_implemented", "field_decimal", "regular", "300", field_type::decimal), + QueryTypesParams("types_not_implemented", "field_geometry", "regular", makesv(geometry_value), field_type::geometry) +)); + +// Tests for certain metadata flags and NULL values +INSTANTIATE_TEST_SUITE_P(METADATA_FLAGS, QueryTypesTest, Values( + QueryTypesParams("types_flags", "field_timestamp", "default", nullptr, field_type::timestamp, + flagsvec{&field_metadata::is_set_to_now_on_update}), + QueryTypesParams("types_flags", "field_primary_key", "default", std::int32_t(50), field_type::int_, + flagsvec{&field_metadata::is_primary_key, &field_metadata::is_not_null, + &field_metadata::is_auto_increment}), + QueryTypesParams("types_flags", "field_not_null", "default", "char", field_type::char_, collation::utf8_general_ci, + flagsvec{&field_metadata::is_not_null}), + QueryTypesParams("types_flags", "field_unique", "default", std::int32_t(21), field_type::int_, + flagsvec{&field_metadata::is_unique_key}), + QueryTypesParams("types_flags", "field_indexed", "default", std::int32_t(42), field_type::int_, + flagsvec{&field_metadata::is_multiple_key}) +)); + + } // anon namespace - -// text types -// TODO: character sets and collations -// missing types -// key flags -// timestamp flags -// NULL - -