#include "EffectIndexInfoService.h" #include "SqlDBHelper.h" #include EffectIndexInfoService::EffectIndexInfoService(QObject *parent) { } int EffectIndexInfoService::AddEffectIndexInfo(const EffectIndexInfo &effectIndexInfo) { int ret = -1; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery query = t.insertInto("t_effect_index_info(`project_id`, `effect_index_name`, `effect_index_value`, " "`effect_index_unit`, `extend_left`, `extend_right`)"); NonQueryResult result = query.values(effectIndexInfo.projectId, effectIndexInfo.effectIndexName, effectIndexInfo.effectIndexValue, effectIndexInfo.effectIndexUnit, effectIndexInfo.extendLeft, effectIndexInfo.extendRight) .exec(); t.commit(); ret = result.lastInsertId().toInt(); } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool EffectIndexInfoService::QueryEffectIndexInfoByProjectId(QList *effectIndexInfoList, int projectId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, " "project_id,effect_index_name,effect_index_value,effect_index_unit,extend_left,extend_right FROM " "t_effect_index_info WHERE project_id = %1") .arg(projectId); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { EffectIndexInfo *effectIndexInfo = new EffectIndexInfo; effectIndexInfo->id = query.value(0).toInt(); effectIndexInfo->projectId = query.value(1).toInt(); effectIndexInfo->effectIndexName = query.value(2).toString(); effectIndexInfo->effectIndexValue = query.value(3).toString(); effectIndexInfo->effectIndexUnit = query.value(4).toString(); effectIndexInfo->extendLeft = query.value(5).toString(); effectIndexInfo->extendRight = query.value(6).toString(); effectIndexInfoList->append(effectIndexInfo); } } ret = true; } else { qDebug() << query.lastError(); } return ret; } bool EffectIndexInfoService::UpdateEffectIndexInfo(const EffectIndexInfo &effectIndexInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_effect_index_info") .set("effect_index_name", effectIndexInfo.effectIndexName) .set("effect_index_value", effectIndexInfo.effectIndexValue) .set("effect_index_unit", effectIndexInfo.effectIndexUnit) .set("extend_left", effectIndexInfo.extendLeft) .set("extend_right", effectIndexInfo.extendRight) .where("id = ?", effectIndexInfo.id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; }