mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Improve execute many and fix GCC 9 Build by explicitly scoping SQLiteCpp::bind()
Fix #206 #207
This commit is contained in:
parent
a637d24764
commit
3ba20a3519
@ -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 <typename Arg, typename... Types>
|
||||
void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&... aParams)
|
||||
{
|
||||
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)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 aTuple Tuple to bind
|
||||
*/
|
||||
template <typename ... Types>
|
||||
void reset_bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple)
|
||||
template <typename TupleT>
|
||||
void reset_bind_exec(Statement& apQuery, TupleT&& aTuple)
|
||||
{
|
||||
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 aTuple Tuple to bind
|
||||
*/
|
||||
template <typename ... Types>
|
||||
void bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple)
|
||||
template <typename TupleT>
|
||||
void bind_exec(Statement& apQuery, TupleT&& aTuple)
|
||||
{
|
||||
bind(apQuery, std::forward<decltype(aTuple)>(aTuple));
|
||||
SQLite::bind(apQuery, std::forward<TupleT>(aTuple));
|
||||
while (apQuery.executeStep()) {}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user