#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 < SqliteDB::GetDataMultiLine(QString tablename, QString column, QString whereCon) { QSqlQuery sql_query; QVector 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 SqliteDB::GetWorkConditionChannels(QString tablename) { QSqlQuery sql_query; QVector 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 SqliteDB::GetWorkCondition(QString tablename,QString whereCon) { QSqlQuery sql_query; QVector 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 SqliteDB::GetWorkConditionInfo(QString tablename,QString whereCon) { QSqlQuery sql_query; QVector 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 SqliteDB::GetTriggerConfig(QString tablename,QString whereCon) { QSqlQuery sql_query; QVector 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" < SqliteDB::GetTriggerEvent(QString tablename,QString whereCon) { QSqlQuery sql_query; QVector 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" < SqliteDB::GetTriggerAlarmStatusInfo(QString tablename,QString whereCon) { QSqlQuery sql_query; QVector 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" <