@ -91,7 +91,7 @@ sqliteDBC::sqliteDBC(config_setting_t * Settings) :
m_bMemIsConnected = false ;
m_bRepIsConnected = false ;
m_bStaIsConnected = false ;
m_bLastEventWasClosed = false ;
//m_bLastEventWasClosed = false;
m_pDataStorage = NULL ;
m_pDataMemory = NULL ;
m_pDataReports = NULL ;
@ -137,7 +137,8 @@ bool sqliteDBC::connect(void)
m_bMemIsConnected = false ;
m_bRepIsConnected = false ;
m_bStaIsConnected = false ;
m_bLastEventWasClosed = false ;
//m_bLastEventWasClosed = false;
bool bLastEventWasClosed = true ; // Workaround
// Apply New Config
# ifdef DEBUG
@ -293,22 +294,17 @@ bool sqliteDBC::connect(void)
} ;
sprintf ( m_pDbStat , " %s/stat.db " , m_pDbReportBase ) ;
m_pDataStatistics = new SQLite_Connector ( ) ;
if ( m_pDataStatistics )
{
if ( fileExist ( m_pDbStat ) )
{
if ( m_pDataStatistics ) {
if ( fileExist ( m_pDbStat ) ) {
m_bStaIsCreated = false ;
if ( m_pDataStatistics - > Connect ( m_pDbStat , 0 , true ) )
{
if ( m_pDataStatistics - > Connect ( m_pDbStat , 0 , true ) ) {
# ifdef DEBUG
LOG ( m_pDbStat ) ;
LOG ( " DB Statistics Opened " ) ;
# endif
m_pDataStatistics - > SilentQuery ( " PRAGMA journal_mode=WAL " ) ;
m_bStaIsConnected = true ;
}
else
{
} else {
LOG_ERROR ( " Cannot Connect to DB Statistics " ) ;
delete ( m_pDataStorage ) ;
delete ( m_pDataMemory ) ;
@ -320,12 +316,9 @@ bool sqliteDBC::connect(void)
m_pDataStatistics = NULL ;
return false ;
} ;
}
else
{
} else {
m_bStaIsCreated = true ;
if ( m_pDataStatistics - > Connect ( m_pDbStat , 0 , true ) )
{
if ( m_pDataStatistics - > Connect ( m_pDbStat , 0 , true ) ) {
# ifdef DEBUG
LOG ( " NEW DB Statistics Creating " ) ;
# endif
@ -336,9 +329,7 @@ bool sqliteDBC::connect(void)
" CREATE TABLE IF NOT EXISTS \" days \" ( \" year \" INTEGER, \" month \" INTEGER, \" day \" INTEGER, \" evt_count \" INTEGER DEFAULT 0, \" session_count \" INTEGER DEFAULT 0, \" videos_count \" INTEGER DEFAULT 0, \" session_closed \" INTEGER "
" DEFAULT 0, CONSTRAINT \" date_uni \" UNIQUE( \" year \" , \" month \" , \" day \" ) ); " ) ;
m_bStaIsConnected = true ;
}
else
{
} else {
LOG_ERROR ( " Cannot Connect to DB Statistics " ) ;
delete ( m_pDataStorage ) ;
delete ( m_pDataMemory ) ;
@ -352,42 +343,34 @@ bool sqliteDBC::connect(void)
} ;
} ;
} ;
m_pDataReports = new SQLite_Connector ( ) ;
if ( m_pDataReports )
{
m_pDataReports = new SQLite_Connector ( ) ;
if ( m_pDataReports ) {
/*
memset ( & m_sPRepInfo , 0 , sizeof ( REPORT_DIRINFO ) ) ;
if ( ! m_bStaIsCreated )
{
if ( ! m_bStaIsCreated ) {
# ifdef DEBUG
LOG ( " OLD Statistics PRESENT Report Created! " ) ;
# endif
AAssoc * result = m_pDataStatistics - > Query ( " SELECT * FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1 " ) ;
if ( result )
{
if ( result - > size ( ) > 0 )
{
if ( result ) {
if ( result - > size ( ) > 0 ) {
Assoc * cArr ;
Assoc : : iterator it ;
cArr = result - > at ( 0 ) ;
it = cArr - > find ( " year " ) ;
if ( it ! = cArr - > end ( ) )
{
if ( it ! = cArr - > end ( ) ) {
strncpy ( m_sPRepInfo . YEAR , it - > second . c_str ( ) , 4 ) ;
} ;
it = cArr - > find ( " month " ) ;
if ( it ! = cArr - > end ( ) )
{
if ( it ! = cArr - > end ( ) ) {
sprintf ( m_sPRepInfo . MONTH , " %02d " , atoi ( it - > second . c_str ( ) ) ) ;
} ;
it = cArr - > find ( " day " ) ;
if ( it ! = cArr - > end ( ) )
{
if ( it ! = cArr - > end ( ) ) {
sprintf ( m_sPRepInfo . DAY , " %02d " , atoi ( it - > second . c_str ( ) ) ) ;
} ;
m_sPRepInfo . ts = getTsFromRDF ( m_sPRepInfo ) ;
}
else
{
} else {
# ifdef DEBUG
LOG ( " No Rows Fetched from STAT! " ) ;
# endif
@ -396,94 +379,71 @@ bool sqliteDBC::connect(void)
m_pDataMemory - > deleteResult ( result ) ;
} ;
if ( m_sPRepInfo . ts ! = 0 )
{
if ( m_sPRepInfo . ts ! = 0 ) {
# ifdef DEBUG
LOG ( " Have Old Reports! " ) ;
# endif
if ( checkRDFDir ( m_pDbReportBase , m_sPRepInfo , false ) = = 0 )
{
if ( checkRDFDir ( m_pDbReportBase , m_sPRepInfo , false ) = = 0 ) {
LOG_ERROR ( " Error Connecting to Prev Report! " ) ;
m_bLastEventWasClosed = true ;
}
else
{
bLastEventWasClosed = true ;
} else {
# ifdef DEBUG
LOG ( " Connect to old Report Database " ) ;
# endif
sprintf ( m_pDbReport , " %s/%s/%s/%s/report.db " , m_pDbReportBase , m_sPRepInfo . YEAR , m_sPRepInfo . MONTH , m_sPRepInfo . DAY ) ;
LOG ( m_pDbReport ) ;
if ( fileExist ( m_pDbReport ) )
{
if ( fileExist ( m_pDbReport ) ) {
SQLite_Connector * tDBC = new SQLite_Connector ( ) ;
if ( tDBC )
{
if ( tDBC - > Connect ( m_pDbReport , 0 , true ) )
{
if ( tDBC ) {
if ( tDBC - > Connect ( m_pDbReport , 0 , true ) ) {
char tQBuf [ CTEXT ] ;
AAssoc * result ;
sprintf ( tQBuf , " SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1 " , EVT_LRF_START_SESSION , EVT_LRF_END_SESSION_MA , EVT_LRF_END_SESSION_TO ) ;
//sprintf(tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO);
sprintf ( tQBuf , " SELECT `evt_type`, `ts`, `ts_ms` FROM `events` ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1 " ) ;
# ifdef DEBUG_ALL
LOG ( tQBuf ) ;
# endif
result = tDBC - > Query ( tQBuf ) ;
if ( result ! = NULL )
{
if ( result - > size ( ) > 0 )
{
if ( result ! = NULL ) {
if ( result - > size ( ) > 0 ) {
Assoc * cArr ;
Assoc : : iterator it ;
cArr = result - > at ( 0 ) ;
it = cArr - > find ( " evt_type " ) ;
if ( it ! = cArr - > end ( ) )
{
if ( atoi ( it - > second . c_str ( ) ) ! = EVT_LRF_START_SESSION )
{
m_bLastEventWasClosed = true ;
if ( it ! = cArr - > end ( ) ) {
if ( atoi ( it - > second . c_str ( ) ) ! = EVT_LRF_START_SESSION ) {
bLastEventWasClosed = true ;
}
} ;
}
else
{
m_bLastEventWasClosed = true ;
}
} else {
bLastEventWasClosed = true ;
} ;
} ;
deleteResult ( result ) ;
}
else
{
} else {
LOG_ERROR ( " Error Connecting to Prev Report! " ) ;
m_ bLastEventWasClosed = true ;
bLastEventWasClosed = true ;
} ;
delete ( tDBC ) ;
}
else
{
} else {
LOG_ERROR ( " Error Create DB Connection Object! " ) ;
m_ bLastEventWasClosed = true ;
bLastEventWasClosed = true ;
} ;
}
else
{
} else {
LOG_ERROR ( " Error No Prev Report Database! " ) ;
m_ bLastEventWasClosed = true ;
bLastEventWasClosed = true ;
} ;
} ;
}
else
{
m_bLastEventWasClosed = true ;
} else {
bLastEventWasClosed = true ;
} ;
if ( m_bLastEventWasClosed )
{
*/
if ( bLastEventWasClosed ) {
# ifdef DEBUG
LOG ( " Last Session is Closed! " ) ;
# endif
fillRDF ( time ( NULL ) , m_sCRepInfo ) ;
}
else
{
} else {
# ifdef DEBUG
LOG ( " Last Session is NOT Closed! " ) ;
# endif
@ -492,8 +452,7 @@ bool sqliteDBC::connect(void)
# ifdef DEBUG
LOG ( m_pDbReportBase ) ;
# endif
if ( ! checkRDFDir ( m_pDbReportBase , m_sCRepInfo , true , getUserUid ( web_access_user ) , getUserGid ( web_access_group ) ) )
{
if ( ! checkRDFDir ( m_pDbReportBase , m_sCRepInfo , true , getUserUid ( web_access_user ) , getUserGid ( web_access_group ) ) ) {
LOG_ERROR ( " Cannot Open Report!! " ) ;
return false ;
} ;
@ -501,8 +460,7 @@ bool sqliteDBC::connect(void)
# ifdef DEBUG
LOG ( m_pDbReport ) ;
# endif
if ( m_pDataReports - > Connect ( m_pDbReport , 0 , true ) )
{
if ( m_pDataReports - > Connect ( m_pDbReport , 0 , true ) ) {
# ifdef DEBUG
LOG ( " Report File Opened " ) ;
# endif