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 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]") diff --git a/tests/oracle/test-oracle.cpp b/tests/oracle/test-oracle.cpp index 23fc33e8..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); @@ -178,8 +187,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 +360,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 {