改了几个bug,提交
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QFile>
|
||||
#include "applicationmanager.h"
|
||||
#define MAX_KEY_LENGTH 255
|
||||
#define MAX_VALUE_NAME 16383
|
||||
|
||||
@ -782,7 +783,7 @@ bool SQLiteHelper::update_software()
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total + 1);
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
@ -1177,24 +1178,18 @@ bool SQLiteHelper::update_app()
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total + 1);
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1251,7 +1246,7 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||
query.addBindValue("app");
|
||||
query.addBindValue(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(orig_name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
@ -1266,6 +1261,31 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("<22><><EFBFBD><EFBFBD>"), QString::fromLocal8Bit("д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD><CAA7>"));
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
qDebug()<< query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1293,12 +1313,12 @@ bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||
qDebug() << work.lastError();
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
||||
bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit,bool all)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
if(is_edit)
|
||||
{
|
||||
if (!query.exec("select id,name,status,sort from kmd_category where is_edit=1;"))
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category where is_edit=1;"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1313,12 +1333,29 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
||||
categrory.id = query.value("id").toInt();
|
||||
categrory.sort = query.value("sort").toInt();
|
||||
categrory.display = query.value("status").toBool();
|
||||
categrory.total = query.value("total").toInt();
|
||||
categrories << categrory;
|
||||
}
|
||||
}
|
||||
else if (all&&(!is_edit)) {
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
Categrory categrory;
|
||||
categrory.name = query.value("name").toString();
|
||||
categrory.id = query.value("id").toInt();
|
||||
categrory.sort = query.value("sort").toInt();
|
||||
categrory.display = query.value("status").toBool();
|
||||
categrory.total = query.value("total").toInt();
|
||||
categrories << categrory;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!query.exec("select id,name,status,sort from kmd_category;"))
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1333,6 +1370,7 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit)
|
||||
categrory.id = query.value("id").toInt();
|
||||
categrory.sort = query.value("sort").toInt();
|
||||
categrory.display = query.value("status").toBool();
|
||||
categrory.total = query.value("total").toInt();
|
||||
categrories << categrory;
|
||||
}
|
||||
}
|
||||
@ -1393,7 +1431,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
@ -1415,34 +1453,21 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if(categories[i])
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if(!query2.exec())
|
||||
qDebug() << query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
if(query2.next())
|
||||
{
|
||||
QSqlQuery total(db);
|
||||
QSqlQuery query3(db);
|
||||
QString total_sql = "select id from kmd_menu where category_id like '%";
|
||||
total_sql += QString::number(i + 1);
|
||||
total_sql += "%';";
|
||||
total.exec(total_sql);
|
||||
query3.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query3.bindValue(":total", total.size());;
|
||||
query3.bindValue(":id", i + 1);
|
||||
if (!query3.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QSqlQuery commit(db);
|
||||
@ -1456,7 +1481,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
@ -1496,7 +1521,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
total_sql += "%';";
|
||||
total.exec(total_sql);
|
||||
query3.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query3.bindValue(":total", total.size());;
|
||||
query3.bindValue(":total", total.size()+1);
|
||||
query3.bindValue(":id", i + 1);
|
||||
if (!query3.exec())
|
||||
{
|
||||
@ -1512,3 +1537,33 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
||||
QString sql = "select * from kmd_menu where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (query.next())
|
||||
{
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (query.value("category_id").toString().contains(QString::number(i + 1))) {
|
||||
record->categories[i] = true;
|
||||
}
|
||||
else {
|
||||
record->categories[i] = false;
|
||||
}
|
||||
}
|
||||
record->sort = query.value("sort").toInt();
|
||||
record->name = query.value("name").toString();
|
||||
record->orig_name = query.value("orig_name").toString();
|
||||
record->op = query.value("op").toString();
|
||||
record->func = query.value("func").toString();
|
||||
record->exe_file = query.value("path").toString();
|
||||
record->url = query.value("url").toString();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user