Last active
June 6, 2017 10:35
-
-
Save barkady/78c6f1d51a911e18a78fd464369a9d69 to your computer and use it in GitHub Desktop.
20170506_3.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename...Ts> | |
void variadicExecutor(Ts&&...) {} | |
template<typename T> | |
Poco::Data::Statement& pocoSessionParameterBinder(Poco::Data::Statement& stmt, T&& t); | |
template<> | |
Poco::Data::Statement& pocoSessionParameterBinder(Poco::Data::Statement& stmt, Poco::Data::AbstractExtraction::Ptr&& t) | |
{ | |
return stmt.addExtract(t); | |
} | |
template<> | |
Poco::Data::Statement& pocoSessionParameterBinder(Poco::Data::Statement& stmt, Poco::Data::AbstractBinding::Ptr&& t) | |
{ | |
return stmt.addBind(t); | |
} | |
template<typename... Ts> | |
bool execute(Poco::Data::Session& session, std::string sql, Ts... Fargs) | |
{ | |
//Do any stuff you should for each execute. | |
//For example, I met problem, that if SQL server disturb session, there | |
//is no way get known this, using `Poco::Data` interface. So I just | |
//got exception on "execute" step postfactum, and had to handle it and | |
//recreate session. | |
Poco::Data::Statement stmt = (session << sql); | |
variadicExecutor(pocoSessionParameterBinder(stmt, Fargs)...); | |
stmt.execute(); | |
} | |
//Somewhere else | |
execute(session, query, | |
into(pHomer, 0), use(aHomer), | |
into(aBart, 1), | |
into(pLisa, 2), use(aLisa)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment