#include "stdafx.h" #include "SQLite.h" #include "ManageServerDB.h" #include #include const char* CManageServerDB::GetDefaultDBFileName() { return "./ManageServerDB.dat"; } CManageServerDB& CManageServerDB::GetInstance() { static CManageServerDB manageServerDB; return manageServerDB; } CManageServerDB::CManageServerDB() : m_lpSQLite(new CSQLite) { } CManageServerDB::~CManageServerDB() { if(0 != m_lpSQLite) { delete m_lpSQLite; m_lpSQLite = 0; } } bool CManageServerDB::Initialize(const char* szDBFileName) { if(0 == m_lpSQLite || !m_lpSQLite->Open(szDBFileName)) { ERRLOG1(g_Log, "Cannot open database : %s", szDBFileName); return false; } // Create Tables - ÀÌ¹Ì ¸¸µé¾îÁ® ÀÖÀ¸¸é ¿¡·¯°¡ ³­´Ù. const int MAX_QUERY_NUM = 5; const char* szCreateTableQuery[MAX_QUERY_NUM] = { "CREATE TABLE TblManageToolUser (ID char(16) PRIMARY KEY, PASS char(16), " "NAME char(32), IP char(16), LEVEL INTEGER)", "CREATE TABLE TblServerInfo (IP INTEGER PRIMARY KEY, ServerName char(64))", "CREATE TABLE TblRunPath (PathID INTEGER PRIMARY KEY, RunPath char(260))", "CREATE TABLE TblRunOptions (OptionID INTEGER PRIMARY KEY, RunOption char(260))", "CREATE TABLE TblRunInfo (RunID INTEGER PRIMARY KEY, PathID INTEGER, OptionID INTEGER, ServerIP INTEGER)" }; m_lpSQLite->SetErrorLog(false); for(int nQuery = 0; nQuery < MAX_QUERY_NUM; ++nQuery) { CSQLite::Dataset createUserTable(*m_lpSQLite, szCreateTableQuery[nQuery]); if(!createUserTable.Compile() || !createUserTable.Execute()) { if(0 != createUserTable.GetLastError()) { // Table create failed. if already create failed? char szTableName[MAX_PATH]; int nLength = sscanf(createUserTable.GetLastError(), "table %s already exists", szTableName); if(EOF == nLength || 0 == nLength) { m_lpSQLite->SetErrorLog(true); return false; } } } } m_lpSQLite->SetErrorLog(true); return true; }