Skip to content

Commit ad85de8

Browse files
committed
Database: modify field name
1 parent 9348e8a commit ad85de8

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

App/Client/Recent/RecentDatabase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool CRecentDatabase::OnInitializeDatabase()
3939
" icon INTEGER DEFAULT 0,"
4040
" name TEXT NOT NULL,"
4141
" protocol TEXT,"
42-
" type TEXT,"
42+
" operate_type TEXT,"
4343
" file TEXT UNIQUE NOT NULL,"
4444
" time DATETIME DEFAULT CURRENT_TIMESTAMP,"
4545
" description TEXT"
@@ -115,7 +115,7 @@ int CRecentDatabase::AddRecent(const RecentItem &item)
115115
query.bindValue(":id", id);
116116
} else {
117117
query.prepare(
118-
"INSERT INTO recent (operate_id, icon, name, protocol, type, file, time, description)"
118+
"INSERT INTO recent (operate_id, icon, name, protocol, operate_type, file, time, description)"
119119
"VALUES (:operate_id, :icon, :name, :protocol, :type, :file, :time, :description)"
120120
);
121121
query.bindValue(":operate_id", item.szOperateId);
@@ -182,13 +182,13 @@ QList<CRecentDatabase::RecentItem> CRecentDatabase::GetRecents(int limit, int of
182182
QSqlQuery query(GetDatabase());
183183
if(0 > limit) {
184184
query.prepare(
185-
"SELECT id, operate_id, icon, name, protocol, type, file, time, description "
185+
"SELECT id, operate_id, icon, name, protocol, operate_type, file, time, description "
186186
"FROM recent "
187187
"ORDER BY time DESC "
188188
);
189189
} else {
190190
query.prepare(
191-
"SELECT id, operate_id, icon, name, protocol, type, file, time, description "
191+
"SELECT id, operate_id, icon, name, protocol, operate_type, file, time, description "
192192
"FROM recent "
193193
"ORDER BY time DESC "
194194
"LIMIT :limit OFFSET :offset"

App/Client/Resource/Database/Sqlite.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ CREATE INDEX idx_favorite_folders_parent ON favorite_folders(parent_id);
1414
CREATE TABLE favorite_tree (
1515
id INTEGER PRIMARY KEY AUTOINCREMENT,
1616
name TEXT,
17-
key INTEGER DEFAULT 0,
17+
value INTEGER DEFAULT 0,
1818
created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
1919
modified_time DATETIME DEFAULT CURRENT_TIMESTAMP,
2020
last_visit_time DATETIME,
2121
parent_id INTEGER DEFAULT 0
2222
);
2323

2424
-- 创建索引
25-
CREATE INDEX idx_favorite_tree_key ON favorite_tree(key);
25+
CREATE INDEX idx_favorite_tree_value ON favorite_tree(value);
2626
CREATE INDEX idx_favorite_tree_parent_id ON favorite_tree(parent_id);
2727

2828
-- 创建表
@@ -44,7 +44,7 @@ CREATE TABLE recent (
4444
icon INTEGER DEFAULT 0,
4545
name TEXT NOT NULL,
4646
protocol TEXT,
47-
type TEXT,
47+
operate_type TEXT,
4848
file TEXT UNIQUE NOT NULL,
4949
time DATETIME DEFAULT CURRENT_TIMESTAMP,
5050
description TEXT

App/Client/Resource/Database/mysql.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ CREATE INDEX idx_favorite_folders_parent ON favorite_folders(parent_id);
1414
CREATE TABLE favorite_tree (
1515
id INTEGER PRIMARY KEY AUTO_INCREMENT,
1616
name TEXT,
17-
`key` INTEGER DEFAULT 0,
17+
value INTEGER DEFAULT 0,
1818
created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
1919
modified_time DATETIME DEFAULT CURRENT_TIMESTAMP,
2020
last_visit_time DATETIME,
2121
parent_id INTEGER DEFAULT 0
2222
);
2323

2424
-- 创建索引
25-
CREATE INDEX idx_favorite_tree_key ON favorite_tree(`key`);
25+
CREATE INDEX idx_favorite_tree_value ON favorite_tree(value);
2626
CREATE INDEX idx_favorite_tree_parent_id ON favorite_tree(parent_id);
2727

2828
-- 创建表
@@ -45,7 +45,7 @@ CREATE TABLE recent (
4545
icon INTEGER DEFAULT 0,
4646
name TEXT NOT NULL,
4747
protocol TEXT,
48-
`type` TEXT,
48+
operate_type TEXT,
4949
file TEXT NOT NULL,
5050
time DATETIME DEFAULT CURRENT_TIMESTAMP,
5151
description TEXT,

Src/Database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bool CDatabase::OpenSQLiteDatabase(
8585
if (!dir.exists()) {
8686
dir.mkpath(dataDir);
8787
}
88-
databasePath = dir.filePath("database.db");
88+
databasePath = dir.filePath("remote_control.db");
8989
} else {
9090
databasePath = dbPath;
9191
}

Src/DatabaseTree.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ bool CDatabaseTree::OnInitializeDatabase()
516516
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
517517
" parent_id INTEGER DEFAULT 0,"
518518
" name TEXT,"
519-
" key INTEGER DEFAULT 0,"
519+
" value INTEGER DEFAULT 0,"
520520
" created_time DATETIME DEFAULT CURRENT_TIMESTAMP,"
521521
" modified_time DATETIME DEFAULT CURRENT_TIMESTAMP,"
522522
" last_visit_time DATETIME"
@@ -531,7 +531,7 @@ bool CDatabaseTree::OnInitializeDatabase()
531531
}
532532

533533
// 创建索引
534-
query.exec("CREATE INDEX IF NOT EXISTS idx_" + m_szTableName + "_key ON " + m_szTableName + "(key)");
534+
query.exec("CREATE INDEX IF NOT EXISTS idx_" + m_szTableName + "_value ON " + m_szTableName + "(value)");
535535
query.exec("CREATE INDEX IF NOT EXISTS idx_" + m_szTableName + "_parent_id ON " + m_szTableName + "(parent_id)");
536536

537537
return true;
@@ -545,7 +545,7 @@ int CDatabaseTree::Add(const TreeItem &item)
545545
// Check if it already exists
546546
query.prepare(
547547
"SELECT id FROM " + m_szTableName +
548-
" WHERE key=:key AND parent_id=:parent_id"
548+
" WHERE value=:key AND parent_id=:parent_id"
549549
);
550550
query.bindValue(":key", item.GetKey());
551551
query.bindValue(":parent_id", item.GetParentId());
@@ -561,7 +561,7 @@ int CDatabaseTree::Add(const TreeItem &item)
561561

562562
// Insert
563563
query.prepare(
564-
"INSERT INTO " + m_szTableName + " (name, key, "
564+
"INSERT INTO " + m_szTableName + " (name, value, "
565565
"created_time, modified_time, last_visit_time, parent_id) "
566566
"VALUES (:name, :key, "
567567
":created_time, :modified_time, :last_visit_time, :parent_id)"
@@ -596,7 +596,7 @@ bool CDatabaseTree::Update(const TreeItem &item)
596596
query.prepare(
597597
"UPDATE " + m_szTableName + " SET "
598598
"name = :name, "
599-
"key = :key, "
599+
"value = :key, "
600600
"created_time = :created_time, "
601601
"modified_time = :modified_time, "
602602
"last_visit_time = :last_visit_time, "
@@ -740,7 +740,7 @@ TreeItem CDatabaseTree::GetLeaf(int id)
740740

741741
QSqlQuery query(GetDatabase());
742742
query.prepare(
743-
"SELECT name, key, "
743+
"SELECT name, value, "
744744
"created_time, modified_time, last_visit_time, parent_id FROM " + m_szTableName +
745745
" WHERE id = :id");
746746
query.bindValue(":id", id);
@@ -770,7 +770,7 @@ QList<TreeItem> CDatabaseTree::GetLeaves(int nodeId)
770770
QList<TreeItem> items;
771771
QSqlQuery query(GetDatabase());
772772
QString szSql;
773-
szSql = "SELECT id, name, key, "
773+
szSql = "SELECT id, name, value, "
774774
"created_time, modified_time, last_visit_time, parent_id "
775775
"FROM " + m_szTableName;
776776
if(0 <= nodeId)
@@ -810,7 +810,7 @@ QList<TreeItem> CDatabaseTree::GetLeavesByKey(int key)
810810
szSql = "SELECT id, name, "
811811
"created_time, modified_time, last_visit_time, parent_id "
812812
"FROM " + m_szTableName +
813-
" WHERE key = :key";
813+
" WHERE value = :key";
814814
query.prepare(szSql);
815815
query.bindValue(":key", key);
816816
bool success = query.exec();
@@ -844,17 +844,17 @@ QList<TreeItem> CDatabaseTree::GetLeavesByKey(QList<int> key)
844844

845845
QSqlQuery query(GetDatabase());
846846
QString szSql;
847-
szSql = "SELECT id, name, key, "
847+
szSql = "SELECT id, name, value, "
848848
"created_time, modified_time, last_visit_time, parent_id "
849849
"FROM " + m_szTableName +
850850
" WHERE ";
851851
int i = 0;
852852
foreach(auto KeyId, key) {
853853
if(0 == i++) {
854-
szSql += " key = " + QString::number(KeyId);
854+
szSql += " value = " + QString::number(KeyId);
855855
continue;
856856
}
857-
szSql += " OR key = " + QString::number(KeyId);
857+
szSql += " OR value = " + QString::number(KeyId);
858858
}
859859
bool success = query.exec(szSql);
860860
if (!success) {
@@ -952,7 +952,7 @@ bool CDatabaseTree::ExportToJson(QJsonObject& obj)
952952

953953
QSqlQuery query(GetDatabase());
954954
query.prepare(
955-
"SELECT id, parent_id, name, key, "
955+
"SELECT id, parent_id, name, value, "
956956
"created_time, modified_time, last_visit_time FROM " + m_szTableName);
957957
bool success = query.exec();
958958
if (!success) {

0 commit comments

Comments
 (0)