Improve execute many and fix GCC 9 Build by explicitly scoping SQLiteCpp::bind()

Fix #206 #207
This commit is contained in:
maxbachmann 2019-06-25 18:56:14 +02:00 committed by Sébastien Rombauts
parent a637d24764
commit 3ba20a3519
3 changed files with 16 additions and 16 deletions

View File

@ -3,7 +3,7 @@
* @ingroup SQLiteCpp * @ingroup SQLiteCpp
* @brief Convenience function to execute a Statement with multiple Parameter sets * @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) * Copyright (c) 2019 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
@ -33,8 +33,8 @@ namespace SQLite
* *
* \code{.cpp} * \code{.cpp}
* execute_many(db, "INSERT INTO test VALUES (?, ?)", * execute_many(db, "INSERT INTO test VALUES (?, ?)",
* std::make_tuple(1, "one"), * 1,
* std::make_tuple(2, "two"), * std::make_tuple(2),
* std::make_tuple(3, "three") * std::make_tuple(3, "three")
* ); * );
* \endcode * \endcode
@ -47,10 +47,10 @@ template <typename Arg, typename... Types>
void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&... aParams) void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&... aParams)
{ {
SQLite::Statement query(aDatabase, apQuery); SQLite::Statement query(aDatabase, apQuery);
bind_exec(query, std::forward<decltype(aArg)>(aArg)); bind_exec(query, std::forward<Arg>(aArg));
(void)std::initializer_list<int> (void)std::initializer_list<int>
{ {
((void)reset_bind_exec(query, std::forward<decltype(aParams)>(aParams)), 0)... ((void)reset_bind_exec(query, std::forward<Types>(aParams)), 0)...
}; };
} }
@ -63,11 +63,11 @@ void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&.
* @param apQuery Query to use * @param apQuery Query to use
* @param aTuple Tuple to bind * @param aTuple Tuple to bind
*/ */
template <typename ... Types> template <typename TupleT>
void reset_bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple) void reset_bind_exec(Statement& apQuery, TupleT&& aTuple)
{ {
apQuery.reset(); apQuery.reset();
bind_exec(apQuery, std::forward<decltype(aTuple)>(aTuple)); bind_exec(apQuery, std::forward<TupleT>(aTuple));
} }
/** /**
@ -78,10 +78,10 @@ void reset_bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple)
* @param apQuery Query to use * @param apQuery Query to use
* @param aTuple Tuple to bind * @param aTuple Tuple to bind
*/ */
template <typename ... Types> template <typename TupleT>
void bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple) void bind_exec(Statement& apQuery, TupleT&& aTuple)
{ {
bind(apQuery, std::forward<decltype(aTuple)>(aTuple)); SQLite::bind(apQuery, std::forward<TupleT>(aTuple));
while (apQuery.executeStep()) {} while (apQuery.executeStep()) {}
} }

View File

@ -5,7 +5,7 @@
* *
* Copyright (c) 2016 Paul Dreik (github@pauldreik.se) * Copyright (c) 2016 Paul Dreik (github@pauldreik.se)
* Copyright (c) 2016-2019 Sebastien Rombauts (sebastien.rombauts@gmail.com) * 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 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT) * or copy at http://opensource.org/licenses/MIT)

View File

@ -3,7 +3,7 @@
* @ingroup tests * @ingroup tests
* @brief Test of variadic bind * @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) * Copyright (c) 2019 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* *
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
@ -29,8 +29,8 @@ TEST(ExecuteMany, invalid)
EXPECT_TRUE(db.tableExists("test")); EXPECT_TRUE(db.tableExists("test"));
{ {
execute_many(db, "INSERT INTO test VALUES (?, ?)", execute_many(db, "INSERT INTO test VALUES (?, ?)",
std::make_tuple(1), 1,
std::make_tuple(2, "two"), std::make_tuple(2),
std::make_tuple(3, "three") std::make_tuple(3, "three")
); );
} }
@ -47,7 +47,7 @@ TEST(ExecuteMany, invalid)
EXPECT_EQ(std::size_t(3), results.size()); EXPECT_EQ(std::size_t(3), results.size());
EXPECT_EQ(std::make_pair(1,std::string{""}), results.at(0)); 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)); EXPECT_EQ(std::make_pair(3,std::string{"three"}), results.at(2));
} }
} }