-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.cpp
26 lines (19 loc) · 983 Bytes
/
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
#include "database.h"
bool createConnection(void)
{
QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("bookkeeping.db");
if(!db.open())
{
QMessageBox::critical(0,"Cannot open database",
"Unable to eatablish a database connection.",QMessageBox::Cancel);
return false;
}
QSqlQuery query;
query.exec("create table user(id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar, password varchar, money float,begin_month int)");
query.exec("create table cost(id INTEGER PRIMARY KEY AUTOINCREMENT, type varchar, money float,reason varchar,time text)");
query.exec("create table analyze(id INTEGER PRIMARY KEY AUTOINCREMENT,time text,income float,"
"outcome float,clothe float,food float,out float,other float,budget float)");
query.exec("create table wish(id INTEGER PRIMARY KEY AUTOINCREMENT, money float,wish text,status int,surplus float)");
return true;
}