-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbmanager.cpp
41 lines (35 loc) · 965 Bytes
/
dbmanager.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
#include "dbmanager.h"
#include <QMessageBox>
#include <QtSql>
#include <QObject>
DbManager::DbManager(const QString& path)
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(path);
if(!db.open())
{
QSqlQuery query(db);
query.exec("CREATE DATABASE database");
}
if (db.record("products").isEmpty())
{
QSqlQuery query(db);
query.exec("CREATE TABLE products ( \
id INTEGER PRIMARY KEY, \
name VARCHAR, \
price INTEGER UNSIGNED, \
colour VARCHAR, \
sold INTEGER \
addDate TEXT \
)");
}
if (db.record("sellers").isEmpty())
{
QSqlQuery query(db);
query.exec("CREATE TABLE sellers (id INTEGER , name VARCHAR, class VARCHAR, amount REAL, birthday TEXT, PRIMARY KEY (id) )");
}
}
QSqlDatabase* DbManager::getDB()
{
return &db;
}