Commit 2404c2f6 authored by Lisa's avatar Lisa Committed by Daniele Cocca
Browse files

Minor changes in queries

parent 1a8e04fc
......@@ -706,7 +706,8 @@ int QueryPerformer::insertPackage(SQLiteConnection &dbConnection, Package* p)
foreach (Akabei::Group *group, p->groups())
{
dbConnection.query("INSERT INTO groups ('name') VALUES ('" + group->name() + "');");
// Can I assume the group already exists?
//dbConnection.query("INSERT INTO groups ('name') VALUES ('" + group->name() + "');");
dbConnection.query("INSERT INTO belongs ('package', 'group') VALUES (" + QString::number(id) + ", '" + group->name() + "');");
}
......@@ -722,7 +723,7 @@ int QueryPerformer::insertPackage(SQLiteConnection &dbConnection, Package* p)
foreach (QString replace, p->replaces())
{
dbConnection.query("INSERT INTO depends ('package', 'replaces') VALUES (" + QString::number(id) + ", '" + replace + "');");
dbConnection.query("INSERT INTO replaces ('package', 'replaces') VALUES (" + QString::number(id) + ", '" + replace + "');");
}
foreach (QString provides, p->provides())
......@@ -787,6 +788,37 @@ int QueryPerformer::removePackage(SQLiteConnection &dbConnection, Package* p)
try {
dbConnection.bind(":id", p->databaseId());
dbConnection.query(sqlQuery);
foreach (Akabei::Group *group, p->groups()) {
dbConnection.bind(":id", p->databaseId());
dbConnection.query("DELETE FROM belongs WHERE package=:id AND group='" + group->name() + "';");
}
foreach (QString dependency, p->dependencies())
{
dbConnection.query("DELETE FROM depends WHERE package=" + QString::number(p->databaseId()) + " AND dependency='" + dependency + "');");
}
foreach (QString opt, p->optionalDependencies())
{
dbConnection.query("DELETE FROM optional WHERE package=" + QString::number(p->databaseId()) + " AND dependency='" + opt + "');");
}
foreach (QString replace, p->replaces())
{
dbConnection.query("DELETE FROM replaces WHERE package=" + QString::number(p->databaseId()) + " AND replaces='" + replace + "');");
}
foreach (QString provides, p->provides())
{
dbConnection.query("DELETE FROM provides WHERE package=" + QString::number(p->databaseId()) + " AND provides='" + provides + "');");
}
foreach (QString conflict, p->conflictsWith())
{
dbConnection.query("DELETE FROM conflicts WHERE package=" + QString::number(p->databaseId()) + " AND conflict='" + conflict + "');");
}
} catch(SQLiteException& e) {
qDebug() << "Error removing package: " << e.what();
return SQLITE_ABORT;
......@@ -852,6 +884,70 @@ int QueryPerformer::updatePackage(SQLiteConnection &dbConnection, Package* from,
dbConnection.bind(":PreviousPackageId", from->databaseId());
dbConnection.query(sqlQuery);
/*
* Delete every relation
*/
foreach (Akabei::Group *group, from->groups())
{
dbConnection.query("DELETE FROM belongs WHERE package=" + QString::number(from->databaseId()) + " AND group='" + group->name() + "';");
}
foreach (QString dependency, from->dependencies())
{
dbConnection.query("DELETE FROM depends WHERE package=" + QString::number(from->databaseId()) + " AND dependency='" + dependency + "');");
}
foreach (QString opt, from->optionalDependencies())
{
dbConnection.query("DELETE FROM optional WHERE package=" + QString::number(from->databaseId()) + " AND dependency='" + opt + "');");
}
foreach (QString replace, from->replaces())
{
dbConnection.query("DELETE FROM replaces WHERE package=" + QString::number(from->databaseId()) + " AND replaces='" + replace + "');");
}
foreach (QString provides, from->provides())
{
dbConnection.query("DELETE FROM provides WHERE package=" + QString::number(from->databaseId()) + " AND provides='" + provides + "');");
}
foreach (QString conflict, from->conflictsWith())
{
dbConnection.query("DELETE FROM conflicts WHERE package=" + QString::number(from->databaseId()) + " AND conflict='" + conflict + "');");
}
/* Insert everything again */
foreach (Akabei::Group *group, p->groups())
{
dbConnection.query("INSERT INTO belongs ('package', 'group') VALUES (" + QString::number(p->databaseId()) + ", '" + group->name() + "');");
}
foreach (QString dependency, p->dependencies())
{
dbConnection.query("INSERT INTO depends ('package', 'dependency') VALUES (" + QString::number(p->databaseId()) + ", '" + dependency + "');");
}
foreach (QString opt, p->optionalDependencies())
{
dbConnection.query("INSERT INTO optional ('package', 'dependency') VALUES (" + QString::number(p->databaseId()) + ", '" + opt + "');");
}
foreach (QString replace, p->replaces())
{
dbConnection.query("INSERT INTO replaces ('package', 'replaces') VALUES (" + QString::number(p->databaseId()) + ", '" + replace + "');");
}
foreach (QString provides, p->provides())
{
dbConnection.query("INSERT INTO provides ('package', 'provides') VALUES (" + QString::number(p->databaseId()) + ", '" + provides + "');");
}
foreach (QString conflict, p->conflictsWith())
{
dbConnection.query("INSERT INTO conflicts ('package', 'conflict') VALUES (" + QString::number(p->databaseId()) + ", '" + conflict + "');");
}
} catch (SQLiteException& e) {
qDebug() << "Error updating package: " << e.what();
return SQLITE_ABORT;
......
......@@ -41,7 +41,7 @@ The destructor does this for you.
4.2 Number of rows
You can now know the number of rows provided from the last query, calling
connection.getRowsNumber()
connection.getRowsCount()
4.3 Bindings
Bindings are now supported for integers, strings and QByteArrays. Call:
......
......@@ -40,7 +40,6 @@ class SQLiteConnection
sqlite3_stmt *statement;
QList<Row> rows;
QVariantMap bindings;
bool prepared;
void checkForErrors(int);
QString translateBindings(QString);
......
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