aboutsummaryrefslogtreecommitdiff
path: root/src/Database/createtables.cpp
blob: b437163e8a998095113084a6e11bd99a063ba06b (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "databaseinterface.h"

bool createTables()
{
    { // create serverlist
        QSqlQuery q;
        QString createServerlist = QStringLiteral(
            "CREATE TABLE serverlist("
            "id            INTEGER PRIMARY KEY AUTOINCREMENT,"
            "gamename      TEXT    NOT NULL DEFAULT '',"
            "ip            TEXT    NOT NULL ,"
            "queryport     INTEGER NOT NULL DEFAULT 0,"
            "t_protocol    INTEGER NOT NULL DEFAULT 0,"
            "f_blacklist   INTEGER NOT NULL DEFAULT 0,"
            "f_auth        INTEGER NOT NULL DEFAULT 0,"
            "f_direct      INTEGER NOT NULL DEFAULT 0,"
            "dt_added      BIGINT  DEFAULT (CAST(strftime('%s','now') AS BIGINT)),"
            "dt_beacon     BIGINT  DEFAULT (CAST(strftime('%s','now') AS BIGINT)),"
            "dt_sync       BIGINT  DEFAULT (CAST(strftime('%s','now') AS BIGINT)),"
            "dt_updated    BIGINT  DEFAULT (CAST(strftime('%s','now') AS BIGINT))"
            ")");

        // bind values and execute (not all db-interfaces support prepare(create table), exec directly)
        if ( ! q.exec(createServerlist) )
            return reportQuery(q);
    }

    { // create serverinfo
        QSqlQuery q;
        QString createServerinfo = QStringLiteral(
            "CREATE TABLE serverinfo("
                "sid                    INTEGER NOT NULL DEFAULT 0,"
                "hostport               INTEGER NOT NULL DEFAULT 0,"
                "hostname               TEXT,"
                "gamever                TEXT,"
                "minnetver              TEXT,"
                "country                TEXT,"
                "location               TEXT,"
                "listenserver           TEXT,"
                "adminname              TEXT,"
                "adminemail             TEXT,"
                "password               TEXT,"
                "gametype               TEXT,"
                "gamestyle              TEXT,"
                "changelevels           TEXT,"
                "maptitle               TEXT,"
                "mapname                TEXT,"
                "numplayers             INTEGER DEFAULT 0,"
                "maxplayers             INTEGER DEFAULT 0,"
                "minplayers             INTEGER DEFAULT 0,"
                "botskill               TEXT,"
                "balanceteams           TEXT,"
                "playersbalanceteams    TEXT,"
                "friendlyfire           TEXT,"
                "maxteams               TEXT,"
                "timelimit              TEXT,"
                "goalteamscore          TEXT,"
                "fraglimit              TEXT,"
                "mutators               TEXT DEFAULT 'None',"
                "misc                   TEXT,"
                "dt_serverinfo          BIGINT DEFAULT (CAST(strftime('%s','now') AS BIGINT))"
            ")");

        // bind values and execute
        if ( ! q.exec(createServerinfo) )
            return reportQuery(q);
    }

    { // create playerinfo
        QSqlQuery q;
        QString createPlayerlist = QStringLiteral(
            "CREATE TABLE playerinfo("
                "sid        INTEGER NOT NULL DEFAULT 0,"
                "name       TEXT DEFAULT 'Player',"
                "team       TEXT,"
                "frags      INTEGER DEFAULT 0,"
                "mesh       TEXT,"
                "skin       TEXT,"
                "face       TEXT,"
                "ping       INTEGER DEFAULT 0,"
                "misc       TEXT,"
                "dt_player  BIGINT DEFAULT (CAST(strftime('%s','now') AS BIGINT))"
            ")");

        // bind values and execute
        if ( ! q.exec(createPlayerlist) )
            return reportQuery(q);
    }

    { // create gameinfo
        QSqlQuery q;
        QString createGamelist = QStringLiteral(
            "CREATE TABLE gameinfo("
                "gamename   TEXT    NOT NULL DEFAULT '',"
                "label      TEXT    NOT NULL DEFAULT '',"
                "num_total  INTEGER NOT NULL DEFAULT 0,"
                "num_direct INTEGER NOT NULL DEFAULT 0"
            ")");

        // bind values and execute
        if ( ! q.exec(createGamelist) )
            return reportQuery(q);
    }

    { // create version info
        QSqlQuery q;
        QString createVersion = QStringLiteral(
            "CREATE TABLE versioninfo("
                "type    TEXT    NOT NULL DEFAULT '',"
                "version TEXT    NOT NULL DEFAULT ''"
            ")");

        // bind values and execute
        if ( ! q.exec(createVersion) )
            return reportQuery(q);

        // insert current version directly into the db during creation
        q.prepare("INSERT INTO versioninfo (type, version) VALUES (\"database\", :currentver)");
        q.bindValue(":currentver", BUILD_VERSION);

        if ( ! q.exec() )
            reportQuery(q);
    }

    // TODO: optional: write an sql file to /data/tables.sql for easy access on generated tables.

    // no errors
    return true;
}