MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / AddRecent

Method AddRecent

App/Client/Recent/RecentDatabase.cpp:191–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191int CRecentDatabase::AddRecent(const RecentItem &item)
192{
193 QSqlQuery query(GetDatabase());
194 if(item.szFile.isEmpty())
195 return -1;
196 query.prepare(
197 "SELECT id FROM recent "
198 "WHERE file=:file"
199 );
200 query.bindValue(":file", item.szFile);
201 if (query.exec() && query.next()) {
202 // 更新现有记录
203 int id = query.value(0).toInt();
204
205 query.prepare(
206 "UPDATE recent SET "
207 "name=:name, "
208 "time=:time, "
209 "description=:description "
210 "WHERE id=:id"
211 );
212 query.bindValue(":name", item.szName);
213 query.bindValue(":time", item.time);
214 query.bindValue(":description", item.szDescription);
215 query.bindValue(":id", id);
216 } else {
217 query.prepare(
218 "INSERT INTO recent (operate_id, icon, name, protocol, operate_type, file, time, description)"
219 "VALUES (:operate_id, :icon, :name, :protocol, :type, :file, :time, :description)"
220 );
221 query.bindValue(":operate_id", item.szOperateId);
222 query.bindValue(":icon", m_IconDB.GetIcon(item.icon));
223 query.bindValue(":name", item.szName);
224 query.bindValue(":protocol", item.szProtocol);
225 query.bindValue(":type", item.szType);
226 query.bindValue(":file", item.szFile);
227 query.bindValue(":time", item.time);
228 query.bindValue(":description", item.szDescription);
229 }
230 bool success = query.exec();
231 if (!success) {
232 SetError("Failed to add recent: " + query.lastError().text()
233 + "; Sql: " + query.executedQuery());
234 qCritical(log) << GetError();
235 return 0;
236 }
237
238 qDebug(log) << "Insert recent id:" << query.lastInsertId().toInt();
239 emit sigChanged();
240 return query.lastInsertId().toInt();
241}
242
243bool CRecentDatabase::UpdateRecent(const RecentItem& item)
244{

Callers

nothing calls this directly

Calls 2

isEmptyMethod · 0.45
GetIconMethod · 0.45

Tested by

no test coverage detected