From d784e65a8b84a7094776aaae9415cfa7136e1a14 Mon Sep 17 00:00:00 2001 From: anarthal Date: Sun, 1 Mar 2020 15:28:30 +0000 Subject: [PATCH 1/3] Changes to build/run in Windows 64 --- TODO.txt | 8 +++--- include/mysql/impl/binary_serialization.ipp | 27 ++++++++++++--------- test/integration/database_types.cpp | 8 +++--- test/integration/metadata_validator.cpp | 2 +- test/integration/prepare_statement.cpp | 4 +-- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/TODO.txt b/TODO.txt index d2f64538..3c78d612 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,6 +1,3 @@ -Prepared statements - Build in Windows - Build in CI Multiresultset Text protocol Binary protocol (stored procedures) @@ -9,6 +6,7 @@ Handshake SSL compression Usability + Connection quit Incomplete query reads: how does this affect further queries? Metadata in rows: being able to index by name Iterators for sync resultset iteration @@ -46,4 +44,6 @@ Technical debt Test prepared statement binding to procedure out params More thorough testing for several NULLs in integration testing Query and statement tests for DELETEs - prepared_statement::execute(): static_assert(), handle value&, const value&, anything convertible \ No newline at end of file + prepared_statement::execute(): static_assert(), handle value&, const value&, anything convertible + Test for too many connections: do we have a buffer overrun there? (error msg shows incomplete) + Add a connection quit in integ tests: they may fail under Windows otherwise \ No newline at end of file diff --git a/include/mysql/impl/binary_serialization.ipp b/include/mysql/impl/binary_serialization.ipp index 7d0a3b70..fcf7d529 100644 --- a/include/mysql/impl/binary_serialization.ipp +++ b/include/mysql/impl/binary_serialization.ipp @@ -188,14 +188,15 @@ inline void mysql::detail::serialize( { serialize_fields( ctx, - int1(brokendt.tod.hours().count()), - int1(brokendt.tod.minutes().count()), - int1(brokendt.tod.seconds().count()) + int1(static_cast(brokendt.tod.hours().count())), + int1(static_cast(brokendt.tod.minutes().count())), + int1(static_cast(brokendt.tod.seconds().count())) ); } if (length >= 11) { - serialize(int4(brokendt.tod.subseconds().count()), ctx); + auto micros = static_cast(brokendt.tod.subseconds().count()); + serialize(int4(micros), ctx); } } @@ -229,9 +230,10 @@ inline mysql::Error mysql::detail::deserialize( if (err != Error::ok) return err; } - // Compose the final datetime - output = date_part + std::chrono::hours(hours.value) + std::chrono::minutes(minutes.value) + - std::chrono::seconds(seconds.value) + std::chrono::microseconds(micros.value); + // Compose the final datetime. Doing time of day and date separately to avoid overflow + auto time_of_day_part = std::chrono::hours(hours.value) + std::chrono::minutes(minutes.value) + + std::chrono::seconds(seconds.value) + std::chrono::microseconds(micros.value); + output = date_part + time_of_day_part; return Error::ok; } @@ -258,15 +260,16 @@ inline void mysql::detail::serialize( serialize_fields( ctx, is_negative, - int4(std::abs(broken.days.count())), - int1(std::abs(broken.hours.count())), - int1(std::abs(broken.minutes.count())), - int1(std::abs(broken.seconds.count())) + int4(static_cast(std::abs(broken.days.count()))), + int1(static_cast(std::abs(broken.hours.count()))), + int1(static_cast(std::abs(broken.minutes.count()))), + int1(static_cast(std::abs(broken.seconds.count()))) ); } if (length >= 12) { - serialize(int4(std::abs(broken.microseconds.count())), ctx); + auto micros = static_cast(std::abs(broken.microseconds.count())); + serialize(int4(micros), ctx); } } diff --git a/test/integration/database_types.cpp b/test/integration/database_types.cpp index aea9f779..b090091b 100644 --- a/test/integration/database_types.cpp +++ b/test/integration/database_types.cpp @@ -199,7 +199,7 @@ INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DatabaseTypesTest, Values( INSTANTIATE_TEST_SUITE_P(INT, DatabaseTypesTest, Values( database_types_testcase("types_int", "field_signed", "regular", std::int32_t(20), field_type::int_), database_types_testcase("types_int", "field_signed", "negative", std::int32_t(-20), field_type::int_), - database_types_testcase("types_int", "field_signed", "min", std::int32_t(-0x80000000), field_type::int_), + database_types_testcase("types_int", "field_signed", "min", -std::int32_t(0x80000000), field_type::int_), database_types_testcase("types_int", "field_signed", "max", std::int32_t(0x7fffffff), field_type::int_), database_types_testcase("types_int", "field_unsigned", "regular", std::uint32_t(20), field_type::int_, flags_unsigned), @@ -216,7 +216,7 @@ INSTANTIATE_TEST_SUITE_P(INT, DatabaseTypesTest, Values( INSTANTIATE_TEST_SUITE_P(BIGINT, DatabaseTypesTest, Values( database_types_testcase("types_bigint", "field_signed", "regular", std::int64_t(20), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "negative", std::int64_t(-20), field_type::bigint), - database_types_testcase("types_bigint", "field_signed", "min", std::int64_t(-0x8000000000000000), field_type::bigint), + database_types_testcase("types_bigint", "field_signed", "min", -std::int64_t(0x8000000000000000), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "max", std::int64_t(0x7fffffffffffffff), field_type::bigint), database_types_testcase("types_bigint", "field_unsigned", "regular", std::uint64_t(20), field_type::bigint, flags_unsigned), @@ -296,13 +296,13 @@ int round_micros(int input, int decimals) { assert(decimals >= 0 && decimals <= 6); if (decimals == 0) return 0; - int modulus = std::pow(10, 6 - decimals); + auto modulus = static_cast(std::pow(10, 6 - decimals)); return (input / modulus) * modulus; } std::chrono::microseconds round_micros(std::chrono::microseconds input, int decimals) { - return std::chrono::microseconds(round_micros(input.count(), decimals)); + return std::chrono::microseconds(round_micros(static_cast(input.count()), decimals)); } std::pair datetime_from_id(std::bitset<4> id, int decimals) diff --git a/test/integration/metadata_validator.cpp b/test/integration/metadata_validator.cpp index 81c53d96..5625c9f1 100644 --- a/test/integration/metadata_validator.cpp +++ b/test/integration/metadata_validator.cpp @@ -39,7 +39,7 @@ void meta_validator::validate( EXPECT_EQ(value.original_table(), org_table_); EXPECT_EQ(value.field_name(), field_); EXPECT_EQ(value.original_field_name(), org_field_); - EXPECT_GT(value.column_length(), 0); + EXPECT_GT(value.column_length(), 0u); EXPECT_EQ(value.type(), type_); EXPECT_EQ(value.decimals(), decimals_); diff --git a/test/integration/prepare_statement.cpp b/test/integration/prepare_statement.cpp index 28762c45..bf111857 100644 --- a/test/integration/prepare_statement.cpp +++ b/test/integration/prepare_statement.cpp @@ -27,7 +27,7 @@ TEST_P(PrepareStatementTest, OkNoParams) auto stmt = GetParam()->prepare_statement(conn, "SELECT * FROM empty_table"); stmt.validate_no_error(); ASSERT_TRUE(stmt.value.valid()); - EXPECT_GT(stmt.value.id(), 0); + EXPECT_GT(stmt.value.id(), 0u); EXPECT_EQ(stmt.value.num_params(), 0); } @@ -36,7 +36,7 @@ TEST_P(PrepareStatementTest, OkWithParams) auto stmt = GetParam()->prepare_statement(conn, "SELECT * FROM empty_table WHERE id IN (?, ?)"); stmt.validate_no_error(); ASSERT_TRUE(stmt.value.valid()); - EXPECT_GT(stmt.value.id(), 0); + EXPECT_GT(stmt.value.id(), 0u); EXPECT_EQ(stmt.value.num_params(), 2); } From 1a92b8be24d5057bcd8a3d57382b56a0a2817f7e Mon Sep 17 00:00:00 2001 From: anarthal Date: Sun, 1 Mar 2020 17:00:21 +0000 Subject: [PATCH 2/3] Fixed overflow warning in database_types.cpp --- test/integration/database_types.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/database_types.cpp b/test/integration/database_types.cpp index b090091b..a6f83e9d 100644 --- a/test/integration/database_types.cpp +++ b/test/integration/database_types.cpp @@ -199,7 +199,7 @@ INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DatabaseTypesTest, Values( INSTANTIATE_TEST_SUITE_P(INT, DatabaseTypesTest, Values( database_types_testcase("types_int", "field_signed", "regular", std::int32_t(20), field_type::int_), database_types_testcase("types_int", "field_signed", "negative", std::int32_t(-20), field_type::int_), - database_types_testcase("types_int", "field_signed", "min", -std::int32_t(0x80000000), field_type::int_), + database_types_testcase("types_int", "field_signed", "min", std::int32_t(-0x80000000), field_type::int_), database_types_testcase("types_int", "field_signed", "max", std::int32_t(0x7fffffff), field_type::int_), database_types_testcase("types_int", "field_unsigned", "regular", std::uint32_t(20), field_type::int_, flags_unsigned), @@ -216,7 +216,7 @@ INSTANTIATE_TEST_SUITE_P(INT, DatabaseTypesTest, Values( INSTANTIATE_TEST_SUITE_P(BIGINT, DatabaseTypesTest, Values( database_types_testcase("types_bigint", "field_signed", "regular", std::int64_t(20), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "negative", std::int64_t(-20), field_type::bigint), - database_types_testcase("types_bigint", "field_signed", "min", -std::int64_t(0x8000000000000000), field_type::bigint), + database_types_testcase("types_bigint", "field_signed", "min", std::int64_t(-0x8000000000000000), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "max", std::int64_t(0x7fffffffffffffff), field_type::bigint), database_types_testcase("types_bigint", "field_unsigned", "regular", std::uint64_t(20), field_type::bigint, flags_unsigned), From 84ef370e0de147f0e8eb2253a7f3c80e7444be08 Mon Sep 17 00:00:00 2001 From: anarthal Date: Sun, 1 Mar 2020 17:05:00 +0000 Subject: [PATCH 3/3] Increased max_connections so integ tests always pass --- TODO.txt | 1 - test/integration/db_setup.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index 3c78d612..026ab382 100644 --- a/TODO.txt +++ b/TODO.txt @@ -16,7 +16,6 @@ Usability Bit Geometry UNIX socket connection - make_values connection::connect that handles TCP/Unix and MySQL connect connection::run_sql that hides the resultset concept Consider if header-only is a good idea diff --git a/test/integration/db_setup.sql b/test/integration/db_setup.sql index 692a7177..6b62c8a0 100644 --- a/test/integration/db_setup.sql +++ b/test/integration/db_setup.sql @@ -1,5 +1,6 @@ -- Connection system variables SET NAMES utf8; +SET global max_connections = 1000; -- Database DROP DATABASE IF EXISTS awesome;