Skip to content

Commit

Permalink
Update unit tests of ODBC backend for complete integer type support
Browse files Browse the repository at this point in the history
  • Loading branch information
zann1x committed Jun 9, 2022
1 parent 5ceb3b2 commit 0333372
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/odbc/test-odbc-access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct table_creator_one : public table_creator_base
: table_creator_base(sql)
{
sql << "create table soci_test(id integer, val integer, c char, "
"str varchar(20), sh integer, ul number, d float, "
"num76 numeric(7,6), "
"str varchar(20), sh integer, ll number, ul number, "
"d float, num76 numeric(7,6), "
"tm timestamp, i1 integer, i2 integer, i3 integer, "
"name varchar(20))";
}
Expand Down
9 changes: 7 additions & 2 deletions tests/odbc/test-odbc-db2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct table_creator_one : public table_creator_base
table_creator_one(soci::session & sql)
: table_creator_base(sql)
{
sql << "CREATE TABLE SOCI_TEST(ID INTEGER, VAL SMALLINT, C CHAR, STR VARCHAR(20), SH SMALLINT, UL NUMERIC(20), D DOUBLE, "
"NUM76 NUMERIC(7,6), "
sql << "CREATE TABLE SOCI_TEST(ID INTEGER, VAL SMALLINT, C CHAR, STR VARCHAR(20), SH SMALLINT, LL BIGINT, UL NUMERIC(20), "
"D DOUBLE, NUM76 NUMERIC(7,6), "
"TM TIMESTAMP(9), I1 INTEGER, I2 INTEGER, I3 INTEGER, NAME VARCHAR(20))";
}
};
Expand Down Expand Up @@ -89,6 +89,11 @@ class test_context : public test_context_base
return new table_creator_for_get_affected_rows(s);
}

bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}

std::string to_date_time(std::string const &datdt_string) const
{
return "\'" + datdt_string + "\'";
Expand Down
33 changes: 31 additions & 2 deletions tests/odbc/test-odbc-mssql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ struct table_creator_one : public table_creator_base
: table_creator_base(sql)
{
sql << "create table soci_test(id integer, val integer, c char, "
"str varchar(20), sh smallint, ul numeric(20), d float, "
"num76 numeric(7,6), "
"str varchar(20), sh smallint, ll bigint, ul numeric(20), "
"d float, num76 numeric(7,6), "
"tm datetime, i1 integer, i2 integer, i3 integer, "
"name varchar(20))";
}
Expand Down Expand Up @@ -210,6 +210,35 @@ class test_context : public test_context_base
return true;
}

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

bool has_full_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_full_unsigned_type_support();
}

std::string sql_length(std::string const& s) const SOCI_OVERRIDE
{
return "len(" + s + ")";
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_mysql : public test_context
{
public:
test_context_odbc_mysql(backend_factory const &backEnd_,
std::string const &connectString_)
: test_context(backEnd_, connectString_) {}

bool has_full_uint64_support() const SOCI_OVERRIDE
{
// For some reason it seems that MySQL has a bug under ODBC with which
// the maximum value of a uint64_t cannot be stored in and retrieved
// from the database. I.e. when storing 18446744073709551615, you're
// retrieving the value 9223372036854775807.
return false;
}
};

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_mysql tc(backEnd, connectString);

return Catch::Session().run(argc, argv);
}
9 changes: 7 additions & 2 deletions tests/odbc/test-odbc-postgresql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ struct table_creator_one : public table_creator_base
: table_creator_base(sql)
{
sql << "create table soci_test(id integer, val integer, c char, "
"str varchar(20), sh int2, ul numeric(20), d float8, "
"num76 numeric(7,6), "
"str varchar(20), sh int2, ll bigint, ul numeric(20), "
"d float8, num76 numeric(7,6), "
"tm timestamp, i1 integer, i2 integer, i3 integer, "
"name varchar(20))";
}
Expand Down Expand Up @@ -212,6 +212,11 @@ class test_context : public test_context_base
return !m_verDriver.is_initialized() || m_verDriver < odbc_version(9, 3, 400);
}

bool has_full_uint64_support() const SOCI_OVERRIDE
{
return false;
}

std::string fix_crlf_if_necessary(std::string const& s) const SOCI_OVERRIDE
{
// Version 9.03.0300 (ancient, but still used on AppVeyor CI) is known
Expand Down

0 comments on commit 0333372

Please sign in to comment.