1#include "connection.h"
2
3IDbConnection::IDbConnection(const char *pPrefix)
4{
5 str_copy(dst&: m_aPrefix, src: pPrefix);
6}
7
8void IDbConnection::FormatCreateRace(char *aBuf, unsigned int BufferSize, bool Backup) const
9{
10 str_format(buffer: aBuf, buffer_size: BufferSize,
11 format: "CREATE TABLE IF NOT EXISTS %s_race%s ("
12 " Map VARCHAR(128) COLLATE %s NOT NULL, "
13 " Name VARCHAR(%d) COLLATE %s NOT NULL, "
14 " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "
15 " Time FLOAT DEFAULT 0, "
16 " Server CHAR(4), "
17 " cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, "
18 " cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, "
19 " cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, "
20 " cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, "
21 " cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, "
22 " cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, "
23 " cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, "
24 " cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, "
25 " cp25 FLOAT DEFAULT 0, "
26 " GameId VARCHAR(64), "
27 " DDNet7 BOOL DEFAULT FALSE, "
28 " PRIMARY KEY (Map, Name, Time, Timestamp, Server)"
29 ")",
30 GetPrefix(), Backup ? "_backup" : "",
31 BinaryCollate(), MAX_NAME_LENGTH_SQL, BinaryCollate());
32}
33
34void IDbConnection::FormatCreateTeamrace(char *aBuf, unsigned int BufferSize, const char *pIdType, bool Backup) const
35{
36 str_format(buffer: aBuf, buffer_size: BufferSize,
37 format: "CREATE TABLE IF NOT EXISTS %s_teamrace%s ("
38 " Map VARCHAR(128) COLLATE %s NOT NULL, "
39 " Name VARCHAR(%d) COLLATE %s NOT NULL, "
40 " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "
41 " Time FLOAT DEFAULT 0, "
42 " ID %s NOT NULL, " // VARBINARY(16) for MySQL and BLOB for SQLite
43 " GameId VARCHAR(64), "
44 " DDNet7 BOOL DEFAULT FALSE, "
45 " PRIMARY KEY (Id, Name)"
46 ")",
47 GetPrefix(), Backup ? "_backup" : "",
48 BinaryCollate(), MAX_NAME_LENGTH_SQL, BinaryCollate(), pIdType);
49}
50
51void IDbConnection::FormatCreateMaps(char *aBuf, unsigned int BufferSize) const
52{
53 str_format(buffer: aBuf, buffer_size: BufferSize,
54 format: "CREATE TABLE IF NOT EXISTS %s_maps ("
55 " Map VARCHAR(128) COLLATE %s NOT NULL, "
56 " Server VARCHAR(32) COLLATE %s NOT NULL, "
57 " Mapper VARCHAR(128) COLLATE %s NOT NULL, "
58 " Points INT DEFAULT 0, "
59 " Stars INT DEFAULT 0, "
60 " Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, "
61 " PRIMARY KEY (Map)"
62 ")",
63 GetPrefix(), BinaryCollate(), BinaryCollate(), BinaryCollate());
64}
65
66void IDbConnection::FormatCreateSaves(char *aBuf, unsigned int BufferSize, bool Backup) const
67{
68 str_format(buffer: aBuf, buffer_size: BufferSize,
69 format: "CREATE TABLE IF NOT EXISTS %s_saves%s ("
70 " Savegame TEXT COLLATE %s NOT NULL, "
71 " Map VARCHAR(128) COLLATE %s NOT NULL, "
72 " Code VARCHAR(128) COLLATE %s NOT NULL, "
73 " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, "
74 " Server CHAR(4), "
75 " DDNet7 BOOL DEFAULT FALSE, "
76 " SaveId VARCHAR(36) DEFAULT NULL, "
77 " PRIMARY KEY (Map, Code)"
78 ")",
79 GetPrefix(), Backup ? "_backup" : "",
80 BinaryCollate(), BinaryCollate(), BinaryCollate());
81}
82
83void IDbConnection::FormatCreatePoints(char *aBuf, unsigned int BufferSize) const
84{
85 str_format(buffer: aBuf, buffer_size: BufferSize,
86 format: "CREATE TABLE IF NOT EXISTS %s_points ("
87 " Name VARCHAR(%d) COLLATE %s NOT NULL, "
88 " Points INT DEFAULT 0, "
89 " PRIMARY KEY (Name)"
90 ")",
91 GetPrefix(), MAX_NAME_LENGTH_SQL, BinaryCollate());
92}
93