Commit 7e776261 authored by Martin Straka's avatar Martin Straka Committed by Karel Slaný
Browse files

Added database transaction

parent 69df657a
...@@ -619,6 +619,8 @@ bool AccountDb::changeUserName(const QString &oldUserName, ...@@ -619,6 +619,8 @@ bool AccountDb::changeUserName(const QString &oldUserName,
goto fail; goto fail;
} }
beginTransaction();
queryStr = "UPDATE account_info " queryStr = "UPDATE account_info "
"SET key = :newUserName WHERE key = :oldUserName"; "SET key = :newUserName WHERE key = :oldUserName";
if (!query.prepare(queryStr)) { if (!query.prepare(queryStr)) {
...@@ -644,13 +646,15 @@ bool AccountDb::changeUserName(const QString &oldUserName, ...@@ -644,13 +646,15 @@ bool AccountDb::changeUserName(const QString &oldUserName,
query.bindValue(":oldUserName", oldUserName); query.bindValue(":oldUserName", oldUserName);
query.bindValue(":newUserName", newUserName); query.bindValue(":newUserName", newUserName);
if (query.exec()) { if (query.exec()) {
commitTransaction();
return true; return true;
} else { } else {
logErrorNL("Cannot execute SQL query: %s", logErrorNL("Cannot execute SQL query: %s",
query.lastError().text().toUtf8().constData()); query.lastError().text().toUtf8().constData());
goto fail;
} }
fail: fail:
rollbackTransaction();
return false; return false;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment