658 lines
28 KiB
C++
658 lines
28 KiB
C++
#include "sqlitedb.h"
|
|
|
|
SqliteDB* g_SqliteDB = NULL;
|
|
SqliteDB::SqliteDB()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
int SqliteDB::OpenDataBase()
|
|
{
|
|
QDir pluginsDir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
|
|
QString path1 = pluginsDir.absolutePath();
|
|
qDebug("Plugins path : %s", qPrintable(path1));
|
|
|
|
QString path = QDir::currentPath();
|
|
qDebug("currentPath : %s", qPrintable(path));
|
|
QApplication::addLibraryPath(path);
|
|
QPluginLoader loader(QString("./plugins/sqldrivers/qsqlite.dll"));
|
|
|
|
|
|
qDebug() << QSqlDatabase::drivers() << "\r\n";
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
db.setDatabaseName(QCoreApplication::applicationDirPath() + "\\config\\config.db");
|
|
if (!db.open())
|
|
{
|
|
qDebug() << "Error: Failed to connect database." << database.lastError();
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
QString strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
.arg("sqlite_master").arg("t_ChannelSetting").arg("confidenceDegree");
|
|
int iRet = ExeSqlData(strSql);
|
|
if(iRet == 0){
|
|
strSql = "ALTER TABLE t_ChannelSetting ADD COLUMN 'confidenceDegree' integer";
|
|
ExeSqlData(strSql);
|
|
}
|
|
strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
.arg("sqlite_master").arg("t_ChannelSetting").arg("sectionNum");
|
|
iRet = ExeSqlData(strSql);
|
|
if(iRet == 0){
|
|
strSql = "ALTER TABLE t_ChannelSetting ADD COLUMN 'sectionNum' integer";
|
|
ExeSqlData(strSql);
|
|
}
|
|
strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
.arg("sqlite_master").arg("t_ChannelSetting").arg("EngineeringUnit2");
|
|
iRet = ExeSqlData(strSql);
|
|
if(iRet == 0){
|
|
strSql = "ALTER TABLE t_ChannelSetting ADD COLUMN 'EngineeringUnit2' text";
|
|
ExeSqlData(strSql);
|
|
}
|
|
strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
.arg("sqlite_master").arg("t_ChannelSetting").arg("firstPoleNum");
|
|
iRet = ExeSqlData(strSql);
|
|
if(iRet == 0){
|
|
strSql = "ALTER TABLE t_ChannelSetting ADD COLUMN 'firstPoleNum' text";
|
|
ExeSqlData(strSql);
|
|
}
|
|
strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
.arg("sqlite_master").arg("t_TriggerConfig").arg("operate");
|
|
iRet = ExeSqlData(strSql);
|
|
if(iRet == 0){
|
|
strSql = "ALTER TABLE t_TriggerConfig ADD COLUMN 'operate' integer";
|
|
ExeSqlData(strSql);
|
|
}
|
|
// strSql = QString("select count(*) from %1 where name = '%2' and sql LIKE '%%3%' ")\
|
|
// .arg("sqlite_master").arg("t_WorkCondition").arg("operate");
|
|
// iRet = ExeSqlData(strSql);
|
|
// if(iRet == 0){
|
|
// strSql = "ALTER TABLE t_WorkCondition ADD COLUMN 'operate' integer";
|
|
// ExeSqlData(strSql);
|
|
// }
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
int SqliteDB::CreateDataBase()
|
|
{
|
|
|
|
|
|
}
|
|
int SqliteDB::QueryData(QString& tablename, QString& column, QString& whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
QString strSql = "select ";
|
|
if (whereCon != NULL) {
|
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
|
}
|
|
else {
|
|
strSql = strSql + column + " from " + tablename + ";";
|
|
}
|
|
qDebug() << strSql <<endl;
|
|
int count = -1;
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug()<<sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
count = sql_query.value(0).toInt();
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
QString SqliteDB::GetSingelLine(QString& tablename, QString& column, QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
QString result;
|
|
QString strSql = "select ";
|
|
if (whereCon != NULL) {
|
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
|
}
|
|
else {
|
|
strSql = strSql + column + " from " + tablename + ";";
|
|
}
|
|
qDebug() << strSql;
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
int i = 0;
|
|
QVariant temp;
|
|
while ((temp = sql_query.value(i++)).isValid()){
|
|
result += temp.toString();
|
|
result += ",";
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
QVector<ChannelSetting> SqliteDB::GetDataMultiLine(QString tablename, QString column, QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<ChannelSetting> vecResult;
|
|
ChannelSetting tempchannel;
|
|
QString strSql = "SELECT ";
|
|
if(column != ""){
|
|
strSql = strSql + column + " from " + tablename + " where " + whereCon + ";";
|
|
}
|
|
else{
|
|
strSql = QString("SELECT * FROM %1 order BY sensorModuleNo;").arg(tablename);
|
|
}
|
|
qDebug() << strSql;
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
if(tablename == "t_ChannelSetting"){
|
|
tempchannel.ChUnitCoeff = sql_query.value(0).toDouble();
|
|
tempchannel.ChUnitDot = sql_query.value(1).toInt();
|
|
tempchannel.sensorICP = sql_query.value(2).toBool();
|
|
tempchannel.sensorType = sql_query.value(3).toString();
|
|
tempchannel.bearingClearance = sql_query.value(4).toString();
|
|
tempchannel.bearingStartPosition = sql_query.value(5).toString();
|
|
tempchannel.channel1P5XAMP = sql_query.value(6).toBool();
|
|
tempchannel.channel1P5XAMPDefaultValue = sql_query.value(7).toInt();
|
|
tempchannel.channel1xAmpl = sql_query.value(8).toBool();
|
|
tempchannel.channel1xAmpleDefaultValue = sql_query.value(9).toInt();
|
|
tempchannel.channel2P5XAMP = sql_query.value(10).toBool();
|
|
tempchannel.channel2P5XAMPDefaultValue = sql_query.value(11).toInt();
|
|
tempchannel.channel2p5xAmpl = sql_query.value(12).toBool();
|
|
tempchannel.channel2p5xAmplDefaultValue = sql_query.value(13).toInt();
|
|
tempchannel.channel2xAmpl = sql_query.value(14).toBool();
|
|
tempchannel.channel2xAmplDefaultValue = sql_query.value(15).toInt();
|
|
tempchannel.channel3XAmpl = sql_query.value(16).toBool();
|
|
tempchannel.channel3XAmplDefaultValue = sql_query.value(17).toInt();
|
|
tempchannel.channelACHighpassband = sql_query.value(18).toInt();
|
|
tempchannel.channelDefaultValueEU = sql_query.value(19).toInt();
|
|
tempchannel.channelDirect = sql_query.value(20).toBool();
|
|
tempchannel.channelDirectDefaultValue = sql_query.value(21).toInt();
|
|
tempchannel.channelElement = sql_query.value(22).toBool();
|
|
tempchannel.channelElementDefaultValue = sql_query.value(23).toInt();
|
|
tempchannel.channelGapVoltage = sql_query.value(24).toBool();
|
|
tempchannel.channelGapVoltageDefaultValue= sql_query.value(25).toInt();
|
|
tempchannel.channelId = sql_query.value(26).toString();
|
|
tempchannel.channelIntDiff = sql_query.value(27).toString();
|
|
tempchannel.channelName = sql_query.value(28).toString();
|
|
tempchannel.channelNot1xAmp = sql_query.value(29).toBool();
|
|
tempchannel.channelNot1xAmpDefaultValue = sql_query.value(30).toInt();
|
|
tempchannel.channelOP5XAMP = sql_query.value(31).toBool();
|
|
tempchannel.channelOP5XAMPDefaultValue = sql_query.value(32).toInt();
|
|
tempchannel.channelRMSPkPk2Pk = sql_query.value(33).toString();
|
|
tempchannel.channelRecorderOutput = sql_query.value(34).toString();
|
|
tempchannel.channelRecorderOutputDefaultVal= sql_query.value(35).toInt();
|
|
tempchannel.channelRotor = sql_query.value(36).toBool();
|
|
tempchannel.channelRotorDefaultValue = sql_query.value(37).toInt();
|
|
tempchannel.channelSensorType = sql_query.value(38).toString();
|
|
tempchannel.channelSmax = sql_query.value(39).toBool();
|
|
tempchannel.channelSmaxDefaultValue = sql_query.value(40).toInt();
|
|
tempchannel.channelSpike = sql_query.value(41).toBool();
|
|
tempchannel.channelSpikeDefaultValue = sql_query.value(42).toInt();
|
|
tempchannel.comments = sql_query.value(43).toString();
|
|
tempchannel.couplingACDC = sql_query.value(44).toBool();
|
|
tempchannel.dataWatchNo = sql_query.value(45).toString();
|
|
tempchannel.envelopeHighpassband = sql_query.value(46).toDouble();
|
|
tempchannel.envelopeLowpassband = sql_query.value(47).toDouble();
|
|
tempchannel.equipmentId = sql_query.value(48).toInt();
|
|
tempchannel.filter = sql_query.value(49).toString();
|
|
tempchannel.frequencyRangeMax = sql_query.value(50).toString();
|
|
tempchannel.frequencyRangeMin = sql_query.value(51).toString();
|
|
tempchannel.fullScalePosition = sql_query.value(52).toInt();
|
|
tempchannel.highPassFrequency = sql_query.value(53).toString();
|
|
tempchannel.installMethod = sql_query.value(54).toString();
|
|
tempchannel.isEnable = sql_query.value(55).toInt();
|
|
tempchannel.isWork = sql_query.value(56).toInt();
|
|
tempchannel.lowPassFrequency = sql_query.value(57).toString();
|
|
tempchannel.measuringRange = sql_query.value(58).toString();
|
|
tempchannel.offset = sql_query.value(59).toInt();
|
|
tempchannel.pairChannelId = sql_query.value(60).toString();
|
|
tempchannel.pairChannelName = sql_query.value(61).toString();
|
|
tempchannel.rpmMultiplier = sql_query.value(62).toString();
|
|
tempchannel.samplingRate = sql_query.value(63).toInt();
|
|
tempchannel.sensor1xAmplitudeRunout = sql_query.value(64).toString();
|
|
tempchannel.sensor1xPhaseRunout = sql_query.value(65).toString();
|
|
tempchannel.sensorConfigureDate = sql_query.value(66).toString();
|
|
tempchannel.sensorEngineeringUnit = sql_query.value(67).toString();
|
|
tempchannel.sensorGapVoltage = sql_query.value(68).toString();
|
|
tempchannel.sensorLeftOrRight = sql_query.value(69).toString();
|
|
tempchannel.sensorLocationInDegree = sql_query.value(70).toInt();
|
|
tempchannel.sensorModuleNo = sql_query.value(71).toInt();
|
|
tempchannel.sensorNo = sql_query.value(72).toInt();
|
|
tempchannel.sensorRange = sql_query.value(73).toString();
|
|
tempchannel.sensorRangeCheck = sql_query.value(74).toBool();
|
|
tempchannel.sensorRangeMax = sql_query.value(75).toString();
|
|
tempchannel.sensorRangeMin = sql_query.value(76).toString();
|
|
tempchannel.sensorSensitivity = sql_query.value(77).toString();
|
|
tempchannel.shaftRotationDirection = sql_query.value(78).toString();
|
|
tempchannel.speedRefChannelId = sql_query.value(79).toString();
|
|
tempchannel.startBrands = sql_query.value(80).toString();
|
|
tempchannel.stopBrands = sql_query.value(81).toString();
|
|
tempchannel.tachAutoTach = sql_query.value(82).toBool();
|
|
tempchannel.tachTriggerEdge = sql_query.value(83).toString();
|
|
tempchannel.tachTriggerHysteresis = sql_query.value(84).toDouble();
|
|
tempchannel.tachTriggerPerRev = sql_query.value(85).toString();
|
|
tempchannel.tachTriggerVoltageLevel = sql_query.value(86).toDouble();
|
|
tempchannel.thermalCoupleType = sql_query.value(87).toString();
|
|
tempchannel.xFullScalePosition = sql_query.value(88).toString();
|
|
tempchannel.xProcessVariableName = sql_query.value(89).toString();
|
|
tempchannel.xZeroScalePosition = sql_query.value(90).toString();
|
|
tempchannel.zeroScalePosition = sql_query.value(91).toString();
|
|
tempchannel.boardType = sql_query.value(92).toString();
|
|
tempchannel.speedRefChannelName = sql_query.value(93).toString();
|
|
tempchannel.defaultDisplay = sql_query.value(94).toString();
|
|
tempchannel.sensorTypes = sql_query.value(95).toString();
|
|
tempchannel.confidenceDegree = sql_query.value(96).toInt();
|
|
tempchannel.sectionNum = sql_query.value(97).toInt();
|
|
tempchannel.EngineeringUnit = sql_query.value(98).toString();
|
|
tempchannel.firstPoleNum = sql_query.value(99).toString();
|
|
vecResult.append(tempchannel);
|
|
}
|
|
}
|
|
}
|
|
|
|
return vecResult;
|
|
}
|
|
|
|
QVector<WorkConditionChannels_t>
|
|
SqliteDB::GetWorkConditionChannels(QString tablename)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<WorkConditionChannels_t> vecResult;
|
|
WorkConditionChannels_t tempWokCondition;
|
|
QString strSql = QString("SELECT * FROM %1 order BY WorkConditionChannelType ; ").arg(tablename);
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempWokCondition.channelID = sql_query.value(0).toString();
|
|
tempWokCondition.BoardNo = sql_query.value(1).toInt();
|
|
tempWokCondition.ChannelDispalyName = sql_query.value(2).toString();
|
|
tempWokCondition.ChannelName = sql_query.value(3).toString();
|
|
tempWokCondition.ChannelNoInBoard = sql_query.value(4).toInt();
|
|
tempWokCondition.Enable = sql_query.value(5).toInt();
|
|
tempWokCondition.WorkConditionChannelType = sql_query.value(6).toInt();
|
|
vecResult.append(tempWokCondition);
|
|
}
|
|
}
|
|
|
|
return vecResult;
|
|
}
|
|
QVector<WorkCondition_t>
|
|
SqliteDB::GetWorkCondition(QString tablename,QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<WorkCondition_t> vecResult;
|
|
WorkCondition_t tempWokCondition;
|
|
QString strSql;
|
|
if(whereCon == "")
|
|
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
|
|
else
|
|
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempWokCondition.WorkConditionID = sql_query.value(0).toInt();
|
|
tempWokCondition.CheckWorkConditionInterval = sql_query.value(1).toString();
|
|
tempWokCondition.Description = sql_query.value(2).toString();
|
|
tempWokCondition.Enable = sql_query.value(3).toInt();
|
|
tempWokCondition.SN = sql_query.value(4).toString();
|
|
tempWokCondition.StartWorkCondition = sql_query.value(5).toString();
|
|
tempWokCondition.WorkConditionName = sql_query.value(6).toString();
|
|
QString strWorkConditionRules = sql_query.value(7).toString();
|
|
tempWokCondition.WorkConditionRules = strWorkConditionRules.split(",");
|
|
tempWokCondition.WorkConditionJudgeLogicRules = sql_query.value(8).toString();
|
|
vecResult.append(tempWokCondition);
|
|
}
|
|
}
|
|
|
|
return vecResult;
|
|
}
|
|
|
|
QVector<WorkConditionInfo_t>
|
|
SqliteDB::GetWorkConditionInfo(QString tablename,QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<WorkConditionInfo_t> vecResult;
|
|
WorkConditionInfo_t tempWokCondition;
|
|
QString strSql;
|
|
if(whereCon == "")
|
|
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
|
|
else
|
|
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
|
|
sql_query.exec(strSql);
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempWokCondition.ChannelId = sql_query.value(0).toString();
|
|
tempWokCondition.BoardNo = sql_query.value(1).toInt();
|
|
tempWokCondition.ChannelName = sql_query.value(2).toString();
|
|
tempWokCondition.ChannelNoInBoard = sql_query.value(3).toInt();
|
|
tempWokCondition.EnLowerSideOfRangePercent = sql_query.value(4).toString();
|
|
tempWokCondition.EnRangeUpper = sql_query.value(5).toString();
|
|
tempWokCondition.EnRangeLower = sql_query.value(6).toString();
|
|
tempWokCondition.EnVolatilityRangeUpper = sql_query.value(7).toString();
|
|
tempWokCondition.EnVolatilityRangeLower = sql_query.value(8).toString();
|
|
tempWokCondition.EnableCheckVolatility = sql_query.value(9).toString();
|
|
tempWokCondition.LowerSideOfRange = sql_query.value(10).toString();
|
|
tempWokCondition.UpperSideOfRange = sql_query.value(11).toString();
|
|
tempWokCondition.LowerSideOfVolatilityRange = sql_query.value(12).toString();
|
|
tempWokCondition.UpperSideOfVolatilityRange = sql_query.value(13).toString();
|
|
tempWokCondition.WorkConditionChannelType = sql_query.value(14).toInt();
|
|
tempWokCondition.SN = sql_query.value(15).toString();
|
|
tempWokCondition.WC_NO = sql_query.value(16).toInt();
|
|
tempWokCondition.DisplayName = sql_query.value(17).toString();
|
|
vecResult.append(tempWokCondition);
|
|
}
|
|
}
|
|
return vecResult;
|
|
}
|
|
|
|
QVector<TriggerConfig_t>
|
|
SqliteDB::GetTriggerConfig(QString tablename,QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<TriggerConfig_t> vecResult;
|
|
TriggerConfig_t tempTriggerConfig;
|
|
QString strSql;
|
|
if(whereCon == "")
|
|
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
|
|
else
|
|
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
|
|
sql_query.exec(strSql);
|
|
qDebug() << "strSql" <<strSql << endl;
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempTriggerConfig.ChannelID = sql_query.value(0).toString();
|
|
tempTriggerConfig.ChannelName = sql_query.value(1).toString();
|
|
tempTriggerConfig.WorkConditionID = sql_query.value(2).toInt();
|
|
tempTriggerConfig.WokrConditonName = sql_query.value(3).toString();
|
|
tempTriggerConfig.Characteristic = sql_query.value(4).toString();
|
|
tempTriggerConfig.AlertOver = sql_query.value(5).toInt();
|
|
tempTriggerConfig.AlertOverSetpoint = sql_query.value(6).toString();
|
|
tempTriggerConfig.DangerOver = sql_query.value(7).toInt();
|
|
tempTriggerConfig.DangerOverSetpoint = sql_query.value(8).toString();
|
|
tempTriggerConfig.AlertUnder = sql_query.value(9).toInt();
|
|
tempTriggerConfig.AlertUnderSetpoint = sql_query.value(10).toString();
|
|
tempTriggerConfig.DangerUnder = sql_query.value(11).toInt();
|
|
tempTriggerConfig.DangerUnderSetpoint = sql_query.value(12).toString();
|
|
tempTriggerConfig.AlertTriggerStatus = sql_query.value(13).toString();
|
|
tempTriggerConfig.DangerTriggerStatus = sql_query.value(14).toString();
|
|
tempTriggerConfig.AlertTriggerDelay = sql_query.value(15).toString();
|
|
tempTriggerConfig.DangerTriggerDelay = sql_query.value(16).toString();
|
|
tempTriggerConfig.TriggerType = sql_query.value(17).toString();
|
|
tempTriggerConfig.operate = sql_query.value(18).toInt();
|
|
vecResult.append(tempTriggerConfig);
|
|
g_mapTriggerEvent[tempTriggerConfig.ChannelID] = tempTriggerConfig;
|
|
}
|
|
}
|
|
return vecResult;
|
|
}
|
|
|
|
QVector<TriggerEvent_t>
|
|
SqliteDB::GetTriggerEvent(QString tablename,QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<TriggerEvent_t> vecResult;
|
|
TriggerEvent_t tempTriggerEvent;
|
|
QString strSql;
|
|
if(whereCon == "")
|
|
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
|
|
else
|
|
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
|
|
sql_query.exec(strSql);
|
|
qDebug() << "strSql" <<strSql << endl;
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempTriggerEvent.triggeredChannelName = sql_query.value(0).toString();
|
|
tempTriggerEvent.triggeredType = sql_query.value(1).toString();
|
|
tempTriggerEvent.triggeredValue = sql_query.value(2).toString();
|
|
tempTriggerEvent.triggeredNotification = sql_query.value(3).toString();
|
|
tempTriggerEvent.triggeredDataWatchNo = sql_query.value(4).toString();
|
|
tempTriggerEvent.triggeredDataWatchName = sql_query.value(5).toString();
|
|
tempTriggerEvent.triggeredChannelID = sql_query.value(6).toString();
|
|
tempTriggerEvent.triggeredTime = sql_query.value(7).toInt();
|
|
tempTriggerEvent.triggeredEquipmentID = sql_query.value(8).toInt();
|
|
tempTriggerEvent.triggeredEventName = sql_query.value(9).toString();
|
|
tempTriggerEvent.triggeredFeatureName = sql_query.value(10).toString();
|
|
|
|
vecResult.append(tempTriggerEvent);
|
|
}
|
|
}
|
|
return vecResult;
|
|
}
|
|
QVector<TriggerAlarmStatusInfo_t>
|
|
SqliteDB::GetTriggerAlarmStatusInfo(QString tablename,QString whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
|
|
QVector<TriggerAlarmStatusInfo_t> vecResult;
|
|
TriggerAlarmStatusInfo_t tempTriggerAlarmStatusInfo;
|
|
QString strSql;
|
|
if(whereCon == "")
|
|
strSql = QString("SELECT * FROM %1 ;").arg(tablename);
|
|
else
|
|
strSql = QString("SELECT * FROM %1 where %2;").arg(tablename).arg(whereCon);
|
|
sql_query.exec(strSql);
|
|
qDebug() << "strSql" <<strSql << endl;
|
|
if(!sql_query.exec())
|
|
{
|
|
qDebug() << "Error: Fail to query table. " << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
tempTriggerAlarmStatusInfo.UUID = sql_query.value(0).toString();
|
|
tempTriggerAlarmStatusInfo.channelID = sql_query.value(1).toString();
|
|
tempTriggerAlarmStatusInfo.channelName = sql_query.value(2).toString();
|
|
tempTriggerAlarmStatusInfo.flagOverUnder = sql_query.value(3).toString();
|
|
tempTriggerAlarmStatusInfo.timestamp = sql_query.value(4).toInt();
|
|
tempTriggerAlarmStatusInfo.resetTimestamp = sql_query.value(5).toInt();
|
|
tempTriggerAlarmStatusInfo.triggerEventName = sql_query.value(6).toString();
|
|
tempTriggerAlarmStatusInfo.triggerLevel = sql_query.value(7).toString();
|
|
tempTriggerAlarmStatusInfo.triggerStatus = sql_query.value(8).toString();
|
|
vecResult.append(tempTriggerAlarmStatusInfo);
|
|
}
|
|
}
|
|
return vecResult;
|
|
}
|
|
|
|
|
|
int SqliteDB::InsertData(QString& tablename,QString& sql)
|
|
{
|
|
QSqlQuery sql_query;
|
|
QString strSql = "INSERT INTO ";
|
|
strSql = strSql + tablename + sql;
|
|
qDebug() << "strSql" <<strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "";
|
|
}
|
|
|
|
}
|
|
int SqliteDB::UpdataData(QString& tablename, QString& columnName, QString& columnValue, QString whereColName, QString whereColValue)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
QString strSql = "update ";
|
|
if (whereColName != NULL) {
|
|
strSql = strSql + tablename + " set " + columnName + "='" + columnValue + "'" + " where " + whereColName + "='" + whereColValue + "';";
|
|
}
|
|
else {
|
|
strSql = strSql + tablename + " set " + columnName + "='" + columnValue + "';";
|
|
}
|
|
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
iRet = 0;
|
|
//qDebug() << "";
|
|
}
|
|
return iRet;
|
|
}
|
|
int SqliteDB::UpdateDataSql(QString& tablename,QString& UpdataSql)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
QString strSql = "update ";
|
|
strSql = strSql + tablename + UpdataSql;
|
|
qDebug() << strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
iRet = 0;
|
|
//qDebug() << "";
|
|
}
|
|
return iRet;
|
|
}
|
|
int SqliteDB::UpdataDataCol(QString& tablename, QString& updateColumn, QString& whereCond)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
QString strSql = "update ";
|
|
if (whereCond != NULL) {
|
|
strSql = strSql + tablename + " set " + updateColumn + " where " + whereCond;
|
|
}
|
|
else {
|
|
strSql = strSql + tablename + " set " + updateColumn ;
|
|
}
|
|
//qDebug() << "strSql" << strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
iRet = 0;
|
|
//qDebug() << "";
|
|
}
|
|
return iRet;
|
|
}
|
|
|
|
int SqliteDB::DeleteData(QString& tablename, QString condColumnName, QVariant condColumnValue)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
QString strSql = "delete from ";
|
|
if (condColumnName != NULL) {
|
|
strSql = strSql + tablename + " where " + condColumnName + " ='" + condColumnValue.toString() + "';";
|
|
}
|
|
else {
|
|
strSql = strSql + tablename + ";";
|
|
}
|
|
qDebug() << "strSql" << strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
iRet = 0;
|
|
qDebug() << "";
|
|
}
|
|
return iRet;
|
|
}
|
|
|
|
int SqliteDB::DeleteDataW(QString& tablename, QString& whereCon)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
QString strSql = "delete from ";
|
|
if (whereCon != NULL) {
|
|
strSql = strSql + tablename + " where " + whereCon + ";";
|
|
}
|
|
else {
|
|
strSql = strSql + tablename + ";";
|
|
}
|
|
qDebug() << "strSql" << strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
iRet = 0;
|
|
qDebug() << "";
|
|
}
|
|
return iRet;
|
|
}
|
|
|
|
int SqliteDB::ExeSqlData(QString& strSql)
|
|
{
|
|
QSqlQuery sql_query;
|
|
int iRet = -1;
|
|
qDebug() << "strSql" << strSql << endl;
|
|
if(!sql_query.exec(strSql))
|
|
{
|
|
qDebug() << sql_query.lastError();
|
|
}
|
|
else
|
|
{
|
|
while(sql_query.next())
|
|
{
|
|
iRet = sql_query.value(0).toInt();
|
|
}
|
|
}
|
|
return iRet;
|
|
}
|