EffectIndexInfoService.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "EffectIndexInfoService.h"
  2. #include "SqlDBHelper.h"
  3. #include <QDebug>
  4. EffectIndexInfoService::EffectIndexInfoService(QObject *parent) { }
  5. int EffectIndexInfoService::AddEffectIndexInfo(const EffectIndexInfo &effectIndexInfo)
  6. {
  7. int ret = -1;
  8. try {
  9. Transaction t(SqlDBHelper::getDatabase());
  10. InsertQuery query = t.insertInto("t_effect_index_info(`project_id`, `effect_index_name`, `effect_index_value`, "
  11. "`effect_index_unit`, `extend_left`, `extend_right`)");
  12. NonQueryResult result = query.values(effectIndexInfo.projectId, effectIndexInfo.effectIndexName,
  13. effectIndexInfo.effectIndexValue, effectIndexInfo.effectIndexUnit,
  14. effectIndexInfo.extendLeft, effectIndexInfo.extendRight)
  15. .exec();
  16. t.commit();
  17. ret = result.lastInsertId().toInt();
  18. } catch (const DBException &ex) {
  19. qDebug() << ex.lastError.text();
  20. }
  21. return ret;
  22. }
  23. bool EffectIndexInfoService::QueryEffectIndexInfoByProjectId(QList<EffectIndexInfo *> *effectIndexInfoList,
  24. int projectId)
  25. {
  26. QSqlDatabase db = SqlDBHelper::getDatabase();
  27. QSqlQuery query(db);
  28. bool ret = false;
  29. QString selectSql =
  30. QString("SELECT id, "
  31. "project_id,effect_index_name,effect_index_value,effect_index_unit,extend_left,extend_right FROM "
  32. "t_effect_index_info WHERE project_id = %1")
  33. .arg(projectId);
  34. if (query.exec(selectSql)) {
  35. while (query.next()) {
  36. if (query.isNull(0) == false) {
  37. EffectIndexInfo *effectIndexInfo = new EffectIndexInfo;
  38. effectIndexInfo->id = query.value(0).toInt();
  39. effectIndexInfo->projectId = query.value(1).toInt();
  40. effectIndexInfo->effectIndexName = query.value(2).toString();
  41. effectIndexInfo->effectIndexValue = query.value(3).toString();
  42. effectIndexInfo->effectIndexUnit = query.value(4).toString();
  43. effectIndexInfo->extendLeft = query.value(5).toString();
  44. effectIndexInfo->extendRight = query.value(6).toString();
  45. effectIndexInfoList->append(effectIndexInfo);
  46. }
  47. }
  48. ret = true;
  49. } else {
  50. qDebug() << query.lastError();
  51. }
  52. return ret;
  53. }
  54. bool EffectIndexInfoService::UpdateEffectIndexInfo(const EffectIndexInfo &effectIndexInfo)
  55. {
  56. bool ret = false;
  57. try {
  58. Transaction t(SqlDBHelper::getDatabase());
  59. t.update("t_effect_index_info")
  60. .set("effect_index_name", effectIndexInfo.effectIndexName)
  61. .set("effect_index_value", effectIndexInfo.effectIndexValue)
  62. .set("effect_index_unit", effectIndexInfo.effectIndexUnit)
  63. .set("extend_left", effectIndexInfo.extendLeft)
  64. .set("extend_right", effectIndexInfo.extendRight)
  65. .where("id = ?", effectIndexInfo.id);
  66. t.commit();
  67. ret = true;
  68. } catch (const DBException &ex) {
  69. qDebug() << ex.lastError.text();
  70. }
  71. return ret;
  72. }