changes in logging with sqlite-db

This commit is contained in:
floty
2010-07-02 23:29:30 +00:00
parent fdabcfcdda
commit 51126fad7c
4 changed files with 212 additions and 218 deletions
+139 -146
View File
@@ -60,7 +60,7 @@ Log::Log(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), my
myLogDir = new QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str()));
QDateTime currentTime = QDateTime::currentDateTime();
myHtmlLogFile = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+".html");
mySqliteLogDb = new QSqlDatabase();
mySqliteLogDb = new QSqlDatabase;
//Logo-Pixmap extrahieren
QPixmap logoChipPixmapFile(":/gfx/logoChip3D.png");
@@ -84,74 +84,77 @@ Log::Log(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), my
// lege sqlite-Datenbank
*mySqliteLogDb = QSqlDatabase::addDatabase("QSQLITE");
mySqliteLogDb->setDatabaseName(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+".pdb");
if(!mySqliteLogDb->open()) {
if(mySqliteLogDb->open()) {
QSqlQuery query(*mySqliteLogDb);
QString sql;
// Session-Tabelle
sql = "CREATE TABLE Session (";
sql += "Version TEXT,";
sql += "Date TEXT,";
sql += "Time TEXT,";
sql += "PRIMARY KEY(Date,Time))";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
sql = "INSERT INTO Session (Version,Date,Time) VALUES (";
sql += "'"+QString("%1").arg(POKERTH_BETA_RELEASE_STRING)+"',";
sql += "'"+currentTime.toString("yyyy-MM-dd")+"',";
sql += "'"+currentTime.toString("hh:mm:ss")+"')";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Game-Tabelle
sql = "CREATE TABLE Game (";
sql += "GameID INTEGER NOT NULL PRIMARY KEY,";
sql += "Startmoney INTEGER NOT NULL,";
sql += "StartSb INTEGER NOT NULL,";
sql += "DealerPos INTEGER NOT NULL";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + QString("%1").arg(i);
}
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Hand-Tabelle
sql = "CREATE TABLE Hand (";
sql += "HandID INTEGER NOT NULL,";
sql += "GameID INTEGER NOT NULL,";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += "Seat_" + QString("%1").arg(i) + "_Cash INTEGER,";
sql += "Seat_" + QString("%1").arg(i) + "_Card_1 INTEGER,";
sql += "Seat_" + QString("%1").arg(i) + "_Card_2 INTEGER,";
}
for(i=1; i<=5; i++) {
sql += "BoardCard_" + QString("%1").arg(i) + " INTEGER,";
}
sql += "PRIMARY KEY(HandID,GameID))";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Action-Tabelle
sql = "CREATE TABLE Action (";
sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT,";
sql += "HandID INTEGER NOT NULL,";
sql += "GameID INTEGER NOT NULL,";
sql += "BeRo INTEGER NOT NULL,";
sql += "Player INTEGER NOT NULL,";
sql += "Action INTEGER NOT NULL,";
sql += "Amount INTEGER)";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
} else {
QMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
QString sql;
QSqlQuery query;
// Session-Tabelle
sql = "CREATE TABLE Session (Version TEXT,Date TEXT,Time TEXT, PRIMARY KEY(Date,Time))";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
sql = "INSERT INTO Session (Version,Date,Time) VALUES (";
sql += "'"+QString("%1").arg(POKERTH_BETA_RELEASE_STRING)+"',";
sql += "'"+currentTime.toString("yyyy-MM-dd")+"',";
sql += "'"+currentTime.toString("hh:mm:ss")+"')";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Game-Tabelle
sql = "CREATE TABLE Game (";
sql += "GameID INTEGER NOT NULL PRIMARY KEY,";
sql += "Startmoney INTEGER NOT NULL,";
sql += "StartSb INTEGER NOT NULL,";
sql += "DealerPos INTEGER NOT NULL";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + QString("%1").arg(i);
}
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Hand-Tabelle
sql = "CREATE TABLE Hand (";
sql += "HandID INTEGER NOT NULL,";
sql += "GameID INTEGER NOT NULL,";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += "Seat_" + QString("%1").arg(i) + "_Cash INTEGER,";
sql += "Seat_" + QString("%1").arg(i) + "_Card_1 INTEGER,";
sql += "Seat_" + QString("%1").arg(i) + "_Card_2 INTEGER,";
}
for(i=1; i<=5; i++) {
sql += "BoardCard_" + QString("%1").arg(i) + " INTEGER,";
}
sql += "PRIMARY KEY(HandID,GameID))";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// Action-Tabelle
sql = "CREATE TABLE Action (";
sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT,";
sql += "HandID INTEGER NOT NULL,";
sql += "GameID INTEGER NOT NULL,";
sql += "BeRo INTEGER NOT NULL,";
sql += "Player INTEGER NOT NULL,";
sql += "Action INTEGER NOT NULL,";
sql += "Amount INTEGER)";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
query.clear();
// Datenbank schließen
mySqliteLogDb->close();
//Zu alte Dateien löschen!!!
int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration");
@@ -189,7 +192,8 @@ Log::Log(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), my
Log::~Log()
{
// Datenbank schließen
mySqliteLogDb->close();
delete myConfig;
delete myLogDir;
@@ -230,31 +234,26 @@ void Log::logPlayerActionMsg(QString msg, int playerID, int action, int setValue
logFileStreamString = "";
}
if(!mySqliteLogDb->open()) {
QMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().data(), QMessageBox::Cancel);
if(mySqliteLogDb->isOpen()) {
QSqlQuery query(*mySqliteLogDb);
QString sql;
sql = "INSERT INTO Action (HandID,GameID,BeRo,Player,Action,Amount) VALUES (";
sql += QString::number(myW->getSession()->getCurrentGame()->getCurrentHandID(),10);
sql += "," + QString::number(myW->getSession()->getCurrentGame()->getMyGameID(),10);
sql += "," + QString::number(myW->getSession()->getCurrentGame()->getCurrentHand()->getCurrentBeRo()->getMyBeRoID(),10);
sql += "," + QString::number(playerID,10);
sql += "," + QString::number(action,10);
sql += "," + QString::number(setValue,10);
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
}
QString sql;
QSqlQuery query;
sql = "INSERT INTO Action (HandID,GameID,BeRo,Player,Action,Amount) VALUES (";
sql += QString::number(myW->getSession()->getCurrentGame()->getCurrentHandID(),10);
sql += "," + QString::number(myW->getSession()->getCurrentGame()->getMyGameID(),10);
sql += "," + QString::number(myW->getSession()->getCurrentGame()->getCurrentHand()->getCurrentBeRo()->getMyBeRoID(),10);
sql += "," + QString::number(playerID,10);
sql += "," + QString::number(action,10);
sql += "," + QString::number(setValue,10);
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
query.clear();
mySqliteLogDb->close();
}
}
@@ -277,55 +276,57 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
QMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
// bei Beginn eines Games
QString sql;
QSqlQuery query;
if(handID == 1) {
sql = "INSERT INTO Game (GameID,Startmoney,StartSb,DealerPos";
if(mySqliteLogDb->isOpen()) {
QSqlQuery query(*mySqliteLogDb);
QString sql;
// bei Beginn eines Games
if(handID == 1) {
sql = "INSERT INTO Game (GameID,Startmoney,StartSb,DealerPos";
for(i=1;i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + QString::number(i,10);
}
sql += ") VALUES (";
sql += QString::number(gameID,10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getStartCash(),10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getStartSmallBlind(),10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getDealerPosition(),10);
for(it_c = currentHand->getSeatsList()->begin();it_c!=currentHand->getSeatsList()->end();it_c++) {
if((*it_c)->getMyActiveStatus()) {
sql += ",'" + QString::fromUtf8((*it_c)->getMyName().c_str()) +"'";
} else {
sql += ",NULL";
}
}
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
}
sql = "INSERT INTO Hand (HandID,GameID";
for(i=1;i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + QString::number(i,10);
sql += ",Seat_" + QString("%1").arg(i) + "_Cash";
}
sql += ") VALUES (";
sql += QString::number(gameID,10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getStartCash(),10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getStartSmallBlind(),10) + ",";
sql += QString::number(myW->getSession()->getCurrentGame()->getDealerPosition(),10);
sql += QString::number(handID,10);
sql += "," + QString::number(gameID,10);
for(it_c = currentHand->getSeatsList()->begin();it_c!=currentHand->getSeatsList()->end();it_c++) {
if((*it_c)->getMyActiveStatus()) {
sql += ",'" + QString::fromUtf8((*it_c)->getMyName().c_str()) +"'";
sql += "," + QString::number((*it_c)->getMyCash()+(*it_c)->getMySet(),10);
} else {
sql += ",NULL";
}
}
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
}
sql = "INSERT INTO Hand (HandID,GameID";
for(i=1;i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + QString("%1").arg(i) + "_Cash";
}
sql += ") VALUES (";
sql += QString::number(handID,10);
sql += "," + QString::number(gameID,10);
for(it_c = currentHand->getSeatsList()->begin();it_c!=currentHand->getSeatsList()->end();it_c++) {
if((*it_c)->getMyActiveStatus()) {
sql += "," + QString::number((*it_c)->getMyCash()+(*it_c)->getMySet(),10);
} else {
sql += ",NULL";
}
}
sql += ")";
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
query.clear();
mySqliteLogDb->close();
//print cash only for active players
@@ -466,18 +467,15 @@ void Log::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int
sql += "GameID = " + QString::number(myW->getSession()->getCurrentGame()->getMyGameID(),10);
if(roundID <= 3) {
if(!mySqliteLogDb->open()) {
QMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().data(), QMessageBox::Cancel);
if(mySqliteLogDb->isOpen()) {
QSqlQuery query(*mySqliteLogDb);
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
}
QSqlQuery query;
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
query.clear();
mySqliteLogDb->close();
}
}
@@ -524,19 +522,14 @@ void Log::logFlipHoleCardsMsg(QString playerName, int playerID, int card1, int c
sql += "HandID = " + QString::number(myW->getSession()->getCurrentGame()->getCurrentHandID(),10) + " AND ";
sql += "GameID = " + QString::number(myW->getSession()->getCurrentGame()->getMyGameID(),10);
if(!mySqliteLogDb->open()) {
QMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().data(), QMessageBox::Cancel);
if(mySqliteLogDb->isOpen()) {
QSqlQuery query(*mySqliteLogDb);
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
}
QSqlQuery query;
if(!query.exec(sql)) {
QMessageBox::critical(0, tr("ERROR"),query.lastError().text().toUtf8().data(), QMessageBox::Cancel);
}
query.clear();
mySqliteLogDb->close();
}