Commit 5b1f460e authored by Lukas Appelhans's avatar Lukas Appelhans

Be able to insert hooks into database

parent e65b7e0f
......@@ -733,7 +733,6 @@ Group* Backend::loadGroupFromFile(const QString &path)
Hook* Backend::loadHookFromFile(const QString& path, QList<Package*> pkgs)
{
Q_D(Backend);
Hook * hook = 0;
QFile file(path);
......
......@@ -31,6 +31,7 @@
#include <sqlite3.h>
#include "md5.h"
#include "akabeihelpers_c.h"
#include "akabeihook.h"
namespace Akabei
{
......@@ -1108,14 +1109,47 @@ int QueryPerformer::removeFiles(sqlite3* db, Package* p)
return SQLITE_OK;
}
int QueryPerformer::insertHook(Database* db, const QString& hook, QList< Package* > p)
int QueryPerformer::insertHook(Database* db, Hook* hook)
{
return insertHook(QueryHelper::dbFromAkabeiDatabase(db), hook, p);
return insertHook(QueryHelper::dbFromAkabeiDatabase(db), hook);
}
int QueryPerformer::insertHook(sqlite3* db, const QString& hook, QList< Package* > p)
int QueryPerformer::insertHook(sqlite3* db, Hook* hook)
{
QString sqlQuery =
"INSERT INTO hooks ('Name', 'Hook', 'Packages') VALUES (:Name, :Hook, :Packages)";
// Now prepare
sqlite3_stmt *stmt = 0;
int result = sqlite3_prepare16_v2(db, sqlQuery.constData(), (sqlQuery.size() + 1) * sizeof(QChar),
&stmt, 0);
switch (result) {
case SQLITE_OK:
// Everything went fine and the handle is ready
break;
default:
// Errors. Take action here
return result;
break;
}
QStringList pkgs;
foreach (Package * p, hook->packages())
pkgs << QString::number(p->databaseId());
// Now go for all the bindings
if (!performBind(stmt, ":Name", hook->name())) finalizeAndReturn(stmt);
if (!performBind(stmt, ":Hook", hook->content())) finalizeAndReturn(stmt);
if (!performBind(stmt, ":Packages", stringFromStringList(pkgs))) finalizeAndReturn(stmt);
// Ok, do the query
result = sqlite3_step(stmt);
if (result != SQLITE_DONE) {
// errors...
return result;
}
sqlite3_finalize(stmt);
return SQLITE_OK;
}
int QueryPerformer::insertScriptlet(Database* db, Package* p)
......
......@@ -25,6 +25,7 @@ namespace Akabei {
class Package;
class Database;
class Group;
class Hook;
namespace Helpers
{
......@@ -76,8 +77,8 @@ namespace QueryPerformer
int AKABEICORESHARED_EXPORT removeScriptlet(Akabei::Database *db, Package *p);
int AKABEICORESHARED_EXPORT removeScriptlet(sqlite3 *db, Package *p);
int AKABEICORESHARED_EXPORT insertHook(Akabei::Database *db, const QString &hook, QList<Package*> p);
int AKABEICORESHARED_EXPORT insertHook(sqlite3 *db, const QString &hook, QList<Package*> p);
int AKABEICORESHARED_EXPORT insertHook(Akabei::Database *db, Hook * hook);
int AKABEICORESHARED_EXPORT insertHook(sqlite3 *db, Hook * hook);
}
class PackageEventLoop : public QEventLoop
......
......@@ -31,6 +31,12 @@ QString Akabei::Hook::name() const
return d->name;
}
QString Akabei::Hook::content() const
{
Q_D(const Hook);
return d->content;
}
QList< Akabei::Package* > Akabei::Hook::packages() const
{
Q_D(const Hook);
......
......@@ -31,6 +31,8 @@ class Hook
QString name() const;
QString content() const;
QList<Akabei::Package*> packages() const;
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment