}
}
+DB::SqlConnection::DataCommandAutoPtr & PrivilegeDb::getQuery(QueryType queryType)
+{
+ auto &command = m_commands.at(static_cast<size_t>(queryType));
+ command->Reset();
+ return command;
+}
+
PrivilegeDb::~PrivilegeDb()
{
delete mSqlConnection;
bool PrivilegeDb::PkgIdExists(const std::string &pkgId)
{
return try_catch<bool>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EPkgIdExists));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EPkgIdExists);
command->BindString(1, pkgId.c_str());
return command->Step();
});
bool PrivilegeDb::GetAppPkgId(const std::string &appId, std::string &pkgId)
{
return try_catch<bool>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EGetPkgId));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EGetPkgId);
command->BindString(1, appId.c_str());
if (!command->Step()) {
pkgIdIsNew = !(this->PkgIdExists(pkgId));
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EAddApplication));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EAddApplication);
command->BindString(1, appId.c_str());
command->BindString(2, pkgId.c_str());
command->BindInteger(3, static_cast<unsigned int>(uid));
return;
}
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::ERemoveApplication));
-
- command->Reset();
+ auto &command = getQuery(QueryType::ERemoveApplication);
command->BindString(1, appId.c_str());
command->BindInteger(2, static_cast<unsigned int>(uid));
std::vector<std::string> ¤tPrivileges)
{
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EGetPkgPrivileges));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EGetPkgPrivileges);
command->BindString(1, pkgId.c_str());
command->BindInteger(2, static_cast<unsigned int>(uid));
void PrivilegeDb::RemoveAppPrivileges(const std::string &appId, uid_t uid)
{
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::ERemoveAppPrivileges));
-
- command->Reset();
+ auto &command = getQuery(QueryType::ERemoveAppPrivileges);
command->BindString(1, appId.c_str());
command->BindInteger(2, static_cast<unsigned int>(uid));
if (command->Step()) {
const std::vector<std::string> &privileges)
{
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EAddAppPrivileges));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EAddAppPrivileges);
command->BindString(1, appId.c_str());
command->BindInteger(2, static_cast<unsigned int>(uid));
std::vector<std::string> &groups)
{
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EGetPrivilegeGroups));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EGetPrivilegeGroups);
command->BindString(1, privilege.c_str());
while (command->Step()) {
void PrivilegeDb::GetUserApps(uid_t uid, std::vector<std::string> &apps)
{
try_catch<void>([&] {
- DB::SqlConnection::DataCommandAutoPtr &command =
- m_commands.at(static_cast<size_t>(QueryType::EGetUserApps));
-
- command->Reset();
+ auto &command = getQuery(QueryType::EGetUserApps);
command->BindInteger(1, static_cast<unsigned int>(uid));
apps.clear();
while (command->Step()) {