-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
55 lines (45 loc) · 1.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <QApplication>
#include <QPushButton>
#include <QIcon>
#include <QDir>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlDriver>
#include <QSqlError>
#include <QFileInfo>
#include "Windows/StartWindow.h"
#include "Boards/OthelloBoard.h"
#include "constants.h"
bool isDBexists(){
//we check if bdd file exists
QFileInfo qfi(QDir::homePath() + QDir::separator() + "bdd");
return qfi.exists() && qfi.isFile();
}
void initConnection() {
const QString DRIVER("QSQLITE");
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(QDir::homePath() + QDir::separator() + "bdd");
db.open();
}
void createDB(){
QSqlQuery query;
// we execute some query in order to create and insert some data and ensure it's done correctly
query.exec("CREATE TABLE games (id INTEGER PRIMARY KEY, name TEXT, numberPlay INTEGER, numberWins INTEGER)");
query.exec("INSERT INTO games(name,numberPlay,numberWins) VALUES('Connect Four',0,0)");
query.exec("INSERT INTO games(name,numberPlay,numberWins) VALUES('Othello',0,0)");
query.exec("INSERT INTO games(name,numberPlay,numberWins) VALUES('Tic Tac Toe',0,0)");
}
int main(int argc, char *argv[])
{
if(!isDBexists()){
initConnection();
createDB();
}
else {
initConnection();
}
QApplication a(argc, argv);
StartWindow w;
w.show();
return a.exec();
}