Skip to content

Instantly share code, notes, and snippets.

@barkady
Created June 7, 2017 11:38
Show Gist options
  • Save barkady/efaf9ec90db9fb7508db3a87a611fd54 to your computer and use it in GitHub Desktop.
Save barkady/efaf9ec90db9fb7508db3a87a611fd54 to your computer and use it in GitHub Desktop.
template<typename T>
Poco::Data::Statement& pocoSessionParameterBinder(Poco::Data::Statement& stmt, T& t);
template<>
Poco::Data::Statement& pocoSessionParameterBinder<Poco::Data::AbstractExtraction::Ptr>(Poco::Data::Statement& stmt, Poco::Data::AbstractExtraction::Ptr& t)
{
return stmt.addExtract(t);
}
template<>
Poco::Data::Statement& pocoSessionParameterBinder<Poco::Data::AbstractBinding::Ptr>(Poco::Data::Statement& stmt, Poco::Data::AbstractBinding::Ptr& t)
{
return stmt.addBind(t);
}
template<typename T, typename...Ts>
Poco::Data::Statement& pocoSessionParameterBinder(Poco::Data::Statement& stmt, T& t, Ts... Fargs)
{
return pocoSessionParameterBinder(pocoSessionParameterBinder(stmt, t), Fargs...);
}
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);
if (sizeof...(Fargs) > 0)
pocoSessionParameterBinder(stmt, Fargs...);
stmt.execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment