102 lines
3.2 KiB
C++
102 lines
3.2 KiB
C++
#include "IOCfgDao.h"
|
|
#include "../ConfigManager.h"
|
|
|
|
|
|
IOCfgDao::IOCfgDao(SQLite::Database* pdb) :BaseDao(pdb)
|
|
{
|
|
}
|
|
|
|
|
|
IOCfgDao::~IOCfgDao()
|
|
{
|
|
}
|
|
|
|
void IOCfgDao::CreateTable()
|
|
{
|
|
if (m_pDB->tableExists(IOCfg::TABLE_NAME))return;
|
|
char buffer[1024];
|
|
memset(buffer, '\0', sizeof(buffer));
|
|
string createsql = "CREATE TABLE %s(%s INTEGER PRIMARY KEY AUTOINCREMENT,%s INTEGER,%s INTEGER,%s INTEGER,%s INTEGER,%s VARCHAR(50),%s VARCHAR(50),%s INTEGER,UNIQUE(%s,%s))";
|
|
sprintf_s(buffer, sizeof(buffer), createsql.c_str(),
|
|
IOCfg::TABLE_NAME.c_str(),
|
|
IOCfg::FIELD_ID.c_str(),
|
|
IOCfg::FIELD_MACHINE_TYPE.c_str(),
|
|
IOCfg::FIELD_STATUS_ADDR.c_str(),
|
|
IOCfg::FIELD_CTRL_ADDR.c_str(),
|
|
IOCfg::FIELD_IS_OUTPUT.c_str(),
|
|
IOCfg::FIELD_CODE.c_str(),
|
|
IOCfg::FIELD_CONTENT.c_str(),
|
|
IOCfg::FIELD_AUTH_LESS.c_str(),
|
|
IOCfg::FIELD_MACHINE_TYPE.c_str(),
|
|
IOCfg::FIELD_CODE.c_str()
|
|
);
|
|
MachineCfg* cfg = ConfigManager::GetInstance()->GetMachineCfg();
|
|
//SQLite::Transaction transaction(*m_pDB);
|
|
m_pDB->exec(buffer);
|
|
}
|
|
|
|
void IOCfgDao::Find(IOCfgWrapper* iowrapper)
|
|
{
|
|
Machine* machine = ConfigManager::GetInstance()->GetMachine();
|
|
vector<string> ups;
|
|
if (!ups.empty()) {
|
|
SQLite::Transaction transaction(*m_pDB);
|
|
for (size_t insIndex = 0; insIndex < ups.size(); insIndex++) {
|
|
m_pDB->exec(ups[insIndex]);
|
|
}
|
|
transaction.commit();
|
|
}
|
|
|
|
SQLite::Statement query(*m_pDB, machine->GetFindIOStr());
|
|
while (query.executeStep())
|
|
{
|
|
int addr = query.getColumn(IOCfg::FIELD_STATUS_ADDR.c_str()).getInt();
|
|
IOCfg* pbean = new IOCfg();
|
|
pbean->m_Id = query.getColumn(IOCfg::FIELD_ID.c_str()).getInt();
|
|
pbean->m_MachineType = query.getColumn(IOCfg::FIELD_MACHINE_TYPE.c_str()).getInt();
|
|
pbean->m_StatusAddr = addr;
|
|
pbean->m_CtrlAddr = query.getColumn(IOCfg::FIELD_CTRL_ADDR.c_str()).getInt();
|
|
pbean->SetOutput(query.getColumn(IOCfg::FIELD_IS_OUTPUT.c_str()).getInt()>0?true:false);
|
|
pbean->m_Code = query.getColumn(IOCfg::FIELD_CODE.c_str()).getString();
|
|
pbean->m_Content = query.getColumn(IOCfg::FIELD_CONTENT.c_str()).getString();
|
|
pbean->m_AuthLess = query.getColumn(IOCfg::FIELD_AUTH_LESS.c_str()).getInt();
|
|
if (!pbean->m_IsOutput) {
|
|
iowrapper->m_InputCfgs.push_back(pbean);
|
|
iowrapper->m_InputCheckAssist[pbean->m_StatusAddr] = true;
|
|
}
|
|
else{
|
|
iowrapper->m_OutputCfgs.push_back(pbean);
|
|
iowrapper->m_OutputCheckAssist[pbean->m_StatusAddr] = true;
|
|
}
|
|
iowrapper->m_IOCfgMap[pbean->m_Code] = pbean;
|
|
}
|
|
vector<string> ins;
|
|
MachineCfg* mc = ConfigManager::GetInstance()->GetMachineCfg();
|
|
machine->CheckIO(ins, iowrapper, mc->m_IOVersion->GetValue());
|
|
|
|
if (!ins.empty()) {
|
|
SQLite::Transaction transaction(*m_pDB);
|
|
for (size_t insIndex = 0; insIndex < ins.size(); insIndex++) {
|
|
m_pDB->exec(ins[insIndex]);
|
|
}
|
|
transaction.commit();
|
|
}
|
|
}
|
|
|
|
void IOCfgDao::Save(map<string, IOCfg *>& iocfgmap)
|
|
{
|
|
for (map<string, IOCfg *>::iterator it = iocfgmap.begin(); it != iocfgmap.end(); it++) {
|
|
IOCfg* pcfg = it->second;
|
|
if (pcfg == NULL)continue;
|
|
m_pDB->exec(pcfg->GetUpdateSql());
|
|
}
|
|
}
|
|
|
|
void IOCfgDao::Export(map<string, IOCfg*>& iocfgmap, stringstream &sql)
|
|
{
|
|
for (map<string, IOCfg *>::iterator it = iocfgmap.begin(); it != iocfgmap.end(); it++) {
|
|
IOCfg* pcfg = it->second;
|
|
if (pcfg == NULL)continue;
|
|
sql<<pcfg->GetUpdateSql() <<"\n";
|
|
}
|
|
} |