Skip to content

Commit

Permalink
Improve execute many and fix binding
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann authored and SRombauts committed Jun 27, 2019
1 parent 2fff3a6 commit 66677ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions include/SQLiteCpp/ExecuteMany.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)...
};
}

Expand All @@ -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));
}

/**
Expand All @@ -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()) {}
}

Expand Down
2 changes: 1 addition & 1 deletion include/SQLiteCpp/VariadicBind.h
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/ExecuteMany_test.cpp
Expand Up @@ -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")
);
}
Expand All @@ -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));
}
}
Expand Down

0 comments on commit 66677ed

Please sign in to comment.