-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyDictList.cpp
109 lines (93 loc) · 2.55 KB
/
MyDictList.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "MyDictList.h"
MyDictList::MyDictList(const QString &dbpath, const QString &connName)
: MySQLite(dbpath, connName)
{
if (!isTableExist("MyDictList")) // н¨µÄÊý¾Ý¿â,´´½¨±í
{
createTable();
}
}
MyDictList::~MyDictList()
{
}
bool MyDictList::dictEixst(const QString &dictPath)
{
QSqlQuery query(QString("select id from MyDictList where DictPath = '%1'").arg(dictPath), *db);
return query.next();
}
bool MyDictList::addNewDict(const QString &dictName,
const QString &dictPath)
{
if (!dictEixst(dictPath))
{
QString sql = QString("insert into MyDictList(DictName, DictPath) values('%1', '%2')")
.arg(dictName)
.arg(dictPath);
return exec(sql);
}
else
{
return false;
}
}
bool MyDictList::deleteDict(const QString &dictPath)
{
if(dictEixst(dictPath))
{
QString sql = QString("delete from MyDictList where DictPath = '%1'")
.arg(dictPath);
return exec(sql);
}
else
{
return false;
}
}
QString MyDictList::getDictName(const int &id)
{
QSqlQuery query(QString("select DictName from MyDictList where id = '%1'").arg(id), *db);
query.next();
return query.record().value(0).toString();
}
QString MyDictList::getDictPath(const int &id)
{
QSqlQuery query(QString("select DictPath from MyDictList where id = '%1'").arg(id), *db);
query.next();
return query.record().value(0).toString();
}
QString MyDictList::getDictPath(const QString &dictName)
{
QSqlQuery query(QString("select DictPath from MyDictList where DictName = '%1'").arg(dictName), *db);
query.next();
return query.record().value(0).toString();
}
QStringList MyDictList::getDictNames()
{
QStringList dictNames;
QSqlQuery query("select DictName from MyDictList", *db);
while (query.next())
{
dictNames << query.record().value("DictName").toString();
}
return dictNames;
}
QStringList MyDictList::getDictPaths()
{
QStringList dictPaths;
QSqlQuery query("select DictPath from MyDictList", *db);
while (query.next())
{
dictPaths << query.record().value("DictPath").toString();
}
return dictPaths;
}
bool MyDictList::createTable()
{
QSqlQuery query(*db);
query.exec("CREATE TABLE [MyDictList] (\
[id] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY AUTOINCREMENT, \
[DictName] TEXT NOT NULL ON CONFLICT FAIL, \
[DictPath] TEXT NOT NULL ON CONFLICT FAIL);");
db->commit();
return true;
}