From 3ba20a351946516343aba45adb68d0abe9192214 Mon Sep 17 00:00:00 2001 From: maxbachmann <44199644+maxbachmann@users.noreply.github.com> Date: Tue, 25 Jun 2019 18:56:14 +0200 Subject: [PATCH] Improve execute many and fix GCC 9 Build by explicitly scoping SQLiteCpp::bind() Fix #206 #207 --- include/SQLiteCpp/ExecuteMany.h | 22 +++++++++++----------- include/SQLiteCpp/VariadicBind.h | 2 +- tests/ExecuteMany_test.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/SQLiteCpp/ExecuteMany.h b/include/SQLiteCpp/ExecuteMany.h index 40131445..73c0fd87 100644 --- a/include/SQLiteCpp/ExecuteMany.h +++ b/include/SQLiteCpp/ExecuteMany.h @@ -3,7 +3,7 @@ * @ingroup SQLiteCpp * @brief Convenience function to execute a Statement with multiple Parameter sets * - * Copyright (c) 2019 Maximilian Bachmann (github maxbachmann) + * Copyright (c) 2019 Maximilian Bachmann (contact@maxbachmann.de) * Copyright (c) 2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) * * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt @@ -33,8 +33,8 @@ namespace SQLite * * \code{.cpp} * execute_many(db, "INSERT INTO test VALUES (?, ?)", - * std::make_tuple(1, "one"), - * std::make_tuple(2, "two"), + * 1, + * std::make_tuple(2), * std::make_tuple(3, "three") * ); * \endcode @@ -47,10 +47,10 @@ template void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&... aParams) { SQLite::Statement query(aDatabase, apQuery); - bind_exec(query, std::forward(aArg)); + bind_exec(query, std::forward(aArg)); (void)std::initializer_list { - ((void)reset_bind_exec(query, std::forward(aParams)), 0)... + ((void)reset_bind_exec(query, std::forward(aParams)), 0)... }; } @@ -63,11 +63,11 @@ void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&. * @param apQuery Query to use * @param aTuple Tuple to bind */ -template -void reset_bind_exec(SQLite::Statement& apQuery, std::tuple&& aTuple) +template +void reset_bind_exec(Statement& apQuery, TupleT&& aTuple) { apQuery.reset(); - bind_exec(apQuery, std::forward(aTuple)); + bind_exec(apQuery, std::forward(aTuple)); } /** @@ -78,10 +78,10 @@ void reset_bind_exec(SQLite::Statement& apQuery, std::tuple&& aTuple) * @param apQuery Query to use * @param aTuple Tuple to bind */ -template -void bind_exec(SQLite::Statement& apQuery, std::tuple&& aTuple) +template +void bind_exec(Statement& apQuery, TupleT&& aTuple) { - bind(apQuery, std::forward(aTuple)); + SQLite::bind(apQuery, std::forward(aTuple)); while (apQuery.executeStep()) {} } diff --git a/include/SQLiteCpp/VariadicBind.h b/include/SQLiteCpp/VariadicBind.h index 8e5a31c7..1143b325 100644 --- a/include/SQLiteCpp/VariadicBind.h +++ b/include/SQLiteCpp/VariadicBind.h @@ -5,7 +5,7 @@ * * Copyright (c) 2016 Paul Dreik (github@pauldreik.se) * Copyright (c) 2016-2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) - * Copyright (c) 2019 Maximilian Bachmann (github maxbachmann) + * Copyright (c) 2019 Maximilian Bachmann (contact@maxbachmann.de) * * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * or copy at http://opensource.org/licenses/MIT) diff --git a/tests/ExecuteMany_test.cpp b/tests/ExecuteMany_test.cpp index 03eb3b75..c29caad9 100644 --- a/tests/ExecuteMany_test.cpp +++ b/tests/ExecuteMany_test.cpp @@ -3,7 +3,7 @@ * @ingroup tests * @brief Test of variadic bind * - * Copyright (c) 2019 Maximilian Bachmann (github@maxbachmann) + * Copyright (c) 2019 Maximilian Bachmann (contact@maxbachmann.de) * Copyright (c) 2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) * * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt @@ -29,8 +29,8 @@ TEST(ExecuteMany, invalid) EXPECT_TRUE(db.tableExists("test")); { execute_many(db, "INSERT INTO test VALUES (?, ?)", - std::make_tuple(1), - std::make_tuple(2, "two"), + 1, + std::make_tuple(2), std::make_tuple(3, "three") ); } @@ -47,7 +47,7 @@ TEST(ExecuteMany, invalid) EXPECT_EQ(std::size_t(3), results.size()); EXPECT_EQ(std::make_pair(1,std::string{""}), results.at(0)); - EXPECT_EQ(std::make_pair(2,std::string{"two"}), results.at(1)); + EXPECT_EQ(std::make_pair(2,std::string{""}), results.at(1)); EXPECT_EQ(std::make_pair(3,std::string{"three"}), results.at(2)); } }