From 59068a6ead841d2a87b20717a5a4cc5e7c0dd1c8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Jul 2026 17:13:37 +0200 Subject: [PATCH 1/4] Add unit test for bulk operations with optional --- tests/common/test-common.cpp | 48 ++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/common/test-common.cpp b/tests/common/test-common.cpp index 96c42faf..e08e39dc 100644 --- a/tests/common/test-common.cpp +++ b/tests/common/test-common.cpp @@ -2525,7 +2525,7 @@ TEST_CASE("soci_error is nothrow", "[core][exception][nothrow]") // test for handling NULL values with std::optional // (both into and use) -TEST_CASE_METHOD(common_tests, "NULL with std optional", "[core][null]") +TEST_CASE_METHOD(common_tests, "NULL with std optional", "[core][optional][null]") { soci::session sql(backEndFactory_, connectString_); @@ -2997,7 +2997,51 @@ TEST_CASE_METHOD(common_tests, "NULL with std optional", "[core][null]") } } } -#endif + +TEST_CASE_METHOD(common_tests, "optional-bulk", "[core][optional][null]") +{ + soci::session sql(backEndFactory_, connectString_); + + // create and populate the test table + auto_table_creator tableCreator(tc_.table_creator_1(sql)); + + constexpr int N = 10; + std::vector ids(N); + std::vector> in(N); + for (int i = 0; i < N; ++i) + { + ids[i] = i; + + if (i % 2 == 0) + in[i] = std::string(1, static_cast('a' + i / 2)); + } + + sql << "insert into soci_test(id, str) values(:ids, :str)", use(ids), use(in); + + std::vector> out(10); + sql << "select str from soci_test order by id", into(out); + + REQUIRE(out.size() == in.size()); + for (int i = 0; i < N; ++i) + { + INFO("i = " << i); + + if (in[i].has_value()) + { + CHECK(out[i].has_value()); + if (out[i].has_value()) + { + CHECK(out[i].value() == in[i].value()); + } + } + else + { + CHECK(!out[i].has_value()); + } + } +} + +#endif // SOCI_HAVE_CXX17 // connection and reconnection tests TEST_CASE_METHOD(common_tests, "Connection and reconnection", "[core][connect]") From d3d09026487fa5253c52138a8e918be4618b5f46 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Jul 2026 17:26:31 +0200 Subject: [PATCH 2/4] Avoid harmless MSVS variable shadowing warnings in Oracle test Don't redeclare the same variables or do redeclare it but reduce the scope of a previously declared variable with the same name to avoid shadowing. No real changes. This commit is best viewed ignoring whitespace-only changes. --- tests/oracle/test-oracle.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/oracle/test-oracle.cpp b/tests/oracle/test-oracle.cpp index 23fc33e8..6de6efaf 100644 --- a/tests/oracle/test-oracle.cpp +++ b/tests/oracle/test-oracle.cpp @@ -178,8 +178,6 @@ TEST_CASE("Oracle datetime", "[oracle][datetime]") { // date and time - between years 1- 2201 - soci::session sql(backEnd, connectString); - table_creator_for_timestamp tableCreator(sql); for(int i = 100; i <= 2201; i = i + 50) @@ -353,14 +351,16 @@ TEST_CASE("Oracle stored procedure", "[oracle][stored-procedure]") soci::session sql(backEnd, connectString); procedure_creator procedure_creator(sql); - std::string in("my message"); - std::string out; - statement st = (sql.prepare << - "begin soci_test(:output, :input); end;", - use(out, "output"), - use(in, "input")); - st.execute(1); - CHECK(out == in); + { + std::string in("my message"); + std::string out; + statement st = (sql.prepare << + "begin soci_test(:output, :input); end;", + use(out, "output"), + use(in, "input")); + st.execute(1); + CHECK(out == in); + } // explicit procedure syntax { From 9b34986861bc798020f66a44e944f47cf2d9e360 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Jul 2026 17:31:26 +0200 Subject: [PATCH 3/4] Avoid MSVS warnings about "deprecated" localtime() Use MSVS-specific localtime_s() instead when using this compiler. --- tests/oracle/test-oracle.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/oracle/test-oracle.cpp b/tests/oracle/test-oracle.cpp index 6de6efaf..0cde975e 100644 --- a/tests/oracle/test-oracle.cpp +++ b/tests/oracle/test-oracle.cpp @@ -26,6 +26,17 @@ using namespace soci::tests; std::string connectString; backend_factory const &backEnd = *soci::factory_oracle(); +static std::tm Localtime(std::time_t t) +{ + std::tm local; +#ifdef _MSC_VER + localtime_s(&local, &t); +#else + local = *localtime(&t); +#endif + return local; +} + // Helpers for creating tables for different tests. struct table_creator_one : public table_creator_base { @@ -117,8 +128,7 @@ TEST_CASE("Oracle datetime", "[oracle][datetime]") { std::time_t now = std::time(nullptr); - std::tm t1, t2; - t2 = *std::localtime(&now); + std::tm t1, t2 = Localtime(now); sql << "select t from (select :t as t from dual)", into(t1), use(t2); @@ -148,8 +158,7 @@ TEST_CASE("Oracle datetime", "[oracle][datetime]") { // date and time - before year 2000 std::time_t then = std::time(nullptr) - 17*365*24*60*60; - std::tm t1, t2; - t2 = *std::localtime(&then); + std::tm t1, t2 = Localtime(then); sql << "select t from (select :t as t from dual)", into(t1), use(t2); From 426a26c31f1964b26d29ca9c7231d66658214792 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Jul 2026 19:37:05 +0200 Subject: [PATCH 4/4] Fix using bulk operations with strings in Oracle backend This was broken by c35b1b6a (Avoid disabling MSVC CRT security warnings globally, 2025-06-08) which implicitly replaced std::strncpy() calls in Oracle vector use type backend with the calls to soci::strncpy() which doesn't behave in the same way as the standard function, e.g. it can't be used with n==0 and it always NUL-terminates the destination buffer. Restore the original strncpy() behaviour to fix this. See #1268. --- include/soci/soci-platform.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/soci/soci-platform.h b/include/soci/soci-platform.h index 2ddad998..e2caa125 100644 --- a/include/soci/soci-platform.h +++ b/include/soci/soci-platform.h @@ -160,8 +160,12 @@ inline int sscanf(const char* str, const char* format, ...) inline char* strncpy(char* dest, const char* src, size_t n) { - strncpy_s(dest, n, src, _TRUNCATE); - return dest; + #pragma warning(push) + #pragma warning(disable:4996) + + return std::strncpy(dest, src, n); + + #pragma warning(pop) } #else // !_MSC_VER