|
@@ -97,12 +97,14 @@ void CDataLogger::Release(void)
|
|
|
unsigned long CDataLogger::GetTagID(const char *pszVarPath, int nDataType, int nLogType)
|
|
|
{
|
|
|
CMySqlDB db;
|
|
|
- const char *pszID = NULL;
|
|
|
+ const char *pszID = NULL, *pszDataType = NULL, *pszLogType = 0;
|
|
|
char *pszEndptr;
|
|
|
unsigned long nID = ULONG_MAX;
|
|
|
+ int nDT, nLT;
|
|
|
|
|
|
std::string sSql;
|
|
|
- sSql = formatString("select `tagid` from `%s` where `path` = '%s' and `dataType` = %d and `logType` = %d", m_dlp.szTagsTable, pszVarPath, nDataType, nLogType);
|
|
|
+// sSql = formatString("select `tagid` from `%s` where `path` = '%s' and `dataType` = %d and `logType` = %d", m_dlp.szTagsTable, pszVarPath, nDataType, nLogType);
|
|
|
+ sSql = formatString("select `tagid`, `dataType`+0, `logType`+0 from `%s` where `path` = '%s'", m_dlp.szTagsTable, pszVarPath);
|
|
|
|
|
|
if(!db.Connect("localhost", m_dlp.szDBUser, m_dlp.szDBPass, m_dlp.szDBName))
|
|
|
{
|
|
@@ -123,7 +125,23 @@ unsigned long CDataLogger::GetTagID(const char *pszVarPath, int nDataType, int n
|
|
|
{
|
|
|
MYSQL_ROW pRow = res.FetchRow();
|
|
|
pszID = pRow[0];
|
|
|
+ pszDataType = pRow[1];
|
|
|
+ pszLogType = pRow[2];
|
|
|
+
|
|
|
nID = strtoul(pszID, &pszEndptr, 10);
|
|
|
+ nDT = strtol(pszDataType, &pszEndptr, 10);
|
|
|
+ nLT = strtol(pszLogType, &pszEndptr, 10);
|
|
|
+
|
|
|
+ if((nDT != nDataType) || (nLT != nLogType))
|
|
|
+ {
|
|
|
+ sSql = formatString("update `%s` set `dataType` = %d, `logType` = %d where `tagid` = %u", m_dlp.szTagsTable, nDataType, nLogType, nID);
|
|
|
+// TRACE("%s\n", sSql.c_str());
|
|
|
+ res = db.Query(sSql.c_str());
|
|
|
+ bError = res.error();
|
|
|
+
|
|
|
+ if(bError)
|
|
|
+ m_lf.Error("Error updating Tags-Table: %s\n", db.LastError().c_str());
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -597,7 +615,7 @@ bool CDataLogger::CreateDatabase(CMySqlDB &rdb, bool bEnforceCreate)
|
|
|
bError = res.error();
|
|
|
|
|
|
if(bError)
|
|
|
- m_lf.Error("CDataLogger::InitDatabase: DB Error: %s\n", rdb.LastError().c_str());
|
|
|
+ m_lf.Error("CDataLogger::CreateDatabase: DB Error: %s\n", rdb.LastError().c_str());
|
|
|
}
|
|
|
|
|
|
if(!bError)
|
|
@@ -607,7 +625,7 @@ bool CDataLogger::CreateDatabase(CMySqlDB &rdb, bool bEnforceCreate)
|
|
|
bError = res.error();
|
|
|
|
|
|
if(bError)
|
|
|
- m_lf.Error("CDataLogger::InitDatabase: DB Error: %s\n", rdb.LastError().c_str());
|
|
|
+ m_lf.Error("CDataLogger::CreateDatabase: DB Error: %s\n", rdb.LastError().c_str());
|
|
|
}
|
|
|
|
|
|
return !bError;
|
|
@@ -804,6 +822,7 @@ time_t CDataLogger::GetLastLogTimestamp(CMySqlDB &rdb)
|
|
|
|
|
|
bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
{
|
|
|
+ std::string strErr;
|
|
|
::pthread_mutex_lock(&m_condmtx1);
|
|
|
bool bGoodBadTransition = false, bSgInProg = m_bSGInProgress;
|
|
|
::pthread_mutex_unlock(&m_condmtx1);
|
|
@@ -898,7 +917,7 @@ bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
|
|
|
if(m_dlp.bMinMax && _IS_INTERVAL_LOGTYPE(rle.lt))
|
|
|
{
|
|
|
- if(!rle0.bNull)
|
|
|
+ if(!rle.bNull)
|
|
|
sSql = formatString(",(%lu, timestamp(from_unixtime(%lu)), %.20g, %.20g, %.20g)", rle.nTagID, rle.nTimestamp, rle.fValue, rle.fMin, rle.fMax);
|
|
|
else
|
|
|
sSql = formatString(",(%lu, timestamp(from_unixtime(%lu)), NULL, NULL, NULL)", rle.nTagID, rle.nTimestamp);
|
|
@@ -917,12 +936,13 @@ bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
{
|
|
|
db.Query(strLock.c_str());
|
|
|
CMySqlResult res = db.Query(strSql.c_str());
|
|
|
- bError = res.error();
|
|
|
+ if((bError = res.error()))
|
|
|
+ strErr = db.LastError();
|
|
|
db.Query(strUnlock.c_str());
|
|
|
Unlock();
|
|
|
|
|
|
if(bError)
|
|
|
- m_lf.Error("CDataLogger::Flush: DB Error: %s\n", db.LastError().c_str());
|
|
|
+ m_lf.Error("CDataLogger::Flush: DB Error: %s\n", strErr.c_str());
|
|
|
else
|
|
|
m_nLastLogTimestamp = nMaxLogTimestamp;
|
|
|
|
|
@@ -934,13 +954,13 @@ bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
{
|
|
|
if(m_bBadDateLogsDetected)
|
|
|
{
|
|
|
- bool bError;
|
|
|
+ bool bErr;
|
|
|
char szTs[64];
|
|
|
unsigned long long nNextAIVal = 0;
|
|
|
sSql = formatString("select auto_increment from `information_schema`.`TABLES` where `TABLE_SCHEMA` = '%s' and `TABLE_NAME` = '%s';", m_dlp.szDBName, m_dlp.szLogsTableBD);
|
|
|
CMySqlResult res = db.Query(sSql.c_str());
|
|
|
|
|
|
- if(!(bError = res.error()))
|
|
|
+ if(!(bErr = res.error()))
|
|
|
{
|
|
|
CMySqlVar val;
|
|
|
my_ulonglong nRowCount = res.RowCount();
|
|
@@ -980,13 +1000,13 @@ bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- bool bError;
|
|
|
+ bool bErr;
|
|
|
char szTs[64];
|
|
|
unsigned long long nLastID = 0;
|
|
|
sSql = formatString("select max(`id`) from `%s`.`%s`;", m_dlp.szDBName, m_dlp.szLogsTableBD);
|
|
|
CMySqlResult res = db.Query(sSql.c_str());
|
|
|
|
|
|
- if(!(bError = res.error()))
|
|
|
+ if(!(bErr = res.error()))
|
|
|
{
|
|
|
CMySqlVar val;
|
|
|
my_ulonglong nRowCount = res.RowCount();
|
|
@@ -1074,11 +1094,12 @@ bool CDataLogger::Flush(time_t nTimestamp)
|
|
|
|
|
|
db.Query(strLock.c_str());
|
|
|
CMySqlResult res = db.Query(strSql.c_str());
|
|
|
- bError = res.error();
|
|
|
+ if((bError = res.error()))
|
|
|
+ strErr = db.LastError();
|
|
|
db.Query(strUnlock.c_str());
|
|
|
|
|
|
if(bError)
|
|
|
- m_lf.Error("CDataLogger::Flush: DB Error: %s\n", db.LastError().c_str());
|
|
|
+ m_lf.Error("CDataLogger::Flush: DB Error: %s\n", strErr.c_str());
|
|
|
|
|
|
m_logsBD.clear();
|
|
|
}
|