summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdbpp/command.h2
-rw-r--r--libdbpp/unittests/testUtils.cpp75
2 files changed, 42 insertions, 35 deletions
diff --git a/libdbpp/command.h b/libdbpp/command.h
index f080121..34338eb 100644
--- a/libdbpp/command.h
+++ b/libdbpp/command.h
@@ -127,7 +127,7 @@ namespace DB {
std::is_same<O, boost::posix_time::ptime>::value) {
bindParamT(i, o);
}
- else if constexpr (std::is_same<O, Blob>::value) {
+ else if constexpr (std::is_same<O, Blob>::value || std::is_convertible<O, Blob>::value) {
bindParamBLOB(i, o);
}
else if constexpr (std::is_integral<O>::value && !std::is_pointer<O>::value) {
diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp
index eed1322..9ceef54 100644
--- a/libdbpp/unittests/testUtils.cpp
+++ b/libdbpp/unittests/testUtils.cpp
@@ -303,50 +303,57 @@ BOOST_AUTO_TEST_CASE( bindIntPtr )
BOOST_FIXTURE_TEST_CASE( traits_bind, DB::TestCore )
{
+ using namespace std::literals;
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
auto cmd = db->select("select x is null, format('%s', x) from (select ? x) d");
- auto check = [cmd](int line, const auto & v, bool isNull, const auto & strval) {
+ auto cmd2 = db->select("select x is null, x from (select ?::bytea x) d");
+ auto check = [](int line, const auto & v, bool isNull, const auto & testval, auto & cmd) {
BOOST_TEST_CONTEXT("line " << line) {
- cmd->bindParam(0, v);
- for (const auto & [null, str] : cmd->as<bool, std::string_view>()) {
+ BOOST_REQUIRE_NO_THROW(cmd->bindParam(0, v));
+ for (const auto & [null, dbval] : cmd->template as<bool, std::decay_t<decltype(testval)>>()) {
BOOST_CHECK_EQUAL(null, isNull);
- BOOST_CHECK_EQUAL(str, strval);
+ BOOST_CHECK_EQUAL(dbval, testval);
}
}
};
- check(__LINE__, std::nullopt, true, "");
- check(__LINE__, nullptr, true, "");
- check(__LINE__, testInt, false, "43");
- check(__LINE__, std::make_unique<short>(testInt), false, "43");
- check(__LINE__, std::unique_ptr<short>(), true, "");
- check(__LINE__, (unsigned int)testInt, false, "43");
- check(__LINE__, &testInt, false, "43");
- check(__LINE__, testDouble, false, "3.14");
- check(__LINE__, std::make_shared<float>(testDouble), false, "3.14");
- check(__LINE__, std::shared_ptr<float>(), true, "");
- check(__LINE__, (float)testDouble, false, "3.14");
- check(__LINE__, &testDouble, false, "3.14");
- check(__LINE__, testString, false, testString);
- check(__LINE__, &testString, false, testString);
- check(__LINE__, "str", false, "str");
- check(__LINE__, "", false, "");
+ check(__LINE__, std::nullopt, true, ""sv, cmd);
+ check(__LINE__, nullptr, true, ""sv, cmd);
+ check(__LINE__, testInt, false, "43"sv, cmd);
+ check(__LINE__, std::make_unique<short>(testInt), false, "43"sv, cmd);
+ check(__LINE__, std::unique_ptr<short>(), true, ""sv, cmd);
+ check(__LINE__, (unsigned int)testInt, false, "43"sv, cmd);
+ check(__LINE__, &testInt, false, "43"sv, cmd);
+ check(__LINE__, testDouble, false, "3.14"sv, cmd);
+ check(__LINE__, std::make_shared<float>(testDouble), false, "3.14"sv, cmd);
+ check(__LINE__, std::shared_ptr<float>(), true, ""sv, cmd);
+ check(__LINE__, (float)testDouble, false, "3.14"sv, cmd);
+ check(__LINE__, &testDouble, false, "3.14"sv, cmd);
+ check(__LINE__, testString, false, testString, cmd);
+ check(__LINE__, &testString, false, testString, cmd);
+ check(__LINE__, "str", false, "str"sv, cmd);
+ check(__LINE__, "", false, ""sv, cmd);
const char * const nullstr = nullptr;
- check(__LINE__, nullstr, true, "");
+ check(__LINE__, nullstr, true, ""sv, cmd);
const char * const str = "str";
- check(__LINE__, str, false, "str");
- check(__LINE__, std::string(), false, "");
- check(__LINE__, std::string_view(), false, "");
- check(__LINE__, Glib::ustring(), false, "");
- check(__LINE__, Glib::ustring("foo"), false, "foo");
- check(__LINE__, testDateTime, false, "2015-05-02T01:36:33");
- check(__LINE__, testInterval, false, "01:02:03");
- check(__LINE__, &testInterval, false, "01:02:03");
+ check(__LINE__, str, false, "str"sv, cmd);
+ check(__LINE__, std::string(), false, ""sv, cmd);
+ check(__LINE__, std::string_view(), false, ""sv, cmd);
+ check(__LINE__, Glib::ustring(), false, ""sv, cmd);
+ check(__LINE__, Glib::ustring("foo"), false, "foo"sv, cmd);
+ check(__LINE__, testDateTime, false, "2015-05-02T01:36:33"sv, cmd);
+ check(__LINE__, testInterval, false, "01:02:03"sv, cmd);
+ check(__LINE__, &testInterval, false, "01:02:03"sv, cmd);
decltype(testInterval) * nullInterval = nullptr;
- check(__LINE__, nullInterval, true, "");
- check(__LINE__, true, false, "1");
- check(__LINE__, false, false, "0");
- check(__LINE__, std::optional<int>(4), false, "4");
- check(__LINE__, std::optional<int>(), true, "");
+ check(__LINE__, nullInterval, true, ""sv, cmd);
+ check(__LINE__, true, false, "1"sv, cmd);
+ check(__LINE__, false, false, "0"sv, cmd);
+ check(__LINE__, std::optional<int>(4), false, "4"sv, cmd);
+ check(__LINE__, std::optional<int>(), true, ""sv, cmd);
+ check(__LINE__, testBlob, false, testBlob, cmd2);
+ check(__LINE__, testBlobData, false, testBlob, cmd2);
+ check(__LINE__, std::shared_ptr<DB::Blob>(), true, ""sv, cmd);
+ check(__LINE__, std::optional<DB::Blob>(), true, ""sv, cmd);
+ check(__LINE__, std::optional<DB::Blob>(testBlob), false, testBlob, cmd2);
}
BOOST_AUTO_TEST_CASE( testBlobRaw )