int main() { try { clock_t tStart = clock(); readConfFile(); cout<<"Started the program\n"; //cout<<tabIndex; DBConnection *squidLog = new DBConnection(); squidLog->dbConnOpen("127.0.0.1","3306","root","simple","squid"); string logReadQuery = "select * from access_log_new where id > ?;"; PreparedStatement *pstm = squidLog->conn->prepareStatement(logReadQuery); pstm->setInt(1,tabIndex); squidLog->res = pstm->executeQuery(); /*DBConnection *squidLog = new DBConnection(); squidLog->dbConnOpen("127.0.0.1","3306","root","simple","squid"); squidLog->tableName = "access_log"; squidLog->setReadPstmt(1,squidLog->tableName,"",""); squidLog->readTable();*/ statLog = new DBConnection(); createStatistics(squidLog,statLog); /*grossStatisticsAcc(statLog->tableNameAcc); grossStatisticsDen(statLog->tableNameDen); createDomainStatisticsAcc(statLog->tableNameAcc); createUserStatisticsAcc(statLog->tableNameAcc); createDomainStatisticsDen(statLog->tableNameDen); createUserStatisticsDen(statLog->tableNameDen);*/ writeConfFile(); printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); cout<<"End Of program \n"; } catch (sql::SQLException &e) { cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; } catch (exception& e) { cout << "# ERR File: " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << e.what() << '\n'; } return 0; }
//void *grossStatisticsAcc(void *tbNa) void grossStatisticsAcc(string tbNa) { string tName = tbNa; cout<<""; try { /* ifstream confFile("/home/sivaprakash/workspace/StatisticsDataFromDB/src/tabAcc.conf"); confFile>>tName; confFile.close(); cout<<"start of Acc thread for table:"<<tName<<endl;*/ PreparedStatement *readPstmt,*inPstmt,*upPstmt; ResultSet *dailyRes,*ymRes; string year = tName.substr(13,4); string month = tName.substr(10,2); string day = tName.substr(7,2); string yearStatisticstable = "ud_acc_"+year; string monthStatisticstable = "ud_acc_"+month; string schema = "squidStatistics_"+year; DBConnection *grossLog = new DBConnection(); grossLog->dbConnOpen("127.0.0.1","3306","root","simple",schema); Statement *stmt = grossLog->conn->createStatement(); checkPresenecOfGrossStatisticsTableAcc(stmt,yearStatisticstable); checkPresenecOfGrossStatisticsTableAcc(stmt,monthStatisticstable); string searchQueryMonth = "select * from "+ monthStatisticstable +" where user=? and domain=? ;"; string searchQueryYear = "select * from "+ yearStatisticstable +" where user=? and domain=?;"; string insertMonth = "insert into " + monthStatisticstable + "(user,domain,size,connection,hit,miss,response_time) values(?,?,?,?,?,?,?);"; string updateMonth = "update " + monthStatisticstable + " set size=?,connection=?,hit=?,miss=?,response_time=? where user=? and domain=?;"; string insertYear = "insert into " + yearStatisticstable + "(user,domain,size,connection,hit,miss,response_time) values(?,?,?,?,?,?,?);"; string updateYear = "update " + yearStatisticstable + " set size=?,connection=?,hit=?,miss=?,response_time=? where user=? and domain=?;"; string selectQuery = "select * from " + tName +";"; readPstmt = grossLog->conn->prepareStatement(selectQuery); dailyRes = readPstmt->executeQuery(); while(dailyRes->next()) { // cout<<dailyRes->getInt(4)<<"\tstart\n"; for(int i=0;i<2;i++) { if(i == 0) //updating monthly gross statistics { readPstmt = grossLog->conn->prepareStatement(searchQueryMonth); inPstmt = grossLog->conn->prepareStatement(insertMonth); upPstmt = grossLog->conn->prepareStatement(updateMonth); } else { readPstmt = grossLog->conn->prepareStatement(searchQueryYear); inPstmt = grossLog->conn->prepareStatement(insertYear); upPstmt = grossLog->conn->prepareStatement(updateYear); } readPstmt->setString(1,dailyRes->getString(1)); readPstmt->setString(2,dailyRes->getString(2)); ymRes = readPstmt->executeQuery(); if(ymRes->next()) { updateRowDataAcc(dailyRes,ymRes,upPstmt); } else { // cout<<dailyRes->getInt(4)<<endl; insertRowDataAcc(dailyRes,inPstmt); } } } createUserStatisticsAcc(tName); createDomainStatisticsAcc(tName); } catch (sql::SQLException &e) { cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; } catch (exception& e) { cout << "# ERR File: " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; cout << e.what() << '\n'; } }