Skip to content

Commit bda5713

Browse files
committed
App: modify CRecentDatabase error
1 parent 9ac30c0 commit bda5713

1 file changed

Lines changed: 29 additions & 19 deletions

File tree

App/Client/Recent/RecentDatabase.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool CRecentDatabase::OnInitializeSqliteDatabase()
5757
QSqlQuery query(GetDatabase());
5858

5959
// Create recent table
60-
bool success = query.exec(
60+
QString szSql =
6161
"CREATE TABLE IF NOT EXISTS recent ("
6262
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
6363
" operate_id TEXT NOT NULL,"
@@ -68,11 +68,13 @@ bool CRecentDatabase::OnInitializeSqliteDatabase()
6868
" file TEXT UNIQUE NOT NULL,"
6969
" time DATETIME DEFAULT CURRENT_TIMESTAMP,"
7070
" description TEXT"
71-
")"
72-
);
71+
")";
72+
bool success = query.exec(szSql);
7373

7474
if (!success) {
75-
qCritical(log) << "Failed to create recent table:" << query.lastError().text();
75+
SetError("Failed to create recent table: " + query.lastError().text()
76+
+ "; Sql:" + szSql);
77+
qCritical(log) << GetError();
7678
return false;
7779
}
7880

@@ -90,7 +92,7 @@ bool CRecentDatabase::OnInitializeSqliteDatabase()
9092
<< "Sql:" << query.executedQuery();
9193
}
9294

93-
QString szSql = R"(
95+
szSql = R"(
9496
CREATE TRIGGER delete_icon_after_recent
9597
AFTER DELETE ON recent
9698
FOR EACH ROW
@@ -122,7 +124,7 @@ bool CRecentDatabase::OnInitializeMySqlDatabase()
122124
QSqlQuery query(GetDatabase());
123125

124126
// Create recent table
125-
success = query.exec(
127+
QString szSql =
126128
"CREATE TABLE IF NOT EXISTS recent ("
127129
" id INTEGER PRIMARY KEY AUTO_INCREMENT,"
128130
" operate_id TEXT NOT NULL,"
@@ -134,12 +136,12 @@ bool CRecentDatabase::OnInitializeMySqlDatabase()
134136
" time DATETIME DEFAULT CURRENT_TIMESTAMP,"
135137
" description TEXT,"
136138
" UNIQUE KEY uk_recent_file (file(255))"
137-
")"
138-
);
139+
")";
140+
success = query.exec(szSql);
139141
if (!success) {
140-
qCritical(log) << "Failed to create recent table:"
141-
<< query.lastError().text()
142-
<< "Sql:" << query.executedQuery();
142+
SetError("Failed to create recent table: " + query.lastError().text()
143+
+ "; Sql: " + szSql);
144+
qCritical(log) << GetError();
143145
return false;
144146
}
145147

@@ -150,7 +152,7 @@ bool CRecentDatabase::OnInitializeMySqlDatabase()
150152
<< "Sql:" << query.executedQuery();
151153
}
152154

153-
QString szSql = R"(
155+
szSql = R"(
154156
CREATE TRIGGER delete_icon_after_recent
155157
AFTER DELETE ON recent
156158
FOR EACH ROW
@@ -227,7 +229,9 @@ int CRecentDatabase::AddRecent(const RecentItem &item)
227229
}
228230
bool success = query.exec();
229231
if (!success) {
230-
qCritical(log) << "Failed to add recent:" << query.lastError().text();
232+
SetError("Failed to add recent: " + query.lastError().text()
233+
+ "; Sql: " + query.executedQuery());
234+
qCritical(log) << GetError();
231235
return 0;
232236
}
233237

@@ -258,8 +262,9 @@ bool CRecentDatabase::UpdateRecent(
258262

259263
bool success = query.exec();
260264
if (!success) {
261-
qCritical(log) << "Failed to update recent:" << query.lastError().text()
262-
<< "Sql:" << query.executedQuery();
265+
SetError("Failed to update recent: " + query.lastError().text()
266+
+ "; Sql: " + query.executedQuery());
267+
qCritical(log) << GetError();
263268
}
264269
emit sigChanged();
265270
return success;
@@ -273,8 +278,10 @@ bool CRecentDatabase::DeleteRecent(int id)
273278
query.bindValue(":id", id);
274279
bool success = query.exec();
275280
if (!success) {
276-
qCritical(log) << "Failed to delete recent id:"
277-
<< id << query.lastError().text();
281+
SetError("Failed to delete recent: " + query.lastError().text()
282+
+ "; Sql: " + query.executedQuery()
283+
+ "; id: " + QString::number(id));
284+
qCritical(log) << GetError();
278285
}
279286
return success;
280287
}
@@ -315,7 +322,9 @@ QList<CRecentDatabase::RecentItem> CRecentDatabase::GetRecents(int limit, int of
315322
items.append(item);
316323
}
317324
} else {
318-
qCritical(log) << "Failed to get recents:" << query.lastError().text();
325+
SetError("Failed to get recents: " + query.lastError().text()
326+
+ "; Sql: " + query.executedQuery());
327+
qCritical(log) << GetError();
319328
}
320329

321330
return items;
@@ -359,7 +368,8 @@ bool CRecentDatabase::ImportFromJson(const QJsonObject &obj)
359368
{
360369
QJsonArray recents = obj["Recent"].toArray();
361370
if(recents.isEmpty()){
362-
qCritical(log) << "The file format is error. Don't find recents";
371+
SetError(tr("The file format is error. Don't find recents"));
372+
qCritical(log) << GetError();
363373
return false;
364374
}
365375

0 commit comments

Comments
 (0)