Skip to content

Commit

Permalink
Work around bug in int8_t support when using SQL Server
Browse files Browse the repository at this point in the history
Negative values saved to the database are stored as positive numbers in
at least some versions of the database, so even if they're converted
back to the negative ones when we read them back, ordering the result
set by them doesn't work as expected, see #1193.

Until this can be fixed, work around this by sorting the values in the
test itself instead.
  • Loading branch information
vadz committed Jan 20, 2025
1 parent 601504c commit c7932d2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/common/test-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,14 @@ 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);
sql << "select sh from soci_test", into(v2);
CHECK(v2.size() == 4);

// This is a hack: "order by" doesn't work correctly with SQL Server
// for this type because it's stored as unsigned in the database, so
// sort the values here instead.
std::sort(v2.begin(), v2.end());

CHECK((int)v2[0] == (int)(std::numeric_limits<int8_t>::min)());
CHECK((int)v2[1] == (int)-5);
CHECK((int)v2[2] == (int)123);
Expand Down

0 comments on commit c7932d2

Please sign in to comment.