123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "stdafx.h"
- #include "GenInfoDB.h"
- #include "DBConst.h"
- #include "InformationTable.h"
- namespace OTSSQLITE
- {
- CGenInfoDB::CGenInfoDB(CDBStoreBasePtr a_datastore):CInformationDB(a_datastore),
- m_sFileVersion(_T(""))
- {
- }
- CGenInfoDB::~CGenInfoDB(void)
- {
- }
- BOOL CGenInfoDB::Init(const BOOL /*a_bClean = FALSE*/)
- {
- if (IsDBExist()) { return TRUE; }
- if (CreateTable())
- {
- auto datastorePtr = GetDatastore() ;
- ASSERT(datastorePtr);
- if (!datastorePtr)
- {
- return FALSE;
- }
- if (!InsertTimeStampRow(g_sTableItemNameCreateTime, datastorePtr->GetFileName()))
- {
- LogErrorTrace(__FILE__,__LINE__,_T("Save %s item to table(%s) failed"), (LPCTSTR)g_sTableItemNameCreateTime, (LPCTSTR)GetTableInfo()->GetTableName());
- }
- if (!InsertStringRow(g_sTableItemNameFileVersion, g_sDBFileVersion))
- {
- LogErrorTrace(__FILE__,__LINE__,_T("Save %s item to table(%s) failed"), (LPCTSTR)g_sTableItemNameFileVersion, (LPCTSTR)GetTableInfo()->GetTableName());
- ASSERT(FALSE);
- return FALSE;
- }
- if (!InsertTimeStampRow(g_sTableItemNameTimeStart, datastorePtr->GetFileName()))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Save %s item to table(%s) failed"), (LPCTSTR)g_sTableItemNameCreateTime, (LPCTSTR)GetTableInfo()->GetTableName());
- }
- if (!InsertTimeStampRow(g_sTableItemNameTimeEnd, datastorePtr->GetFileName()))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Save %s item to table(%s) failed"), (LPCTSTR)g_sTableItemNameCreateTime, (LPCTSTR)GetTableInfo()->GetTableName());
- }
- CString resultSta("0");//in default ,initialize it to 0,it will be updated in the running process.
- if (!InsertStringRow(g_sTableItemNameResultStatus, resultSta))
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Save %s item to table(%s) failed"), (LPCTSTR)g_sTableItemNameFileVersion, (LPCTSTR)GetTableInfo()->GetTableName());
- ASSERT(FALSE);
- return FALSE;
- }
- m_sFileVersion = g_sDBFileVersion;
- return TRUE;
- }
- ASSERT(FALSE);
- return FALSE;
- }
- CString CGenInfoDB::GetFileVersion()
- {
- m_sFileVersion.Trim();
- if (m_sFileVersion.IsEmpty())
- {
- // read in file version if it is empty
- auto datastorePtr = GetDatastore();
- ASSERT(datastorePtr);
- if (!datastorePtr)
- {
- return m_sFileVersion;
- }
-
- auto tableInfoPtr = GetTableInfo();
- ASSERT(tableInfoPtr);
- if (!tableInfoPtr)
- {
- return m_sFileVersion;
- }
-
- CString sItemName = tableInfoPtr->GetColumnName((int)CInformationTable::ColumnID::ITEM - (int)CInformationTable::ColumnID::MIN);
- CString sSQLCommand;
- sSQLCommand.Format(_T("SELECT * FROM \'%s\' WHERE %s = \'%s\';"),
- (LPCTSTR)tableInfoPtr->GetTableName(),
- (LPCTSTR)sItemName,
- (LPCTSTR)g_sTableItemNameFileVersion);
- auto query = datastorePtr->QueryByCommand(sSQLCommand);
- ASSERT(query);
- if (!query)
- {
- return m_sFileVersion;
- }
- ASSERT(query->IsValid());
- if (!query->IsValid())
- {
- return m_sFileVersion;
- }
- if (query->IsEOF())
- {
- LogErrorTrace(__FILE__,__LINE__,_T("Could not read file version from datastore."));
- return m_sFileVersion;
- }
- int nCol = (int)CInformationTable::ColumnID::CONTENT - (int)CInformationTable::ColumnID::MIN;
- m_sFileVersion = query->GetColStringValue(nCol);
- }
- return m_sFileVersion;
- }
- CString CGenInfoDB::GetTableItemNameTimeStart() {
- return CString(g_sTableItemNameTimeStart);
- }
- CString CGenInfoDB::GetTableItemNameTimeEnd() {
- return CString(g_sTableItemNameTimeEnd);
- }
- CString CGenInfoDB::GetTableItemNameResultStatus() {
- return CString(g_sTableItemNameResultStatus);
- }
- }
|