-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.cpp
68 lines (66 loc) · 2.09 KB
/
database.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
#include "database.h"
#include <QDir>
#include <QFile>
#include <QSqlQuery>
#include <QDebug>
Database::Database(QObject *parent) :
QObject(parent)
{
this->db = QSqlDatabase::addDatabase("QSQLITE");
QString path(QDir::home().path());
path.append(QDir::separator()).append(".cute_credit.sqlite");
path = QDir::toNativeSeparators(path);
db.setDatabaseName(path);
if (!this->db.open()) {
printf("Could not create database!");
exit(-1);
} else {
QSqlQuery q;
QString sql = "";
sql += "CREATE TABLE messages (ref_id VARCHAR(255), ";
sql += "msg TEXT, ";
sql += "sent_at INTEGER, ";
sql += "ind VARCHAR(255),";
sql += "sa VARCHAR ( 255 ),";
sql += "name VARCHAR(255), ";
sql += "card VARCHAR(255), " ;
sql += "expiry_date VARCHAR(255), ";
sql += "uid VARCHAR(255), ";
sql += "tid VARCHAR(255), " ;
sql += "receipt_id VARCHAR(255), ";
sql += "auth VARCHAR(255), ";
sql += "total VARCHAR(255), ";
sql += "result TEXT,";
sql += "x_text TEXT, ";
sql += "transactions_remaining TEXT, ";
sql += "customer_display_text TEXT, ";
sql += "user_display_text TEXT, ";
sql += "signature_required VARCHAR(5), ";
sql += "cash_record TEXT, ";
sql += "credit_card_receipt TEXT, ";
sql += "printed VARCHAR(1), ";
sql += "receipt_text TEXT );";
if (!q.exec(sql)) {
qDebug() << "Creat Table Statement invalid!" << q.lastError().text();
}
}
}
Database::~Database() {
this->db.close();
}
void Database::runQuery(QString id, QString query) {
qDebug() << "Database received: " << query;
QSqlQuery q;
if (q.exec(query)) {
emit queryComplete(id,q);
} else {
qDebug() << "There was a query Error" << q.lastError().text();
emit queryComplete(id,q.lastError().text());
}
}
QSqlQuery Database::runQuery(QString query) {
qDebug() << "Database received Direct: " << query;
QSqlQuery q;
q.exec(query);
return q;
}