Skip to content

Commit

Permalink
tmp odbc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zann1x committed Jun 3, 2022
1 parent 0d19891 commit d69c2fd
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 28 deletions.
129 changes: 108 additions & 21 deletions tests/common-tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,14 @@ class test_context_base
// to fit by default.
virtual bool has_silent_truncate_bug(session&) const { return false; }

// Override this if the backend doesn't support unsigned 64-bit integers.
virtual bool has_uint64_support() const { return true; }
// Override this if the backend doesn't fully support signed 8-bit integers.
virtual bool has_full_int8_support() const { return true; }

// Override this if the backend doesn't support unsigned types.
virtual bool has_unsigned_type_support() const { return true; }

// Override this if the backend doesn't fully support unsigned 64-bit integers.
virtual bool has_full_uint64_support() const { return true; }

// Override this if the backend doesn't distinguish between empty and null
// strings (Oracle does this).
Expand Down Expand Up @@ -1525,6 +1531,12 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("int8_t min")
{
if (!tc_.has_full_int8_support())
{
WARN("int8 not fully supported by the database, skipping the test.");
return;
}

int8_t s = (std::numeric_limits<int8_t>::min)();
sql << "insert into soci_test(id) values(:id)", use(s);

Expand Down Expand Up @@ -1635,7 +1647,7 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("uint16_t min")
{
uint16_t s = (std::numeric_limits<uint16_t>::min)();
uint16_t s = (std::numeric_limits<uint16_t>::min)();
sql << "insert into soci_test(id) values(:id)", use(s);

uint16_t s2 = 0;
Expand All @@ -1646,6 +1658,12 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("uint16_t max")
{
if (!tc_.has_unsigned_type_support())
{
WARN("uint16 not fully supported by the database, skipping the test.");
return;
}

uint16_t s = (std::numeric_limits<uint16_t>::max)();
sql << "insert into soci_test(id) values(:id)", use(s);

Expand Down Expand Up @@ -1723,6 +1741,12 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("uint32_t max")
{
if (!tc_.has_unsigned_type_support())
{
WARN("uint32 not fully supported by the database, skipping the test.");
return;
}

uint32_t i = (std::numeric_limits<uint32_t>::max)();
sql << "insert into soci_test(ul) values(:i)", use(i);

Expand All @@ -1734,6 +1758,12 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("unsigned long")
{
if (!tc_.has_unsigned_type_support())
{
WARN("unsigned long not fully supported by the database, skipping the test.");
return;
}

unsigned long ul = 4000000000ul;
sql << "insert into soci_test(ul) values(:num)", use(ul);

Expand Down Expand Up @@ -1800,7 +1830,7 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("uint64_t max")
{
if (!tc_.has_uint64_support())
if (!tc_.has_unsigned_type_support() || !tc_.has_full_uint64_support())
{
WARN("uint64 not fully supported by the database, skipping the test.");
return;
Expand Down Expand Up @@ -1991,6 +2021,12 @@ TEST_CASE_METHOD(common_tests, "Use type conversion", "[core][use]")

SECTION("const unsigned long")
{
if (!tc_.has_unsigned_type_support())
{
WARN("unsigned long not fully supported by the database, skipping the test.");
return;
}

unsigned long const ul = 4000000000ul;
sql << "insert into soci_test(ul) values(:num)", use(ul);

Expand Down Expand Up @@ -2182,8 +2218,11 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
SECTION("int8_t")
{
std::vector<int8_t> v;
v.push_back((std::numeric_limits<int8_t>::min)());
v.push_back(-5);
if (tc_.has_full_int8_support())
{
v.push_back((std::numeric_limits<int8_t>::min)());
v.push_back(-5);
}
v.push_back(123);
v.push_back((std::numeric_limits<int8_t>::max)());

Expand All @@ -2192,11 +2231,20 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
std::vector<int8_t> v2(4);

sql << "select sh from soci_test order by sh", into(v2);
CHECK(v2.size() == 4);
CHECK(v2[0] == (std::numeric_limits<int8_t>::min)());
CHECK(v2[1] == -5);
CHECK(v2[2] == 123);
CHECK(v2[3] == (std::numeric_limits<int8_t>::max)());
if (tc_.has_full_int8_support())
{
CHECK(v2.size() == 4);
CHECK(v2[0] == (std::numeric_limits<int8_t>::min)());
CHECK(v2[1] == -5);
CHECK(v2[2] == 123);
CHECK(v2[3] == (std::numeric_limits<int8_t>::max)());
}
else
{
CHECK(v2.size() == 2);
CHECK(v2[0] == 123);
CHECK(v2[1] == (std::numeric_limits<int8_t>::max)());
}
}

SECTION("uint8_t")
Expand Down Expand Up @@ -2265,18 +2313,31 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
v.push_back((std::numeric_limits<uint16_t>::min)());
v.push_back(6);
v.push_back(123);
v.push_back((std::numeric_limits<uint16_t>::max)());
if (tc_.has_unsigned_type_support())
{
v.push_back((std::numeric_limits<uint16_t>::max)());
}

sql << "insert into soci_test(val) values(:val)", use(v);

std::vector<uint16_t> v2(4);

sql << "select val from soci_test order by val", into(v2);
CHECK(v2.size() == 4);
if (tc_.has_unsigned_type_support())
{
CHECK(v2.size() == 4);
}
else
{
CHECK(v2.size() == 3);
}
CHECK(v2[0] == (std::numeric_limits<uint16_t>::min)());
CHECK(v2[1] == 6);
CHECK(v2[2] == 123);
CHECK(v2[3] == (std::numeric_limits<uint16_t>::max)());
if (tc_.has_unsigned_type_support())
{
CHECK(v2[3] == (std::numeric_limits<uint16_t>::max)());
}
}

SECTION("int")
Expand Down Expand Up @@ -2351,20 +2412,33 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
v.push_back(1);
v.push_back(123);
v.push_back(1000);
v.push_back((std::numeric_limits<uint32_t>::max)());
if (tc_.has_unsigned_type_support())
{
v.push_back((std::numeric_limits<uint32_t>::max)());
}

sql << "insert into soci_test(ul) values(:ul)", use(v);

std::vector<uint32_t> v2(6);

sql << "select ul from soci_test order by ul", into(v2);
CHECK(v2.size() == 6);
if (tc_.has_unsigned_type_support())
{
CHECK(v2.size() == 6);
}
else
{
CHECK(v2.size() == 5);
}
CHECK(v2[0] == (std::numeric_limits<uint32_t>::min)());
CHECK(v2[1] == 0);
CHECK(v2[2] == 1);
CHECK(v2[3] == 123);
CHECK(v2[4] == 1000);
CHECK(v2[5] == (std::numeric_limits<uint32_t>::max)());
if (tc_.has_unsigned_type_support())
{
CHECK(v2[5] == (std::numeric_limits<uint32_t>::max)());
}
}

SECTION("unsigned long long")
Expand Down Expand Up @@ -2413,7 +2487,7 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")

SECTION("uint64_t")
{
if (!tc_.has_uint64_support())
if (!tc_.has_unsigned_type_support() || !tc_.has_full_uint64_support())
{
WARN("uint64 not fully supported by the database, skipping the test.");
return;
Expand All @@ -2425,20 +2499,33 @@ TEST_CASE_METHOD(common_tests, "Use vector", "[core][use][vector]")
v.push_back(1);
v.push_back(123);
v.push_back(1000);
v.push_back((std::numeric_limits<uint64_t>::max)());
if (tc_.has_unsigned_type_support())
{
v.push_back((std::numeric_limits<uint64_t>::max)());
}

sql << "insert into soci_test(ul) values(:ul)", use(v);

std::vector<uint64_t> v2(6);

sql << "select ul from soci_test order by ul", into(v2);
CHECK(v2.size() == 6);
if (tc_.has_unsigned_type_support())
{
CHECK(v2.size() == 6);
}
else
{
CHECK(v2.size() == 5);
}
CHECK(v2[0] == (std::numeric_limits<uint64_t>::min)());
CHECK(v2[1] == 0);
CHECK(v2[2] == 1);
CHECK(v2[3] == 123);
CHECK(v2[4] == 1000);
CHECK(v2[5] == (std::numeric_limits<uint64_t>::max)());
if (tc_.has_unsigned_type_support())
{
CHECK(v2[5] == (std::numeric_limits<uint64_t>::max)());
}
}

SECTION("double")
Expand Down
2 changes: 1 addition & 1 deletion tests/db2/test-db2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class test_context :public test_context_base
return new table_creator_for_get_affected_rows(s);
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/firebird/test-firebird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ class test_context : public tests::test_context_base
return new TableCreatorXML(s);
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/odbc/test-odbc-db2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class test_context : public test_context_base
return new table_creator_for_get_affected_rows(s);
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down
26 changes: 25 additions & 1 deletion tests/odbc/test-odbc-mssql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,35 @@ class test_context : public test_context_base
return true;
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_int8_support() const SOCI_OVERRIDE
{
// MS SQL only supports tinyint values in the range [0..255].
return false;
}

bool has_unsigned_type_support() const SOCI_OVERRIDE
{
// MS SQL only supports signed integer types. A direct mapping to
// e.g. a uint32 value is therefore only possible up to its equivalent
// signed type range.
//
// In the past, when tests used unsigned types, an overflow happened
// on the C++ side, effectively storing a negative value in the database.
// When reading this value back to an unsigned value, another overflow
// on the C++ side lead to the correct result in the unsigned type var.
// Since SOCI's full support of fixed-size C++ integers and the
// corresponding changes in database communication, unsigned types would
// get stored as-is without any overflows on the C++ side. As MS SQL
// doesn't support unsigned types, we get an overflow and an insertion
// error there.
return false;
}

bool has_full_uint64_support() const SOCI_OVERRIDE
{
return has_unsigned_type_support();
}

std::string sql_length(std::string const& s) const SOCI_OVERRIDE
{
return "len(" + s + ")";
Expand Down
2 changes: 1 addition & 1 deletion tests/odbc/test-odbc-postgresql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class test_context : public test_context_base
return !m_verDriver.is_initialized() || m_verDriver < odbc_version(9, 3, 400);
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/postgresql/test-postgresql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ class test_context : public test_context_base
return false;
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite3/test-sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class test_context : public test_context_base
return true;
}

bool has_uint64_support() const SOCI_OVERRIDE
bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}
Expand Down

0 comments on commit d69c2fd

Please sign in to comment.