#include "stdafx.h"
|
#include "SECSRuntimeManager.h"
|
|
// ³£Á¿
|
const std::string DATABASE_FILE = R"(SECSDataManager.db)";
|
|
// ¾²Ì¬³ÉÔ±³õʼ»¯
|
std::mutex SECSRuntimeManager::m_mutex;
|
|
// »ñÈ¡µ¥ÀýʵÀý
|
SECSRuntimeManager& SECSRuntimeManager::getInstance() {
|
static SECSRuntimeManager instance;
|
return instance;
|
}
|
|
// ¹¹Ô캯Êý
|
SECSRuntimeManager::SECSRuntimeManager() {
|
m_pDB = new BL::SQLiteDatabase();
|
}
|
|
// Îö¹¹º¯Êý
|
SECSRuntimeManager::~SECSRuntimeManager() {
|
termRuntimeSetting();
|
|
if (m_pDB != nullptr) {
|
delete m_pDB;
|
m_pDB = nullptr;
|
}
|
}
|
|
// ´ÓÊý¾Ý¿âÖлñÈ¡ÕûÊý
|
int SECSRuntimeManager::getIntFromDB(const std::string& query) {
|
auto results = m_pDB->fetchResults(query);
|
if (!results.empty() && !results[0].empty()) {
|
// ת»»µÚÒ»¸ö²éѯ½á¹ûΪÕûÊý
|
return std::stoi(results[0][0]);
|
}
|
|
return 0;
|
}
|
|
// ÅжÏVIDÊÇ·ñÖØ¸´
|
bool SECSRuntimeManager::isIDDuplicate(int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return false;
|
}
|
|
// ¶¨ÒåÒª¼ì²éµÄ±í
|
std::vector<std::string> tables = { "SystemSV", "EqpSV", "SystemDV", "EqpDV", "SystemEC", "EqpEC" };
|
|
// ±éÀú±í£¬¼ì²éÊÇ·ñÓÐÖØ¸´µÄ ID
|
for (const auto& table : tables) {
|
// ´´½¨ SQL ²éѯ
|
std::string checkSQL = "SELECT COUNT(*) FROM " + table + " WHERE ID = " + std::to_string(nID) + ";";
|
|
// Ö´Ðвéѯ
|
auto results = m_pDB->fetchResults(checkSQL);
|
int count = (!results.empty() && !results[0].empty()) ? std::stoi(results[0][0]) : 0;
|
|
// Èç¹ûÕÒµ½ÁËÖØ¸´µÄ ID£¬Ôò·µ»Ø true
|
if (count > 0) {
|
return true;
|
}
|
}
|
|
// Èç¹ûûÓÐÖØ¸´£¬·µ»Ø false
|
return false;
|
}
|
|
// ÅжÏÃû³ÆÊÇ·ñÖØ¸´
|
bool SECSRuntimeManager::isNameDuplicate(const std::string& sName) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return false;
|
}
|
|
// ¶¨ÒåÒª¼ì²éµÄ±í
|
std::vector<std::string> tables = { "SystemSV", "EqpSV", "SystemDV", "EqpDV", "SystemEC", "EqpEC" };
|
|
// ±éÀú±í£¬¼ì²éÊÇ·ñÓÐÖØ¸´µÄ Name
|
for (const auto& table : tables) {
|
// ´´½¨ SQL ²éѯ
|
std::string checkSQL = "SELECT COUNT(*) FROM " + table + " WHERE Name = '" + sName + "';";
|
|
// Ö´Ðвéѯ
|
auto results = m_pDB->fetchResults(checkSQL);
|
int count = (!results.empty() && !results[0].empty()) ? std::stoi(results[0][0]) : 0;
|
|
// Èç¹ûÕÒµ½ÁËÖØ¸´µÄ Name£¬Ôò·µ»Ø true
|
if (count > 0) {
|
return true;
|
}
|
}
|
|
// Èç¹ûûÓÐÖØ¸´£¬·µ»Ø false
|
return false;
|
}
|
|
// ɾ³ýÖ¸¶¨±íµÄËùÓÐÊý¾Ý
|
int SECSRuntimeManager::deleteAllDataFromTable(const std::string& tableName) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¹¹½¨É¾³ýËùÓÐÊý¾ÝµÄ SQL Óï¾ä, ÖØÖÃ×ÔÔö ID
|
std::string deleteSQL = "TRUNCATE TABLE " + tableName + ";";
|
if (!m_pDB->executeQuery(deleteSQL)) {
|
return 2;
|
}
|
|
return 0; // ɾ³ý³É¹¦£¬·µ»Ø 0 ±íʾ²Ù×÷³É¹¦Íê³É¡£
|
}
|
|
// ²éѯָ¶¨±íËùÓÐÊý¾Ý
|
bool SECSRuntimeManager::getAllDataFromTable(const std::string& tableName, std::vector<std::vector<std::string>>& outData) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return false; // Êý¾Ý¿âÁ¬½Óʧ°Ü
|
}
|
|
// ²éѯ SQL Óï¾ä£¬»ñȡָ¶¨±íµÄËùÓÐÊý¾Ý
|
std::string querySQL = "SELECT * FROM " + tableName + ";";
|
outData = m_pDB->fetchResults(querySQL); // ʹÓÃÊä³ö²ÎÊý¸³Öµ½á¹û
|
|
return true; // ²éѯ³É¹¦
|
}
|
|
// ɾ³ýÖ¸¶¨±íÖÐÖ¸¶¨ ID µÄÊý¾Ý
|
int SECSRuntimeManager::deleteDataByID(const std::string& tableName, int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó£¬·µ»Ø 1
|
}
|
|
// ¼ì²é ID ÊÇ·ñ´æÔÚ
|
if (!isIDDuplicate(nID)) {
|
return 2; // ID ²»´æÔÚ£¬·µ»Ø 2
|
}
|
|
// ¹¹½¨É¾³ý SQL Óï¾ä
|
std::string deleteSQL = "DELETE FROM " + tableName + " WHERE ID = " + std::to_string(nID) + ";";
|
if (!m_pDB->executeQuery(deleteSQL)) {
|
return 3; // ɾ³ýʧ°Ü£¬·µ»Ø 3
|
}
|
|
return 0; // ɾ³ý³É¹¦£¬·µ»Ø 0
|
}
|
|
// ÉèÖÃÊý¾Ý¿âÁ¬½Ó
|
void SECSRuntimeManager::setDatabase(BL::Database* db) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
m_pDB = db;
|
}
|
|
// ³õʼ»¯SECSÉèÖùÜÀí¿â
|
bool SECSRuntimeManager::initRuntimeSetting() {
|
char path[MAX_PATH];
|
GetModuleFileName(NULL, path, MAX_PATH);
|
std::string exePath(path);
|
std::string dbFileDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\DB";
|
if (!CreateDirectory(dbFileDir.c_str(), NULL) && ERROR_ALREADY_EXISTS != GetLastError()) {
|
throw std::runtime_error("Failed to create database directory.");
|
}
|
|
std::string dbFilePath = dbFileDir + "\\" + DATABASE_FILE;
|
if (!m_pDB->connect(dbFilePath, true)) {
|
return false;
|
}
|
|
// ³õʼ»¯ SystemSV ±í
|
initSystemSVTable();
|
|
// ³õʼ»¯ EqpSV ±í
|
initEqpSVTable();
|
|
// ³õʼ»¯ SystemDV ±í
|
initSystemDVTable();
|
|
// ³õʼ»¯ EqpDV ±í
|
initEqpDVTable();
|
|
// ³õʼ»¯ SystemEC ±í
|
initSystemECTable();
|
|
// ³õʼ»¯ EqpEC ±í
|
initEqpECTable();
|
|
// ³õʼ»¯ SystemECID ±í
|
initSystemEventTable();
|
|
// ³õʼ»¯ EqpECID ±í
|
initEqpEventTable();
|
|
// ³õʼ»¯ SystemEventLink ±í
|
initEventLinkTable();
|
|
// ³õʼ»¯ PPID ±í
|
initPPIDTable();
|
|
// ³õʼ»¯ RPTID ±í
|
initRPTIDTable();
|
|
return true;
|
}
|
|
// Ïú»ÙSECSÉèÖùÜÀí¿â
|
void SECSRuntimeManager::termRuntimeSetting() {
|
if (m_pDB != nullptr) {
|
m_pDB->disconnect();
|
}
|
}
|
|
// ³õʼ»¯Ö¸¶¨µÄ SystemV ±í
|
void SECSRuntimeManager::initSystemVTable(const std::string& tableName) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨±íµÄ SQL Óï¾ä
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
"ID INTEGER PRIMARY KEY, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"DataType TEXT NOT NULL, "
|
"Length INTEGER NULL, "
|
"Unit TEXT NULL, "
|
"Remark TEXT, "
|
"SystemID INTEGER);";
|
|
// Ö´Ðд´½¨±í²Ù×÷
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create " + tableName + " table.");
|
}
|
}
|
|
// Ìí¼ÓÖ¸¶¨µÄ SystemV ±í
|
int SECSRuntimeManager::addSystemVData(const std::string& tableName, int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ¼ì²é ID ºÍ Name ÊÇ·ñÖØ¸´
|
if (isIDDuplicate(nID)) {
|
return 2; // ID ÖØ¸´
|
}
|
|
if (isNameDuplicate(sName)) {
|
return 3; // Name ÖØ¸´
|
}
|
|
// ¹¹½¨²åÈëÓï¾ä
|
std::string insertSQL = "INSERT INTO " + tableName + " (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
|
+ std::to_string(nID) + ", '"
|
+ sName + "', '"
|
+ sDataType + "', "
|
+ (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
|
+ ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
|
+ sRemark + "', "
|
+ std::to_string(nSystemID) + ");";
|
|
// Ö´ÐвåÈë²Ù×÷
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 4; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ²åÈë³É¹¦
|
}
|
|
// »ñȡָ¶¨ ID µÄ SystemV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemVByID(const std::string& tableName, int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {}; // Èç¹ûÊý¾Ý¿âδÁ¬½Ó£¬·µ»Ø¿Õ½á¹û
|
}
|
|
// ¹¹½¨²éѯ SQL Óï¾ä
|
std::string query = "SELECT * FROM " + tableName + " WHERE ID = " + std::to_string(nID) + ";";
|
|
// Ö´Ðвéѯ²¢·µ»Ø½á¹û
|
return m_pDB->fetchResults(query);
|
}
|
|
// »ñÈ¡ SystemV µÄËùÓÐÊý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemV(const std::string& tableName) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {}; // Èç¹ûÊý¾Ý¿âδÁ¬½Ó£¬·µ»Ø¿Õ½á¹û
|
}
|
|
// ¹¹½¨²éѯ SQL Óï¾ä
|
std::string query = "SELECT * FROM " + tableName + ";";
|
|
// Ö´Ðвéѯ²¢·µ»Ø½á¹û
|
return m_pDB->fetchResults(query);
|
}
|
|
// ¸üРSystemV µÄ ID Êý¾Ý
|
int SECSRuntimeManager::updateIDSystemV(const std::string& tableName, int nID, int sNewID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²éÊÇ·ñ´æÔڸà ID
|
if (!isIDDuplicate(nID)) {
|
return 2;
|
}
|
|
// ¼ì²éРID ÊÇ·ñÖØ¸´
|
if (isIDDuplicate(sNewID)) {
|
return 3;
|
}
|
|
// ¹¹½¨¸üÐ嵀 SQL Óï¾ä
|
std::string updateSQL = "UPDATE " + tableName + " SET ID = " + std::to_string(sNewID) + " WHERE ID = " + std::to_string(nID) + ";";
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4;
|
}
|
|
return 0;
|
}
|
|
// ¸üРSystemV µÄËùÓÐ×Ö¶Î
|
int SECSRuntimeManager::updateAllSystemV(const std::string& tableName, int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²éÊÇ·ñ´æÔڸà ID
|
if (!isIDDuplicate(nID)) {
|
return 2;
|
}
|
|
// ¼ì²éÐ嵀 ID ÊÇ·ñÒÑ´æÔÚ£¬Èç¹ûÒÑ´æÔÚ£¬Ôò·µ»Ø´íÎó´úÂë 3¡£
|
if (isIDDuplicate(sNewID)) {
|
return 3;
|
}
|
|
// ¹¹½¨¸üÐ嵀 SQL Óï¾ä
|
std::string updateSQL = "UPDATE " + tableName + " SET ";
|
|
bool firstField = true;
|
|
// Èç¹ûÐ嵀 ID ±»Ìṩ£¬¸üРID
|
if (sNewID > 0) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "ID = " + std::to_string(sNewID);
|
firstField = false;
|
}
|
|
// ¸üРName
|
if (!sName.empty()) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
// ¸üРDataType
|
if (!sDataType.empty()) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "DataType = '" + sDataType + "'";
|
firstField = false;
|
}
|
|
// ¸üРLength
|
if (nLength > 0) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "Length = " + std::to_string(nLength);
|
firstField = false;
|
}
|
|
// ¸üРUnit
|
if (sUnit != "NULL" && !sUnit.empty()) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "Unit = '" + sUnit + "'";
|
firstField = false;
|
}
|
else if (sUnit == "NULL") {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "Unit = NULL";
|
firstField = false;
|
}
|
|
// ¸üРRemark
|
if (!sRemark.empty()) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
// ¸üРSystemID
|
if (nSystemID > 0) {
|
if (!firstField) {
|
updateSQL += ", ";
|
}
|
updateSQL += "SystemID = " + std::to_string(nSystemID);
|
}
|
|
// Ìí¼Ó WHERE ×Ó¾äÀ´Ö¸¶¨¸üÐÂÄĸö¼Ç¼
|
updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
|
|
// Ö´ÐиüвÙ×÷
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4;
|
}
|
|
return 0;
|
}
|
|
// ³õʼ»¯Ö¸¶¨µÄ EqpV ±í
|
void SECSRuntimeManager::initEqpVTable(const std::string& tableName) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨É豸±íµÄ SQL Óï¾ä
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
"ID INTEGER PRIMARY KEY, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"DataType TEXT NOT NULL, "
|
"Length INTEGER NULL, "
|
"Unit TEXT NULL, "
|
"Remark TEXT, "
|
"SeqNo INTEGER);";
|
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create " + tableName + " table.");
|
}
|
}
|
|
// Ìí¼ÓÖ¸¶¨ EqpV ±íµÄÊý¾Ý
|
int SECSRuntimeManager::addEqpVData(const std::string& tableName, int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²é ID ÊÇ·ñÖØ¸´
|
if (isIDDuplicate(nID)) {
|
return 2;
|
}
|
|
// ¼ì²é Name ÊÇ·ñÖØ¸´
|
if (isNameDuplicate(sName)) {
|
return 3;
|
}
|
|
// ¹¹½¨ SQL ²åÈëÓï¾ä
|
std::string insertSQL = "INSERT INTO " + tableName + " (ID, Name, DataType, Length, Unit, Remark, SeqNo) VALUES ("
|
+ std::to_string(nID) + ", '"
|
+ sName + "', '"
|
+ sDataType + "', "
|
+ ((nLength <= 0) ? "NULL" : std::to_string(nLength)) + ", "
|
+ ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
|
+ sRemark + "', "
|
+ std::to_string(nSeqNo) + ");";
|
|
// Ö´ÐвåÈë²Ù×÷
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 4;
|
}
|
|
return 0; // ²åÈë³É¹¦£¬·µ»Ø 0 ±íʾ²Ù×÷³É¹¦Íê³É¡£
|
}
|
|
// ²éѯָ¶¨ ID µÄ EqpV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpVDataByID(const std::string& tableName, int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
// ²éѯ SQL Óï¾ä
|
std::string querySQL = "SELECT * FROM " + tableName + " WHERE ID = " + std::to_string(nID) + ";";
|
return m_pDB->fetchResults(querySQL); // Ö±½Ó·µ»Ø²éѯ½á¹û
|
}
|
|
// ¸üÐÂÖ¸¶¨µÄ EqpV Êý¾Ý
|
int SECSRuntimeManager::updateEqpV(const std::string& tableName, int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Èç¹ûÊý¾Ý¿âδÁ¬½Ó£¬·µ»Ø 1
|
}
|
|
// ¼ì²éÊÇ·ñ´æÔڸà ID
|
if (!isIDDuplicate(nID)) {
|
return 2; // Èç¹û ID ²»´æÔÚ£¬·µ»Ø´íÎó´úÂë 2
|
}
|
|
// ¼ì²éÐ嵀 ID ÊÇ·ñÒÑ´æÔÚ
|
if (isIDDuplicate(nNewID) && nNewID != nID) {
|
return 3; // Èç¹ûРID ÒÑ´æÔÚ£¬·µ»Ø´íÎó´úÂë 3
|
}
|
|
// ¹¹½¨¸üРSQL Óï¾ä
|
std::string updateSQL = "UPDATE " + tableName + " SET ";
|
|
bool firstField = true;
|
|
// Èç¹ûÐ嵀 ID ±»Ìṩ£¬¸üРID
|
if (nNewID > 0 && nNewID != nID) {
|
updateSQL += "ID = " + std::to_string(nNewID);
|
firstField = false;
|
}
|
|
// ¸üРName
|
if (!sName.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
// ¸üРDataType
|
if (!sDataType.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "DataType = '" + sDataType + "'";
|
firstField = false;
|
}
|
|
// ¸üРLength
|
if (nLength > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Length = " + std::to_string(nLength);
|
firstField = false;
|
}
|
|
// ¸üРUnit
|
if (sUnit != "NULL" && !sUnit.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = '" + sUnit + "'";
|
firstField = false;
|
}
|
else if (sUnit == "NULL") {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = NULL";
|
firstField = false;
|
}
|
|
// ¸üРRemark
|
if (!sRemark.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
// ¸üРSeqNo
|
if (nSeqNo > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "SeqNo = " + std::to_string(nSeqNo);
|
}
|
|
// Ìí¼Ó WHERE ×Ӿ䣬¸üÐÂÖ¸¶¨ ID µÄÊý¾Ý
|
updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
|
|
// Ö´ÐиüвÙ×÷
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4; // Èç¹û¸üÐÂʧ°Ü£¬·µ»Ø´íÎó´úÂë 4
|
}
|
|
return 0; // ¸üгɹ¦£¬·µ»Ø 0
|
}
|
|
// ³õʼ»¯ SystemSV ±í
|
void SECSRuntimeManager::initSystemSVTable() {
|
initSystemVTable("SystemSV");
|
|
// Ô¤¶¨ÒåµÄ SV Êý¾Ý
|
std::vector<std::tuple<int, std::string, std::string, int, std::string, std::string, int>> svData = {
|
{1, "SYS_LICENSE_CODE", "ASCII", 0, "NULL", "License code (Formal; Evaluation; NoLicense)", 1},
|
{2, "SYS_LICENSE_STATUS", "UINT_1", 0, "NULL", "License status(0:Unauthorized; 1:Authorized; 2:Evaluation; 3:Evaluation Expiring; 4:Trial; 5:Trial End)", 2},
|
{3, "GEM_CLOCK", "ASCII", 0, "NULL", "System Clock", 3},
|
{4, "SYS_SECS_COMM_MODE", "UINT_1", 0, "NULL", "SECS Communication Mode(0:HSMS Mode; 1:SECSI Mode)", 4},
|
{5, "SYS_SECS_DRIVER_CONNECT_STATE", "UINT_1", 0, "NULL", "Initial SECS Driver Connect State(0:Stop; 1:Start)", 5}
|
};
|
|
for (const auto& entry : svData) {
|
int nID, nLength, nSystemID;
|
std::string sName, sDataType, sRemark, sUnit;
|
std::tie(nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID) = entry;
|
|
// ¼ì²é Name ÊÇ·ñÒÑ´æÔÚ
|
int count = getIntFromDB("SELECT COUNT(*) FROM SystemSV WHERE Name = '" + sName + "';");
|
if (count == 0) {
|
// ²åÈëÊý¾Ý
|
std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
|
+ std::to_string(nID) + ", '"
|
+ sName + "', '"
|
+ sDataType + "', "
|
+ (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
|
+ ((sUnit == "NULL") ? "NULL" : "'" + sUnit + "'") + ", '"
|
+ sRemark + "', "
|
+ std::to_string(nSystemID) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
throw std::runtime_error("Failed to insert SystemSV data.");
|
}
|
}
|
}
|
}
|
|
// Ìí¼Ó SystemSV Êý¾Ý
|
int SECSRuntimeManager::addSystemSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
return addSystemVData("SystemSV", nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
|
}
|
|
// »ñȡָ¶¨ ID µÄ SystemSV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemSVByID(int nID) {
|
return getSystemVByID("SystemSV", nID);
|
}
|
|
// »ñÈ¡ËùÓÐ SystemSV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemSV() {
|
return getAllSystemV("SystemSV");
|
}
|
|
// ¸üРSystemSV ±íÖÐµÄ ID
|
int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
|
return updateIDSystemV("SystemSV", nID, sNewID);
|
}
|
|
// ¸üÐÂËùÓÐ SystemSV Êý¾Ý
|
int SECSRuntimeManager::updateAllSystemSV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
return updateAllSystemV("SystemSV", nID, sNewID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
|
}
|
|
// ɾ³ýÖ¸¶¨ ID µÄ SystemSV Êý¾Ý
|
int SECSRuntimeManager::deleteSystemSVByID(int nID) {
|
return deleteDataByID("SystemSV", nID);
|
}
|
|
// ɾ³ýËùÓÐ SystemSV Êý¾Ý
|
int SECSRuntimeManager::deleteAllSystemSV() {
|
return deleteAllDataFromTable("SystemSV");
|
}
|
|
// ³õʼ»¯ EqpSV ±í
|
void SECSRuntimeManager::initEqpSVTable() {
|
initEqpVTable("EqpSV");
|
}
|
|
// Ìí¼Ó EqpSV Êý¾Ý
|
int SECSRuntimeManager::addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
return addEqpVData("EqpSV", nID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
|
}
|
|
// ²éÕÒÖ¸¶¨ ID µÄ EqpSV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID) {
|
return getEqpVDataByID("EqpSV", nID);
|
}
|
|
// ²éÕÒËùÓÐ EqpSV Êý¾Ý
|
bool SECSRuntimeManager::getAllEqpSV(std::vector<std::vector<std::string>>& outEqpSV) {
|
return getAllDataFromTable("EqpSV", outEqpSV);
|
}
|
|
// ¸üРEqpSV ±íÖ¸¶¨ ID µÄÊý¾Ý
|
int SECSRuntimeManager::updateEqpSV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
return updateEqpV("EqpSV", nID, nNewID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
|
}
|
|
// ɾ³ý EqpSV ±íÖ¸¶¨ ID µÄÊý¾Ý
|
int SECSRuntimeManager::deleteEqpSVByID(int nID) {
|
return deleteDataByID("EqpSV", nID);
|
}
|
|
// ɾ³ý EqpSV ±íÖеÄËùÓÐÊý¾Ý
|
int SECSRuntimeManager::deleteAllEqpSV() {
|
return deleteAllDataFromTable("EqpSV");
|
}
|
|
// ³õʼ»¯ SystemDV ±í
|
void SECSRuntimeManager::initSystemDVTable() {
|
initSystemVTable("SystemDV");
|
}
|
|
// Ìí¼Ó SystemDV Êý¾Ý
|
int SECSRuntimeManager::addSystemDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
return addSystemVData("SystemDV", nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
|
}
|
|
// »ñȡָ¶¨ ID µÄ SystemDV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemDVByID(int nID) {
|
return getSystemVByID("SystemDV", nID);
|
}
|
|
// »ñÈ¡ËùÓÐ SystemDV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemDV() {
|
return getAllSystemV("SystemDV");
|
}
|
|
// ¸üРSystemDV ±íÖÐµÄ ID
|
int SECSRuntimeManager::updateIDSystemDV(int nID, int sNewID) {
|
return updateIDSystemV("SystemDV", nID, sNewID);
|
}
|
|
// ¸üÐÂËùÓÐ SystemDV Êý¾Ý
|
int SECSRuntimeManager::updateAllSystemDV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
return updateAllSystemV("SystemDV", nID, sNewID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
|
}
|
|
// ɾ³ýÖ¸¶¨ ID µÄ SystemDV Êý¾Ý
|
int SECSRuntimeManager::deleteSystemDVByID(int nID) {
|
return deleteDataByID("SystemDV", nID);
|
}
|
|
// ɾ³ýËùÓÐ SystemDV Êý¾Ý
|
int SECSRuntimeManager::deleteAllSystemDV() {
|
return deleteAllDataFromTable("SystemDV");
|
}
|
|
// ³õʼ»¯ EqpDV ±í
|
void SECSRuntimeManager::initEqpDVTable() {
|
initEqpVTable("EqpDV");
|
}
|
|
// Ìí¼Ó EqpDV Êý¾Ý
|
int SECSRuntimeManager::addEqpDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
return addEqpVData("EqpDV", nID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
|
}
|
|
// ²éÕÒÖ¸¶¨ ID µÄ EqpDV Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpDVByID(int nID) {
|
return getEqpVDataByID("EqpDV", nID);
|
}
|
|
// »ñÈ¡ËùÓÐ EqpDV Êý¾Ý
|
bool SECSRuntimeManager::getAllEqpDV(std::vector<std::vector<std::string>>& outEqpDV) {
|
return getAllDataFromTable("EqpDV", outEqpDV);
|
}
|
|
// ¸üРEqpDV ±íÖ¸¶¨ ID µÄÊý¾Ý
|
int SECSRuntimeManager::updateEqpDV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
|
return updateEqpV("EqpDV", nID, nNewID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
|
}
|
|
// ɾ³ý EqpDV ±íÖ¸¶¨ ID µÄÊý¾Ý
|
int SECSRuntimeManager::deleteEqpDVByID(int nID) {
|
return deleteDataByID("EqpDV", nID);
|
}
|
|
// ɾ³ý EqpDV ±íÖеÄËùÓÐÊý¾Ý
|
int SECSRuntimeManager::deleteAllEqpDV() {
|
return deleteAllDataFromTable("EqpDV");
|
}
|
|
// ³õʼ»¯ SystemEC ±í
|
void SECSRuntimeManager::initSystemECTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ SystemEC ±í
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS SystemEC ("
|
"ID INTEGER PRIMARY KEY, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"DataType TEXT NOT NULL, "
|
"MinValue INTEGER NULL, "
|
"MaxValue INTEGER NULL, "
|
"DefaultVal INTEGER NULL, "
|
"Unit TEXT NULL, "
|
"Remark TEXT, "
|
"SystemID INTEGER);";
|
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create SystemEC table.");
|
}
|
}
|
|
// Ìí¼Ó SystemEC Êý¾Ý
|
int SECSRuntimeManager::addSystemEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
if (isIDDuplicate(nID)) {
|
return 2; // ID ÖØ¸´
|
}
|
|
if (isNameDuplicate(sName)) {
|
return 3; // Name ÖØ¸´
|
}
|
|
// ¹¹½¨²åÈë SQL Óï¾ä
|
std::string insertSQL = "INSERT INTO SystemEC (ID, Name, DataType, MinValue, MaxValue, DefaultVal, Unit, Remark, SystemID) VALUES ("
|
+ std::to_string(nID) + ", '" + sName + "', '" + sDataType + "', "
|
+ (nMinValue >= 0 ? std::to_string(nMinValue) : "NULL") + ", "
|
+ (nMaxValue >= 0 ? std::to_string(nMaxValue) : "NULL") + ", "
|
+ (nDefaultVal >= 0 ? std::to_string(nDefaultVal) : "NULL") + ", "
|
+ ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
|
+ sRemark + "', " + std::to_string(nSystemID) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 4; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ²åÈë³É¹¦
|
}
|
|
// ²éѯָ¶¨ ID µÄ SystemEC Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemECByID(int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM SystemEC WHERE ID = " + std::to_string(nID) + ";";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ²éѯËùÓÐ SystemEC Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemEC() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM SystemEC;";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ¸üÐÂÖ¸¶¨ ID µÄ SystemEC Êý¾Ý
|
int SECSRuntimeManager::updateSystemEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultVal, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²éÊÇ·ñ´æÔڸà ID
|
if (!isIDDuplicate(nID)) {
|
return 2;
|
}
|
|
// ¼ì²éÐ嵀 ID ÊÇ·ñÒÑ´æÔÚ
|
if (isIDDuplicate(nNewID) && nNewID != nID) {
|
return 3;
|
}
|
|
// ¹¹½¨¸üРSQL Óï¾ä
|
std::string updateSQL = "UPDATE SystemEC SET ";
|
|
bool firstField = true;
|
|
if (nNewID > 0 && nNewID != nID) {
|
updateSQL += "ID = " + std::to_string(nNewID);
|
firstField = false;
|
}
|
|
if (!sName.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
if (!sDataType.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "DataType = '" + sDataType + "'";
|
firstField = false;
|
}
|
|
if (nMinValue >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "MinValue = " + std::to_string(nMinValue);
|
firstField = false;
|
}
|
|
if (nMaxValue >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "MaxValue = " + std::to_string(nMaxValue);
|
firstField = false;
|
}
|
|
if (nDefaultVal >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "DefaultVal = " + std::to_string(nDefaultVal);
|
firstField = false;
|
}
|
|
if (sUnit != "NULL" && !sUnit.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = '" + sUnit + "'";
|
firstField = false;
|
}
|
else if (sUnit == "NULL") {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = NULL";
|
firstField = false;
|
}
|
|
if (!sRemark.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
if (nSystemID > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "SystemID = " + std::to_string(nSystemID);
|
}
|
|
updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
|
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4;
|
}
|
|
return 0;
|
}
|
|
// ɾ³ýÖ¸¶¨ ID µÄ SystemEC Êý¾Ý
|
int SECSRuntimeManager::deleteSystemECByID(int nID) {
|
return deleteDataByID("SystemEC", nID);
|
}
|
|
// ɾ³ýËùÓÐ SystemEC Êý¾Ý
|
int SECSRuntimeManager::deleteAllSystemEC() {
|
return deleteAllDataFromTable("SystemEC");
|
}
|
|
// ³õʼ»¯ EqpEC ±í
|
void SECSRuntimeManager::initEqpECTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ EqpEC ±í
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS EqpEC ("
|
"ID INTEGER PRIMARY KEY, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"DataType TEXT NOT NULL, "
|
"MinValue INTEGER NULL, "
|
"MaxValue INTEGER NULL, "
|
"DefaultValue INTEGER NULL, "
|
"Unit TEXT NULL, "
|
"Remark TEXT, "
|
"SeqNo INTEGER NOT NULL, "
|
"Length INTEGER NOT NULL, "
|
"CanUpdateByHost INTEGER NOT NULL);";
|
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create EqpEC table.");
|
}
|
}
|
|
// Ìí¼Ó EqpEC Êý¾Ý
|
int SECSRuntimeManager::addEqpEC(int nID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
if (isIDDuplicate(nID)) {
|
return 2; // ID ÖØ¸´
|
}
|
|
if (isNameDuplicate(sName)) {
|
return 3; // Name ÖØ¸´
|
}
|
|
// ¹¹½¨²åÈë SQL Óï¾ä
|
std::string insertSQL = "INSERT INTO EqpEC (ID, Name, DataType, MinValue, MaxValue, DefaultValue, Unit, Remark, SeqNo, Length, CanUpdateByHost) VALUES ("
|
+ std::to_string(nID) + ", '" + sName + "', '" + sDataType + "', "
|
+ (nMinValue >= 0 ? std::to_string(nMinValue) : "NULL") + ", "
|
+ (nMaxValue >= 0 ? std::to_string(nMaxValue) : "NULL") + ", "
|
+ (nDefaultValue >= 0 ? std::to_string(nDefaultValue) : "NULL") + ", "
|
+ ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
|
+ sRemark + "', " + std::to_string(nSeqNo) + ", "
|
+ std::to_string(nLength) + ", " + std::to_string(bCanUpdateByHost) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 4; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ²åÈë³É¹¦
|
}
|
|
// ²éѯָ¶¨ ID µÄ EqpEC Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpECByID(int nID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM EqpEC WHERE ID = " + std::to_string(nID) + ";";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ²éѯËùÓÐ EqpEC Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpEC() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM EqpEC;";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ¸üÐÂÖ¸¶¨ ID µÄ EqpEC Êý¾Ý
|
int SECSRuntimeManager::updateEqpEC(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nMinValue, int nMaxValue, int nDefaultValue, const std::string& sUnit, const std::string& sRemark, int nSeqNo, int nLength, int bCanUpdateByHost) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²éÊÇ·ñ´æÔڸà ID
|
if (!isIDDuplicate(nID)) {
|
return 2;
|
}
|
|
// ¼ì²éÐ嵀 ID ÊÇ·ñÒÑ´æÔÚ
|
if (isIDDuplicate(nNewID) && nNewID != nID) {
|
return 3;
|
}
|
|
// ¹¹½¨¸üРSQL Óï¾ä
|
std::string updateSQL = "UPDATE EqpEC SET ";
|
|
bool firstField = true;
|
|
if (nNewID > 0 && nNewID != nID) {
|
updateSQL += "ID = " + std::to_string(nNewID);
|
firstField = false;
|
}
|
|
if (!sName.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
if (!sDataType.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "DataType = '" + sDataType + "'";
|
firstField = false;
|
}
|
|
if (nMinValue >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "MinValue = " + std::to_string(nMinValue);
|
firstField = false;
|
}
|
|
if (nMaxValue >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "MaxValue = " + std::to_string(nMaxValue);
|
firstField = false;
|
}
|
|
if (nDefaultValue >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "DefaultValue = " + std::to_string(nDefaultValue);
|
firstField = false;
|
}
|
|
if (sUnit != "NULL" && !sUnit.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = '" + sUnit + "'";
|
firstField = false;
|
}
|
else if (sUnit == "NULL") {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Unit = NULL";
|
firstField = false;
|
}
|
|
if (!sRemark.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
if (nSeqNo > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "SeqNo = " + std::to_string(nSeqNo);
|
}
|
|
if (nLength > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Length = " + std::to_string(nLength);
|
}
|
|
if (bCanUpdateByHost >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "CanUpdateByHost = " + std::to_string(bCanUpdateByHost);
|
}
|
|
updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
|
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4;
|
}
|
|
return 0;
|
}
|
|
// ɾ³ýÖ¸¶¨ ID µÄ EqpEC Êý¾Ý
|
int SECSRuntimeManager::deleteEqpECByID(int nID) {
|
return deleteDataByID("EqpEC", nID);
|
}
|
|
// ɾ³ýËùÓÐ EqpEC Êý¾Ý
|
int SECSRuntimeManager::deleteAllEqpEC() {
|
return deleteAllDataFromTable("EqpEC");
|
}
|
|
// ³õʼ»¯ SystemEvent ±í
|
void SECSRuntimeManager::initSystemEventTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ SystemEvent ±í
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS SystemEvent ("
|
"CEID INTEGER PRIMARY KEY, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"Remark TEXT, "
|
"SystemID INTEGER);";
|
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create SystemEvent table.");
|
}
|
}
|
|
// Ìí¼Ó SystemEvent Êý¾Ý
|
int SECSRuntimeManager::addSystemEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ¹¹½¨ SQL ²åÈëÓï¾ä
|
std::string insertSQL = "INSERT INTO SystemEvent (CEID, Name, Remark, SystemID) VALUES ("
|
+ std::to_string(nCEID) + ", '" + sName + "', '" + sRemark + "', " + std::to_string(nSystemID) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 2; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ²åÈë³É¹¦
|
}
|
|
// ²éѯָ¶¨ CEID µÄ SystemEvent Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemEventByID(int nCEID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM SystemEvent WHERE CEID = " + std::to_string(nCEID) + ";";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ²éѯËùÓÐ SystemEvent Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemEvents() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM SystemEvent;";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ¸üÐÂÖ¸¶¨ CEID µÄ SystemEvent Êý¾Ý
|
int SECSRuntimeManager::updateSystemEvent(int nCEID, int nNewCEID, const std::string& sName, const std::string& sRemark, int nSystemID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¹¹½¨¸üРSQL Óï¾ä
|
std::string updateSQL = "UPDATE SystemEvent SET ";
|
|
bool firstField = true;
|
|
if (nNewCEID > 0 && nNewCEID != nCEID) {
|
updateSQL += "CEID = " + std::to_string(nNewCEID);
|
firstField = false;
|
}
|
|
if (!sName.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
if (!sRemark.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
if (nSystemID > 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "SystemID = " + std::to_string(nSystemID);
|
}
|
|
updateSQL += " WHERE CEID = " + std::to_string(nCEID) + ";";
|
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 2;
|
}
|
|
return 0;
|
}
|
|
// ɾ³ýÖ¸¶¨ CEID µÄ SystemEvent Êý¾Ý
|
int SECSRuntimeManager::deleteSystemEventByID(int nCEID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó£¬·µ»Ø 1
|
}
|
|
// ¹¹½¨É¾³ý SQL Óï¾ä
|
std::string deleteSQL = "DELETE FROM SystemEvent WHERE CEID = " + std::to_string(nCEID) + ";";
|
if (!m_pDB->executeQuery(deleteSQL)) {
|
return 2; // ɾ³ýʧ°Ü£¬·µ»Ø 2
|
}
|
|
return 0; // ɾ³ý³É¹¦£¬·µ»Ø 0
|
}
|
|
// ɾ³ýËùÓÐ SystemEvent Êý¾Ý
|
int SECSRuntimeManager::deleteAllSystemEvents() {
|
return deleteAllDataFromTable("SystemEvent");
|
}
|
|
// ³õʼ»¯ EqpEvent ±í
|
void SECSRuntimeManager::initEqpEventTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ EqpEvent ±í
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS EqpEvent ("
|
"CEID INTEGER PRIMARY KEY AUTOINCREMENT, "
|
"Name TEXT UNIQUE NOT NULL, "
|
"Remark TEXT, "
|
"BitNo INTEGER);";
|
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create EqpEvent table.");
|
}
|
}
|
|
// Ìí¼Ó EqpEvent Êý¾Ý
|
int SECSRuntimeManager::addEqpEvent(const std::string& sName, const std::string& sRemark, int nBitNo) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ¹¹½¨ SQL ²åÈëÓï¾ä
|
std::string insertSQL = "INSERT INTO EqpEvent (Name, Remark, BitNo) VALUES ('"
|
+ sName + "', '" + sRemark + "', " + std::to_string(nBitNo) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 2; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ²åÈë³É¹¦
|
}
|
|
// ²éѯָ¶¨ CEID µÄ EqpEvent Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpEventByID(int nCEID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM EqpEvent WHERE CEID = " + std::to_string(nCEID) + ";";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ²éѯËùÓÐ EqpEvent Êý¾Ý
|
std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpEvents() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
std::string querySQL = "SELECT * FROM EqpEvent;";
|
return m_pDB->fetchResults(querySQL);
|
}
|
|
// ¸üÐÂÖ¸¶¨ CEID µÄ EqpEvent Êý¾Ý
|
int SECSRuntimeManager::updateEqpEvent(int nCEID, const std::string& sName, const std::string& sRemark, int nBitNo) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¹¹½¨¸üРSQL Óï¾ä
|
std::string updateSQL = "UPDATE EqpEvent SET ";
|
|
bool firstField = true;
|
|
if (!sName.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Name = '" + sName + "'";
|
firstField = false;
|
}
|
|
if (!sRemark.empty()) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "Remark = '" + sRemark + "'";
|
firstField = false;
|
}
|
|
if (nBitNo >= 0) {
|
if (!firstField) updateSQL += ", ";
|
updateSQL += "BitNo = " + std::to_string(nBitNo);
|
}
|
|
updateSQL += " WHERE CEID = " + std::to_string(nCEID) + ";";
|
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 2;
|
}
|
|
return 0;
|
}
|
|
// ɾ³ýÖ¸¶¨ CEID µÄ EqpEvent Êý¾Ý
|
int SECSRuntimeManager::deleteEqpEventByID(int nCEID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó£¬·µ»Ø 1
|
}
|
|
// ¹¹½¨É¾³ý SQL Óï¾ä
|
std::string deleteSQL = "DELETE FROM EqpEvent WHERE CEID = " + std::to_string(nCEID) + ";";
|
if (!m_pDB->executeQuery(deleteSQL)) {
|
return 2; // ɾ³ýʧ°Ü£¬·µ»Ø 2
|
}
|
|
return 0; // ɾ³ý³É¹¦£¬·µ»Ø 0
|
}
|
|
// ɾ³ýËùÓÐ EqpEvent Êý¾Ý
|
int SECSRuntimeManager::deleteAllEqpEvents() {
|
return deleteAllDataFromTable("EqpEvent");
|
}
|
|
// ³õʼ»¯ EventLink ±í
|
void SECSRuntimeManager::initEventLinkTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ EventLink ±í
|
std::string createEventLinkSQL =
|
"CREATE TABLE IF NOT EXISTS EventLink ("
|
"CEID INTEGER, "
|
"RPTID INTEGER, "
|
"FOREIGN KEY (CEID) REFERENCES EqpEvent(CEID));";
|
|
if (!m_pDB->executeQuery(createEventLinkSQL)) {
|
throw std::runtime_error("Failed to create EventLink table.");
|
}
|
}
|
|
// ³õʼ»¯ PPID ±í
|
void SECSRuntimeManager::initPPIDTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ EqpPPID ±í
|
std::string createTableSQL =
|
"CREATE TABLE IF NOT EXISTS EqpPPID ("
|
"BitNo INTEGER PRIMARY KEY AUTOINCREMENT, "
|
"PPID INTEGER NULL);";
|
if (!m_pDB->executeQuery(createTableSQL)) {
|
throw std::runtime_error("Failed to create EqpPPID table.");
|
}
|
|
// Ïȼì²é±íÊÇ·ñΪ¿Õ
|
int nCount = getIntFromDB("SELECT COUNT(*) FROM EqpPPID;");
|
if (nCount == 0) {
|
// ²åÈë³õʼÊý¾Ý£¨512 ÐУ©
|
for (int nBitNo = 0; nBitNo < 512; ++nBitNo) {
|
std::string insertSQL = "INSERT INTO EqpPPID (BitNo) VALUES (" + std::to_string(nBitNo) + ");";
|
if (!m_pDB->executeQuery(insertSQL)) {
|
throw std::runtime_error("Failed to insert data into EqpPPID table.");
|
}
|
}
|
}
|
}
|
|
// ³õʼ»¯ RPTID ±í
|
void SECSRuntimeManager::initRPTIDTable() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ´´½¨ Report ±í
|
std::string createReportTableSQL =
|
"CREATE TABLE IF NOT EXISTS Report ("
|
"RPTID INTEGER PRIMARY KEY);";
|
|
// ´´½¨ ReportVIDs ±í£¬±£Ö¤Í¬Ò»¸ö RPTID Ï嵀 VID Ψһ
|
std::string createReportVIDsTableSQL =
|
"CREATE TABLE IF NOT EXISTS ReportVIDs ("
|
"RPTID INTEGER NOT NULL, "
|
"VID INTEGER NOT NULL, "
|
"FOREIGN KEY (RPTID) REFERENCES Report(RPTID), "
|
"UNIQUE(RPTID, VID));";
|
|
// Ö´Ðд´½¨±í²Ù×÷
|
if (!m_pDB->executeQuery(createReportTableSQL)) {
|
throw std::runtime_error("Failed to create Report table.");
|
}
|
if (!m_pDB->executeQuery(createReportVIDsTableSQL)) {
|
throw std::runtime_error("Failed to create ReportVIDs table.");
|
}
|
}
|
|
// Ìí¼Ó RPTID Êý¾Ý
|
int SECSRuntimeManager::addRPTIDVID(int nRPTID, int nVID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²é RPTID ºÍ VID µÄ×éºÏÊÇ·ñÒѾ´æÔÚ
|
std::string checkExistSQL = "SELECT COUNT(*) FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nVID) + ";";
|
int count = getIntFromDB(checkExistSQL);
|
if (count > 0) {
|
return 2; // Èç¹û¹ØÏµÒÑ´æÔÚ£¬·µ»Ø´íÎó´úÂë 2
|
}
|
|
// ¼ì²é Report ±íÖÐÊÇ·ñ´æÔڸà RPTID
|
std::string checkReportExistSQL = "SELECT COUNT(*) FROM Report WHERE RPTID = " + std::to_string(nRPTID) + ";";
|
int reportCount = getIntFromDB(checkReportExistSQL);
|
|
if (reportCount == 0) {
|
// Èç¹û RPTID ²»´æÔÚ£¬²åÈë RPTID
|
std::string insertReportSQL = "INSERT INTO Report (RPTID) VALUES (" + std::to_string(nRPTID) + ");";
|
if (!m_pDB->executeQuery(insertReportSQL)) {
|
return 3; // ²åÈëʧ°Ü£¬·µ»Ø´íÎó´úÂë 3
|
}
|
}
|
|
// ¹¹Ôì²åÈë SQL Óï¾ä
|
std::string insertSQL = "INSERT INTO ReportVIDs (RPTID, VID) VALUES ("
|
+ std::to_string(nRPTID) + ", "
|
+ std::to_string(nVID) + ");";
|
|
// Ö´ÐвåÈë²Ù×÷
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 4; // ²åÈëʧ°Ü£¬·µ»Ø´íÎó´úÂë 4
|
}
|
|
return 0; // ²åÈë³É¹¦£¬·µ»Ø 0
|
}
|
|
// »ñȡָ¶¨ RPTID µÄËùÓÐ VID
|
int SECSRuntimeManager::addRPTIDVIDs(int nRPTID, const std::vector<int>& vecVID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1;
|
}
|
|
// ¼ì²é Report ±íÖÐÊÇ·ñ´æÔڸà RPTID
|
std::string checkReportExistSQL = "SELECT COUNT(*) FROM Report WHERE RPTID = " + std::to_string(nRPTID) + ";";
|
int reportCount = getIntFromDB(checkReportExistSQL);
|
|
if (reportCount == 0) {
|
// Èç¹û RPTID ²»´æÔÚ£¬²åÈë RPTID
|
std::string insertReportSQL = "INSERT INTO Report (RPTID) VALUES (" + std::to_string(nRPTID) + ");";
|
if (!m_pDB->executeQuery(insertReportSQL)) {
|
return 2; // ²åÈëʧ°Ü£¬·µ»Ø´íÎó´úÂë 3
|
}
|
}
|
|
// ÅúÁ¿²åÈë VID ºÍ RPTID ¹ØÏµ
|
for (int nVID : vecVID) {
|
// ¼ì²éµ±Ç° RPTID ºÍ VID µÄ×éºÏÊÇ·ñÒѾ´æÔÚ
|
std::string checkExistSQL = "SELECT COUNT(*) FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nVID) + ";";
|
int count = getIntFromDB(checkExistSQL);
|
if (count == 0) {
|
// Èç¹û¹ØÏµ²»´æÔÚ£¬²åÈë
|
std::string insertSQL = "INSERT INTO ReportVIDs (RPTID, VID) VALUES ("
|
+ std::to_string(nRPTID) + ", "
|
+ std::to_string(nVID) + ");";
|
|
if (!m_pDB->executeQuery(insertSQL)) {
|
return 3; // ²åÈëʧ°Ü£¬·µ»Ø´íÎó´úÂë 3
|
}
|
}
|
}
|
|
return 0; // ²åÈë³É¹¦£¬·µ»Ø 0
|
}
|
|
// »ñȡָ¶¨ RPTID µÄËùÓÐ VID
|
int SECSRuntimeManager::deleteRPTIDVID(int nRPTID, int nVID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ¼ì²é ReportVIDs ±íÖÐÊÇ·ñ´æÔڸà RPTID ºÍ VID ×éºÏ
|
std::string checkExistSQL = "SELECT COUNT(*) FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nVID) + ";";
|
int count = getIntFromDB(checkExistSQL);
|
if (count == 0) {
|
return 2; // ¼Ç¼²»´æÔÚ
|
}
|
|
// ɾ³ý ReportVIDs ±íÖÐÖ¸¶¨ RPTID ºÍ VID µÄ¹ØÏµ
|
std::string deleteSQL = "DELETE FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nVID) + ";";
|
if (!m_pDB->executeQuery(deleteSQL)) {
|
return 3; // ɾ³ýʧ°Ü
|
}
|
|
return 0; // ɾ³ý³É¹¦
|
}
|
|
// ɾ³ýÖ¸¶¨ RPTID µÄËùÓÐ VID6
|
int SECSRuntimeManager::deleteRPTID(int nRPTID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ɾ³ý ReportVIDs ±íÖÐËùÓÐÓë¸Ã RPTID Ïà¹ØµÄ¼Ç¼
|
std::string deleteReportVIDsSQL = "DELETE FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + ";";
|
if (!m_pDB->executeQuery(deleteReportVIDsSQL)) {
|
return 2; // ɾ³ýʧ°Ü
|
}
|
|
// ¿ÉÑ¡ÔñÊÇ·ñɾ³ý Report ±íÖÐµÄ RPTID£¬ÒÔÏÂÊÇɾ³ý Report ±íÖÐµÄ RPTID µÄ SQL
|
std::string deleteReportSQL = "DELETE FROM Report WHERE RPTID = " + std::to_string(nRPTID) + ";";
|
if (!m_pDB->executeQuery(deleteReportSQL)) {
|
return 3; // ɾ³ýʧ°Ü
|
}
|
|
return 0; // ɾ³ý³É¹¦
|
}
|
|
// ¸üÐÂÖ¸¶¨ RPTID µÄ VID
|
int SECSRuntimeManager::updateRPTIDVID(int nRPTID, int nOldVID, int nNewVID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// ¼ì²éÖ¸¶¨µÄ RPTID ºÍ OldVID ÊÇ·ñ´æÔÚ
|
std::string checkExistSQL = "SELECT COUNT(*) FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nOldVID) + ";";
|
int count = getIntFromDB(checkExistSQL);
|
if (count == 0) {
|
return 2; // ¼Ç¼²»´æÔÚ£¬²»ÄܸüÐÂ
|
}
|
|
// ¼ì²éÐ嵀 VID ÊÇ·ñÒѾ´æÔÚÓÚÏàͬµÄ RPTID Ï£¬·ÀÖ¹ÖØ¸´
|
std::string checkNewVIDExistSQL = "SELECT COUNT(*) FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nNewVID) + ";";
|
int newVIDCount = getIntFromDB(checkNewVIDExistSQL);
|
if (newVIDCount > 0) {
|
return 3; // Ð嵀 VID ÒѾ´æÔÚ£¬²»ÄÜÖØ¸´
|
}
|
|
// Ö´ÐиüвÙ×÷£¬Ìæ»» OldVID Ϊ NewVID
|
std::string updateSQL = "UPDATE ReportVIDs SET VID = " + std::to_string(nNewVID) + " WHERE RPTID = " + std::to_string(nRPTID) + " AND VID = " + std::to_string(nOldVID) + ";";
|
if (!m_pDB->executeQuery(updateSQL)) {
|
return 4; // ¸üÐÂʧ°Ü
|
}
|
|
return 0; // ¸üгɹ¦
|
}
|
|
// ¸üÐÂÖ¸¶¨ RPTID µÄËùÓÐ VID
|
int SECSRuntimeManager::updateRPTIDVIDs(int nRPTID, const std::vector<int>& vecVID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
if (m_pDB == nullptr) {
|
return 1; // Êý¾Ý¿âδÁ¬½Ó
|
}
|
|
// 1. ÏÈɾ³ý RPTID ÏÂËùÓÐµÄ VID ¹ØÁª¼Ç¼
|
int deleteResult = deleteRPTID(nRPTID);
|
if (deleteResult != 0) {
|
return deleteResult; // ɾ³ýʧ°Ü£¬·µ»ØÉ¾³ýµÄ´íÎóÂë
|
}
|
|
// 2. Ìí¼ÓÐ嵀 VID ¹ØÁª¼Ç¼
|
int addResult = addRPTIDVIDs(nRPTID, vecVID);
|
if (addResult != 0) {
|
return 3; // ²åÈëʧ°Ü
|
}
|
|
return 0; // ɾ³ý²¢Ìí¼Ó³É¹¦
|
}
|
|
// »ñȡָ¶¨ RPTID µÄËùÓÐ VID
|
std::vector<int> SECSRuntimeManager::getVIDsByRPTID(int nRPTID) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
std::vector<int> vecVIDs;
|
|
if (m_pDB == nullptr) {
|
return {};
|
}
|
|
// ¹¹½¨²éѯ SQL£¬²éѯָ¶¨ RPTID ϵÄËùÓÐ VID
|
std::string querySQL = "SELECT VID FROM ReportVIDs WHERE RPTID = " + std::to_string(nRPTID) + ";";
|
|
// Ö´Ðвéѯ
|
std::vector<std::vector<std::string>> results = m_pDB->fetchResults(querySQL);
|
|
// ´¦Àí²éѯ½á¹û²¢Ìî³äµ½ vecVIDs ÖÐ
|
for (const auto& row : results) {
|
if (!row.empty()) {
|
int nVID = std::stoi(row[0]); // ½«×Ö·û´®ÀàÐ굀 VID ת»»Îª int
|
vecVIDs.push_back(nVID); // ½« VID ¼ÓÈë½á¹ûÏòÁ¿
|
}
|
}
|
|
return vecVIDs;
|
}
|
|
// »ñÈ¡ËùÓÐ RPTID
|
std::vector<int> SECSRuntimeManager::getAllRPTIDs() {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
std::vector<int> vecRPTIDs;
|
|
if (m_pDB == nullptr) {
|
throw std::runtime_error("Database not connected.");
|
}
|
|
// ¹¹½¨²éѯ SQL£¬²éѯ Report ±íÖеÄËùÓÐ RPTID
|
std::string querySQL = "SELECT RPTID FROM Report;";
|
|
// Ö´Ðвéѯ
|
std::vector<std::vector<std::string>> results = m_pDB->fetchResults(querySQL);
|
|
// ´¦Àí²éѯ½á¹û²¢Ìî³äµ½ vecRPTIDs ÖÐ
|
for (const auto& row : results) {
|
if (!row.empty()) {
|
int nRPTID = std::stoi(row[0]); // ½«×Ö·û´®ÀàÐ굀 RPTID ת»»Îª int
|
vecRPTIDs.push_back(nRPTID); // ½« RPTID ¼ÓÈë½á¹ûÏòÁ¿
|
}
|
}
|
|
return vecRPTIDs;
|
}
|