From 52196a09bb174ce175bccf6aa5f3df2fb1061ff1 Mon Sep 17 00:00:00 2001 From: floty Date: Tue, 3 Jan 2012 18:02:29 +0000 Subject: [PATCH] some bugfixes according to multiple gameID and txt-export --- src/engine/log.cpp | 39 +++++++++------- src/engine/log.h | 3 +- src/gui/qt/gametable/log/guilog.cpp | 69 ++++++++++++++++++----------- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/engine/log.cpp b/src/engine/log.cpp index a7b6b90f..a65c8dc9 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -28,8 +28,11 @@ using namespace std; -Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID(0), sql("") +Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), uniqueGameID(0), curHandID(0), sql("") { + + logVersion = 1; + } Log::~Log() @@ -79,20 +82,23 @@ Log::init() sql += "PokerTH_Version TEXT NOT NULL"; sql += ",Date TEXT NOT NULL"; sql += ",Time TEXT NOT NULL"; + sql += ",LogVersion INTEGER NOT NULL"; sql += ", PRIMARY KEY(Date,Time));"; sql += "INSERT INTO Session ("; sql += "PokerTH_Version"; sql += ",Date"; sql += ",Time"; + sql += ",LogVersion"; sql += ") VALUES ("; sql += "\"" + boost::lexical_cast(POKERTH_BETA_RELEASE_STRING) + "\","; sql += "\"" + boost::lexical_cast(curDate) + "\","; - sql += "\"" + boost::lexical_cast(curTime) + "\");"; + sql += "\"" + boost::lexical_cast(curTime) + "\","; + sql += boost::lexical_cast(logVersion) + ");"; // create game table sql += "CREATE TABLE Game ("; - sql += "UniqueGameID INTEGER PRIMARY KEY AUTOINCREMENT"; + sql += "UniqueGameID INTEGER PRIMARY KEY"; sql += ",GameID INTEGER NOT NULL"; sql += ",Startmoney INTEGER NOT NULL"; sql += ",StartSb INTEGER NOT NULL"; @@ -106,7 +112,7 @@ Log::init() // create hand table sql += "CREATE TABLE Hand ("; sql += "HandID INTEGER NOT NULL"; - sql += ",GameID INTEGER NOT NULL"; + sql += ",UniqueGameID INTEGER NOT NULL"; sql += ",Dealer_Seat INTEGER"; sql += ",Sb_Amount INTEGER NOT NULL"; sql += ",Sb_Seat INTEGER NOT NULL"; @@ -122,13 +128,13 @@ Log::init() for(i=1; i<=5; i++) { sql += ",BoardCard_" + boost::lexical_cast(i) + " INTEGER"; } - sql += ",PRIMARY KEY(HandID,GameID));"; + sql += ",PRIMARY KEY(HandID,UniqueGameID));"; // create action table sql += "CREATE TABLE Action ("; sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT"; sql += ",HandID INTEGER NOT NULL"; - sql += ",GameID INTEGER NOT NULL"; + sql += ",UniqueGameID INTEGER NOT NULL"; sql += ",BeRo INTEGER NOT NULL"; sql += ",Player INTEGER NOT NULL"; sql += ",Action TEXT NOT NULL"; @@ -145,8 +151,7 @@ Log::init() void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) { - - curGameID = gameID; + uniqueGameID++; if(SQLITE_LOG) { @@ -160,7 +165,8 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal int i; sql += "INSERT INTO Game ("; - sql += "GameID"; + sql += "UniqueGameID"; + sql += ",GameID"; sql += ",Startmoney"; sql += ",StartSb"; sql += ",DealerPos"; @@ -168,7 +174,8 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal sql += ",Seat_" + boost::lexical_cast(i); } sql += ") VALUES ("; - sql += boost::lexical_cast(curGameID); + sql += boost::lexical_cast(uniqueGameID); + sql += "," + boost::lexical_cast(gameID); sql += "," + boost::lexical_cast(startCash); sql += "," + boost::lexical_cast(startSmallBlind); sql += "," + boost::lexical_cast(dealerPosition); @@ -209,7 +216,7 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned sql += "INSERT INTO Hand ("; sql += "HandID"; - sql += ",GameID"; + sql += ",UniqueGameID"; sql += ",Dealer_Seat"; sql += ",Sb_Amount"; sql += ",Sb_Seat"; @@ -220,7 +227,7 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned } sql += ") VALUES ("; sql += boost::lexical_cast(curHandID); - sql += "," + boost::lexical_cast(curGameID); + sql += "," + boost::lexical_cast(uniqueGameID); sql += "," + boost::lexical_cast(dealerPosition); sql += "," + boost::lexical_cast(smallBlind); sql += "," + boost::lexical_cast(smallBlindPosition); @@ -290,14 +297,14 @@ Log::logPlayerAction(GameState bero, int seat, PlayerActionLog action, int amoun if(action!=LOG_ACTION_NONE) { sql += "INSERT INTO Action ("; sql += "HandID"; - sql += ",GameID"; + sql += ",UniqueGameID"; sql += ",BeRo"; sql += ",Player"; sql += ",Action"; sql += ",Amount"; sql += ") VALUES ("; sql += boost::lexical_cast(curHandID); - sql += "," + boost::lexical_cast(curGameID); + sql += "," + boost::lexical_cast(uniqueGameID); sql += "," + boost::lexical_cast(bero);; sql += "," + boost::lexical_cast(seat); switch(action) { @@ -428,7 +435,7 @@ Log::logBoardCards(GameState bero, int boardCards[5]) return; } sql += " WHERE "; - sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; + sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); sql += ";"; if(myConfig->readConfigInt("LogInterval") == 0) { @@ -480,7 +487,7 @@ Log::logHoleCardsHandName(GameState bero, PlayerList activePlayerList, boost::sh sql += ",Seat_" + boost::lexical_cast(player->getMyID()+1) + "_Card_2=" + boost::lexical_cast(myCards[1]); } sql += " WHERE "; - sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; + sql += "UniqueGameID=" + boost::lexical_cast(uniqueGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); sql += ";"; if(myConfig->readConfigInt("LogInterval") == 0 || forceExecLog) { diff --git a/src/engine/log.h b/src/engine/log.h index 238790e4..759d53aa 100644 --- a/src/engine/log.h +++ b/src/engine/log.h @@ -54,9 +54,10 @@ private: void exec_transaction(); + int logVersion; sqlite3 *mySqliteLogDb; ConfigFile *myConfig; - int curGameID; + int uniqueGameID; int curHandID; std::string sql; }; diff --git a/src/gui/qt/gametable/log/guilog.cpp b/src/gui/qt/gametable/log/guilog.cpp index d955874c..f0768f57 100644 --- a/src/gui/qt/gametable/log/guilog.cpp +++ b/src/gui/qt/gametable/log/guilog.cpp @@ -695,7 +695,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) char *errmsg = 0; int game_ctr = 0, hand_ctr = 0, round_ctr = 0, action_ctr = 0; int i = 0, j = 0; - int gameID = 0; + int gameID = 0; int uniqueGameID = 0; string cmpString = "", string_tmp = ""; string player[MAX_NUMBER_OF_PLAYERS]; for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) { @@ -798,6 +798,20 @@ int guiLog::exportLog(QString fileStringPdb,int modus) // run through all games for(game_ctr=1; game_ctr<=nRow_Game; game_ctr++) { + // unique game id + data_found = false; + for(i=0; i(result_Game[i]) == "UniqueGameID") { + uniqueGameID = boost::lexical_cast(result_Game[i+nCol_Game*game_ctr]); + data_found = true; + } + } + + if(!data_found) { + sqlite3_close(mySqliteLogDb); + return 1; + } + // game id data_found = false; for(i=0; i(gameID); + sql = "SELECT HandID FROM Hand WHERE UniqueGameID="; + sql+= boost::lexical_cast(uniqueGameID); if(sqlite3_get_table(mySqliteLogDb,sql.data(),&result_Hand_ID,&nRow_Hand_ID,&nCol_Hand,&errmsg) != SQLITE_OK) { cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; sqlite3_close(mySqliteLogDb); @@ -873,8 +887,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } // read current hand - sql = "SELECT * FROM Hand WHERE GameID="; - sql+= boost::lexical_cast(gameID); + sql = "SELECT * FROM Hand WHERE UniqueGameID="; + sql+= boost::lexical_cast(uniqueGameID); sql+= " AND HandID="; sql+= boost::lexical_cast(result_Hand_ID[hand_ctr]); if(sqlite3_get_table(mySqliteLogDb,sql.data(),&result_Hand,&nRow_Hand,&nCol_Hand,&errmsg) != SQLITE_OK) { @@ -974,7 +988,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } } if(!data_found) { - cout << "Missing seat information in game " << gameID << " and hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing seat information in uniqueGame " << uniqueGameID << " and hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -985,8 +999,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(modus == 1) log_string += "
"; // read dealer and blinds - sql = "SELECT Player,Action,Amount FROM Action WHERE GameID="; - sql += boost::lexical_cast(gameID); + sql = "SELECT Player,Action,Amount FROM Action WHERE UniqueGameID="; + sql += boost::lexical_cast(uniqueGameID); sql += " AND HandID="; sql += boost::lexical_cast(result_Hand_ID[hand_ctr]); sql += " AND BeRo=0"; @@ -997,7 +1011,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) return 1; } if(nRow_Action<1) { - cout << "Missing information about dealer and blinds in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing information about dealer and blinds in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1031,8 +1045,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) log_string += "BLINDS: "; // read small blind - sql = "SELECT Player,Amount FROM Action WHERE GameID="; - sql += boost::lexical_cast(gameID); + sql = "SELECT Player,Amount FROM Action WHERE UniqueGameID="; + sql += boost::lexical_cast(uniqueGameID); sql += " AND HandID="; sql += boost::lexical_cast(result_Hand_ID[hand_ctr]); sql += " AND BeRo=0 AND Action='posts small blind'"; @@ -1043,7 +1057,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) return 1; } if(nRow_Action<1 || nRow_Action>1) { - cout << "Missing information about small blinds in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing information about small blinds in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1057,8 +1071,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) sqlite3_free_table(result_Action); // read big blind - sql = "SELECT Player,Amount FROM Action WHERE GameID="; - sql += boost::lexical_cast(gameID); + sql = "SELECT Player,Amount FROM Action WHERE UniqueGameID="; + sql += boost::lexical_cast(uniqueGameID); sql += " AND HandID="; sql += boost::lexical_cast(result_Hand_ID[hand_ctr]); sql += " AND BeRo=0 AND Action='posts big blind'"; @@ -1069,7 +1083,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) return 1; } if(nRow_Action<1 || nRow_Action>1) { - cout << "Missing information about small blinds in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing information about small blinds in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1083,8 +1097,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) sqlite3_free_table(result_Action); // read dealer - sql = "SELECT Player,Amount FROM Action WHERE GameID="; - sql += boost::lexical_cast(gameID); + sql = "SELECT Player,Amount FROM Action WHERE UniqueGameID="; + sql += boost::lexical_cast(uniqueGameID); sql += " AND HandID="; sql += boost::lexical_cast(result_Hand_ID[hand_ctr]); sql += " AND BeRo=0 AND Action='starts as dealer'"; @@ -1095,7 +1109,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) return 1; } if(nRow_Action>1) { - cout << "Implausible information about dealer in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Implausible information about dealer in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1180,7 +1194,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(modus == 1 || modus == 3) round_string += ""; string_tmp = convertCardIntToString(boost::lexical_cast(result_Hand[j+nCol_Hand])); if(string_tmp == "") { - cout << "Implausible board card in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Implausible board card in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1204,8 +1218,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } // read round action - sql = "SELECT Player,Action,Amount FROM Action WHERE GameID="; - sql += boost::lexical_cast(gameID); + sql = "SELECT Player,Action,Amount FROM Action WHERE UniqueGameID="; + sql += boost::lexical_cast(uniqueGameID); sql += " AND HandID="; sql += boost::lexical_cast(result_Hand_ID[hand_ctr]); sql += " AND BeRo="; @@ -1262,6 +1276,9 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(!neu) action_string = "

" + action_string + " " + boost::lexical_cast(gameID) + "!
"; else action_string = "
" + action_string + " " + boost::lexical_cast(gameID) + "!"; break; + case 2: + action_string += action_string + " " + boost::lexical_cast(gameID) + "!"; + break; case 3: action_string = "" + action_string + " " + boost::lexical_cast(gameID) + "!"; break; @@ -1319,7 +1336,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(boost::lexical_cast(result_Hand[i]) == cmpString) { string_tmp = convertCardIntToString(boost::lexical_cast(result_Hand[i+nCol_Hand])); if(string_tmp == "") { - cout << "Hole card information implausible in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Hole card information implausible in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1332,7 +1349,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } } if(!data_found) { - cout << "Missing hole card information in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing hole card information in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1346,7 +1363,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(boost::lexical_cast(result_Hand[i]) == cmpString) { string_tmp = convertCardIntToString(boost::lexical_cast(result_Hand[i+nCol_Hand])); if(string_tmp == "") { - cout << "Hole card information implausible in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Hole card information implausible in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1358,7 +1375,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } } if(!data_found) { - cout << "Missing hole card information in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing hole card information in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; } @@ -1376,7 +1393,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } } if(!data_found) { - cout << "Missing hand name information in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + cout << "Missing hand name information in uniqueGame " << uniqueGameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; sqlite3_close(mySqliteLogDb); return 1; }