@@ -222,6 +222,52 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity)
222222 return storageId;
223223}
224224
225+ qint64 DBAccessor::replaceEntity (qint64 id, const NotifyEntity &entity)
226+ {
227+ BENCHMARK ();
228+
229+ QMutexLocker locker (&m_mutex);
230+ QSqlQuery query (m_connection);
231+
232+ QString columns = QStringList{QString (" %1 = :icon" ).arg (ColumnIcon),
233+ QString (" %1 = :summary" ).arg (ColumnSummary),
234+ QString (" %1 = :body" ).arg (ColumnBody),
235+ QString (" %1 = :appName" ).arg (ColumnAppName),
236+ QString (" %1 = :appId" ).arg (ColumnAppId),
237+ QString (" %1 = :ctime" ).arg (ColumnCTime),
238+ QString (" %1 = :action" ).arg (ColumnAction),
239+ QString (" %1 = :hint" ).arg (ColumnHint),
240+ QString (" %1 = :replacesId" ).arg (ColumnReplacesId),
241+ QString (" %1 = :notifyId" ).arg (ColumnNotifyId),
242+ QString (" %1 = :processedType" ).arg (ColumnProcessedType)}
243+ .join (" , " );
244+
245+ QString sqlCmd = QString (" UPDATE %1 SET %2 WHERE ID = :id" ).arg (TableName_v2).arg (columns);
246+
247+ query.prepare (sqlCmd);
248+ query.bindValue (" :icon" , entity.appIcon ());
249+ query.bindValue (" :summary" , entity.summary ());
250+ query.bindValue (" :body" , entity.body ());
251+ query.bindValue (" :appName" , entity.appName ());
252+ query.bindValue (" :appId" , entity.appId ());
253+ query.bindValue (" :ctime" , entity.cTime ());
254+ query.bindValue (" :action" , entity.actionsString ());
255+ query.bindValue (" :hint" , entity.hintsString ());
256+ query.bindValue (" :replacesId" , entity.replacesId ());
257+ query.bindValue (" :notifyId" , entity.bubbleId ());
258+ query.bindValue (" :processedType" , entity.processedType ());
259+ query.bindValue (" :id" , id);
260+
261+ if (!query.exec ()) {
262+ qWarning (notifyDBLog) << " Update value to database failed: " << query.lastError ().text () << query.lastQuery () << entity.bubbleId () << entity.cTime ();
263+ return -1 ;
264+ }
265+
266+ qDebug (notifyDBLog) << " Update entity bubbleId:" << entity.bubbleId () << " , id:" << id << " , affected rows:" << query.numRowsAffected ();
267+
268+ return id;
269+ }
270+
225271void DBAccessor::updateEntityProcessedType (qint64 id, int processedType)
226272{
227273 BENCHMARK ();
0 commit comments