-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.cpp
69 lines (54 loc) · 1.97 KB
/
level.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "level.h"
Level::Level(QVector<QVariant> model)
{
this->id = model[0].toInt();
this->name = model[1].toString();
this->sekUmdrehen = model[2].toInt();
this->gedrehtUm = model[3].toInt();
this->strafZeit = model[4].toInt();
this->created_at = model[5].toString();
this->table = this->getTable();
}
Level::Level(DatabaseAnswer<Level>* response)
{
*this = *response->getObject();
}
DatabaseAnswer<Level>* Level::create(QString name, int sekUmdrehen, int gedrehtUm, int strafZeit, Database* db)
{
DatabaseAnswer<Level>* response = db->execModel<Level>(Level::generateSaveModel(name, sekUmdrehen, gedrehtUm, strafZeit));
if(response->hasError()){
Error(500, "QueryError", response->errorToText());
} else {
response = db->find<Level>(Level::generateFindModel(name, Level::getTable()));
}
return response;
}
QString Level::getTable()
{
return "tblLevels";
}
QString Level::generateDeleteModel()
{
return "DELETE FROM " + Level::getTable() + " WHERE name LIKE '" + this->getName() + "'";
}
QString Level::generateDeleteHighscoresModel(QString table)
{
return "DELETE FROM " + table + " WHERE idLevel = " + QString::number(this->getId());
}
QString Level::generateFindModel(QString name, QString table)
{
return "SELECT * FROM " + table + " WHERE name LIKE '" + name + "'";
}
QString Level::generateFindIdModel(int id, QString table)
{
return "SELECT * FROM " + table + " WHERE id = " + QString::number(id);
}
QString Level::generateFindAllModel(QString table)
{
return "SELECT * FROM " + table;
}
QString Level::generateSaveModel(QString name, int sekUmdrehen, int gedrehtUm, int strafZeit)
{
QDate created_at = QDate::currentDate();
return "INSERT INTO " + Level::getTable() + " (name, sekUmdrehen, gedrehtUm, strafZeit, created_at) VALUES ('" + name + "', " + QString::number(sekUmdrehen) + ", " + QString::number(gedrehtUm) + ", " + QString::number(strafZeit) + ", '" + created_at.toString() + "')";
}