Skip to content

Commit

Permalink
Fix MySQL ODBC unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zann1x committed Jan 15, 2023
1 parent ed50d90 commit b8eaeca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
21 changes: 19 additions & 2 deletions tests/common-tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ class test_context_base
// values might be stored as overflown and therefore negative integer.
virtual bool has_uint64_storage_bug() const { return false; }

// Override this if the backend truncates integer values bigger than INT64_MAX.
virtual bool truncates_uint64_to_int64() const { return false; }

// Override this to call commit() if it's necessary for the DDL statements
// to be taken into account (currently this is only the case for Firebird).
virtual void on_after_ddl(session&) const { }
Expand Down Expand Up @@ -1795,7 +1798,14 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")
ui2 = 0;
sql << "select ul from soci_test", into(ui2);

CHECK(ui2 == (std::numeric_limits<uint64_t>::max)());
if (tc_.truncates_uint64_to_int64())
{
CHECK(ui2 == static_cast<uint64_t>((std::numeric_limits<int64_t>::max)()));
}
else
{
CHECK(ui2 == (std::numeric_limits<uint64_t>::max)());
}
}

SECTION("double")
Expand Down Expand Up @@ -2426,7 +2436,14 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
CHECK(v2[2] == 1);
CHECK(v2[3] == 123);
CHECK(v2[4] == 1000);
CHECK(v2[5] == (std::numeric_limits<uint64_t>::max)());
if (tc_.truncates_uint64_to_int64())
{
CHECK(v2[5] == static_cast<uint64_t>((std::numeric_limits<int64_t>::max)()));
}
else
{
CHECK(v2[5] == (std::numeric_limits<uint64_t>::max)());
}
}
}

Expand Down
19 changes: 18 additions & 1 deletion tests/odbc/test-odbc-mysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
std::string connectString;
backend_factory const &backEnd = *soci::factory_odbc();

class test_context_odbc : public test_context
{
public:
using test_context::test_context;

bool truncates_uint64_to_int64() const override
{
// The ODBC driver of MySQL truncates values bigger then INT64_MAX.
// There are open bugs related to this issue:
// - https://bugs.mysql.com/bug.php?id=95978
// - https://bugs.mysql.com/bug.php?id=61114
// Driver version 8.0.31 seems to have fixed this (https://github.com/mysql/mysql-connector-odbc/commit/e78da1344247752f76a082de51cfd36d5d2dd98f),
// but we use an older version in the AppVeyor builds.
return true;
}
};

int main(int argc, char** argv)
{
#ifdef _MSC_VER
Expand Down Expand Up @@ -43,7 +60,7 @@ int main(int argc, char** argv)
connectString = "FILEDSN=./test-mysql.dsn";
}

test_context tc(backEnd, connectString);
test_context_odbc tc(backEnd, connectString);

return Catch::Session().run(argc, argv);
}

0 comments on commit b8eaeca

Please sign in to comment.