-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlite.cpp
69 lines (59 loc) · 1.22 KB
/
sqlite.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 "sqlite.h"
sql::sql()
{
sqldb = QSqlDatabase::addDatabase("QSQLITE");
mysql = nullptr;
}
sql::~sql()
{
closeSql();
delete mysql;
}
bool sql::openSql(QString path)
{
sqldb.setDatabaseName(path);
//QString err = sqldb.lastError().text();
/*
QFile dfile("assets:/db/"+path);
if (dfile.exists()){
dfile.copy("./"+path);
}
sqldb.setDatabaseName("./" + path);*/
if(!sqldb.open()){
return false;
}
else if(sqldb.open() && mysql == nullptr) {
mysql = new QSqlQuery;
return true;
}
return false;
}
void sql::closeSql()
{
sqldb.close();
}
QString sql::sqlError()
{
return mysql->lastError().text();
}
QString sql::seleteSql(QString command,int v)
{
mysql->exec(command);
QString temp;
if(mysql->isSelect())
while (mysql->next())
temp = mysql->value(v).toString();
return temp;
}
void sql::controlSql(QString command)
{
mysql->exec(command);
}
int sql::getColumnSum(QString tableName)
{
QSqlQueryModel model;
model.setQuery("SELECT * FROM " + tableName);
QString m = model.lastError().text();
int c = model.rowCount();
return c;
}