Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions panels/notification/common/dbaccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,31 @@ class Benchmark
DBAccessor::DBAccessor(const QString &key)
: m_key(key)
{
const auto dataPath = notificationDBPath();
auto dataPath = notificationDBPath();
qInfo(notifyLog) << "DBAccessor's key:" << m_key;

auto isDatabaseCorrupted = [this]() {
QSqlQuery query(m_connection);
if (!query.exec("SELECT 1")) {
qDebug() << "Database maybe corrupted, cannot execute basic query!";
m_connection.close();
return true;
}
return false;
};

if (!dataPath.isEmpty() && open(dataPath)) {
tryToCreateTable();
bool dbOpened = true;
if (isDatabaseCorrupted()) {
QString dirPath = dataPath.left(dataPath.lastIndexOf('/'));
dataPath = dirPath + "/" + "data_new_" + QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss") + ".db";
qWarning() << "original database maybe corrupted, create new one:" << dataPath;
dbOpened = open(dataPath);
}

if (dbOpened) {
tryToCreateTable();
}
}
}

Expand Down Expand Up @@ -187,8 +208,8 @@ qint64 DBAccessor::addEntity(const NotifyEntity &entity)
query.bindValue(":processedType", entity.processedType());

if (!query.exec()) {
qWarning(notifyDBLog) << "insert value to database failed: " << query.lastError().text() << entity.bubbleId() << entity.cTime();
return 0;
qWarning(notifyDBLog) << "insert value to database failed: " << query.lastError().text() << query.lastQuery() << entity.bubbleId() << entity.cTime();
return -1;
}

// to get entity's id in database
Expand Down
20 changes: 18 additions & 2 deletions panels/notification/server/dbusadaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ uint DbusAdaptor::Notify(const QString &appName, uint replacesId, const QString
const QString &body, const QStringList &actions, const QVariantMap &hints,
int expireTimeout)
{
return manager()->Notify(appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout);
uint id = manager()->Notify(appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout);
if (id == std::numeric_limits<uint>::max()) {
QDBusError error(QDBusError::InternalError, "Notify failed.");
QDBusMessage reply = QDBusMessage::createError(error);

return QDBusConnection::sessionBus().send(reply);
}

return id;
}

void DbusAdaptor::CloseNotification(uint id)
Expand Down Expand Up @@ -62,7 +70,15 @@ uint DDENotificationDbusAdaptor::Notify(const QString &appName, uint replacesId,
const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints,
int expireTimeout)
{
return manager()->Notify(appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout);
uint id = manager()->Notify(appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout);
if (id == std::numeric_limits<uint>::max()) {
QDBusError error(QDBusError::InternalError, "Notify failed.");
QDBusMessage reply = QDBusMessage::createError(error);

return QDBusConnection::sessionBus().send(reply);
}

return id;
}

void DDENotificationDbusAdaptor::CloseNotification(uint id)
Expand Down
4 changes: 4 additions & 0 deletions panels/notification/server/notificationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const

if (entity.processedType() != NotifyEntity::None) {
qint64 id = m_persistence->addEntity(entity);
if (id == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addEntity错误返回的是0,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addEntity错误返回的是0,

以将错误返回改为-1

return std::numeric_limits<uint>::max();
}

entity.setId(id);

emitRecordCountChanged();
Expand Down
Loading