#include "StdAfx.h" #include "EsqlMgr.h" static const LPCTSTR g_szEsqlFile = _T("./sql/"); CEsqlManager::CEsqlManager() { m_DbSQl.empty(); } CEsqlManager::~CEsqlManager() { m_DbSQl.empty(); } void CEsqlManager::EsqlMain(char* sToolPath,char* sDbName) { if(!sToolPath || !sDbName) return; if (!FileExist(sToolPath) ) { OutputMsg( rmNormal, _T("EsqlTool not exist") ); return; } //if (!FileExist(g_szEsqlFile) ) //{ // OutputMsg( rmNormal, _T("Esql file not exist") ); // return; //} GetAllFileName(); OnRunEsqlTool(sToolPath,sDbName); DeleteEsqlFile(); OutputMsg( rmNormal, _T("load Esql file finish") ); } bool CEsqlManager::FileExist(LPCTSTR lpszFilePath) { #ifdef WIN32 DWORD dwAttr = GetFileAttributes(lpszFilePath); #else DWORD dwAttr = access(lpszFilePath, R_OK | W_OK); #endif if ( dwAttr == (DWORD)-1 ) return false; else return true; } void CEsqlManager::GetAllFileName() { //if (!FileExist(g_szEsqlFile) ) //return; #ifdef WIN32 WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; char DirSpec[MAX_PATH] = ""; DWORD dwError; strncat (DirSpec, "*", 3); hFind = FindFirstFile(DirSpec, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { OutputMsg( rmNormal, _T("no esql file") ); return; } else { //OutputMsg( rmError, "First file name is %s\n", FindFileData.cFileName); FindNextFile(hFind, &FindFileData); while (FindNextFile(hFind, &FindFileData) != 0) { if(bSqlFile(FindFileData.cFileName)) { OutputMsg( rmNormal, "Next file name is %s", FindFileData.cFileName); int nId = GetEsqlId(FindFileData.cFileName); if(nId > 0) { AddEsqlToList(nId,FindFileData.cFileName); } } } //for(int i =0;id_name)) { OutputMsg( rmNormal, "Next file name is %s", ptr->d_name); int nId = GetEsqlId(ptr->d_name); if(nId > 0) { AddEsqlToList(nId,ptr->d_name); } } } //for(int i =0;i= 49 && strEsql[i] <58) { sName[j++] = strEsql[i]; } else { break; } } if(j > 0 && j < 255) { sName[j] = 0; } int nId = atoi(sName); return nId; } return -1; } void CEsqlManager::AddEsqlToList(int nId,char *strEsql) { if(!strEsql) return; DBSQL tmpEsql; tmpEsql.nId = nId; _asncpytA(tmpEsql.sFileName,strEsql); int index = -1; for(int i=0;i= 0) { m_DbSQl.insert(index,tmpEsql); } else { m_DbSQl.add(tmpEsql); } } void CEsqlManager::OnRunEsqlTool(char* sToolPath,char* sDbName) { INT_PTR nCount = m_DbSQl.count(); if(nCount <= 0) return; char buf[1000]; #ifdef WIN32 GetCurrentDirectory(1000,buf); //得到当前工作路径 strcat(buf,"\\"); #else getcwd(buf, 1000); //得到当前工作路径 strcat(buf,"/"); #endif char dbId[32]; if(sDbName) { int j=0; for(int i=0;i= '0' && sDbName[i] <= '9') { dbId[j++] = sDbName[i]; } } if(j >= 0 && j < 32) { dbId[j]=0; } } else { dbId[0]=0; } OutputMsg( rmNormal, "GetCurrentDirectory %s,serveindex=%s",buf,dbId?dbId:""); for(int i = 0;i=0; j--) { if(dir[j] =='\\') { dir[j]=0; break; } } SetCurrentDirectory(dir); system(sPath); Sleep(100); } SetCurrentDirectory(buf); } void CEsqlManager::DeleteEsqlFile() { INT_PTR nCount = m_DbSQl.count(); if(nCount <= 0) return; char buf[1000]; #ifdef WIN32 GetCurrentDirectory(1000,buf); //得到当前工作路径 strcat(buf,"\\"); #else getcwd(buf, 1000); //得到当前工作路径 strcat(buf,"/"); #endif for(int i = 0;i