return uid;
}
-void SqliteStorage::updateUser(UserId user, const QString &password) {
+bool SqliteStorage::updateUser(UserId user, const QString &password) {
QSqlDatabase db = logDb();
db.transaction();
query.bindValue(":password", cryptedPassword(password));
lockForWrite();
safeExec(query);
+ bool success = query.numRowsAffected() != 0;
db.commit();
unlock();
+ return success;
}
void SqliteStorage::renameUser(UserId user, const QString &newName) {
}
UserId SqliteStorage::validateUser(const QString &user, const QString &password) {
- QSqlQuery query(logDb());
- query.prepare(queryString("select_authuser"));
- query.bindValue(":username", user);
- query.bindValue(":password", cryptedPassword(password));
+ UserId userId;
+
+ // this scope ensures that the query is freed in sqlite before we call unlock()
+ // this ensures that our thread doesn't hold a internal after unlock is called
+ // (see sqlites doc on implicit locking for details)
+ {
+ QSqlQuery query(logDb());
+ query.prepare(queryString("select_authuser"));
+ query.bindValue(":username", user);
+ query.bindValue(":password", cryptedPassword(password));
+
+ lockForRead();
+ safeExec(query);
+
+ if(query.first()) {
+ userId = query.value(0).toInt();
+ }
+ }
+ unlock();
- lockForRead();
- safeExec(query);
+ return userId;
+}
- if(query.first()) {
- unlock();
- return query.value(0).toInt();
- } else {
- unlock();
- return 0;
+UserId SqliteStorage::getUserId(const QString &username) {
+ UserId userId;
+
+ // this scope ensures that the query is freed in sqlite before we call unlock()
+ // this ensures that our thread doesn't hold a internal after unlock is called
+ // (see sqlites doc on implicit locking for details)
+ {
+ QSqlQuery query(logDb());
+ query.prepare(queryString("select_userid"));
+ query.bindValue(":username", username);
+
+ lockForRead();
+ safeExec(query);
+
+ if(query.first()) {
+ userId = query.value(0).toInt();
+ }
}
+ unlock();
+
+ return userId;
}
UserId SqliteStorage::internalUser() {
- QSqlQuery query(logDb());
- query.prepare(queryString("select_internaluser"));
- lockForRead();
- safeExec(query);
-
- if(query.first()) {
- unlock();
- return query.value(0).toInt();
- } else {
- unlock();
- return 0;
+ UserId userId;
+
+ // this scope ensures that the query is freed in sqlite before we call unlock()
+ // this ensures that our thread doesn't hold a internal after unlock is called
+ // (see sqlites doc on implicit locking for details)
+ {
+ QSqlQuery query(logDb());
+ query.prepare(queryString("select_internaluser"));
+ lockForRead();
+ safeExec(query);
+
+ if(query.first()) {
+ userId = query.value(0).toInt();
+ }
}
+ unlock();
+
+ return userId;
}
void SqliteStorage::delUser(UserId user) {
QList<CoreIdentity> identities;
QSqlDatabase db = logDb();
db.transaction();
-
+
QSqlQuery query(db);
query.prepare(queryString("select_identities"));
query.bindValue(":userid", user.toInt());
QSqlDatabase db = logDb();
db.transaction();
-
+
QSqlQuery query(db);
query.prepare(queryString("insert_network"));
query.bindValue(":userid", user.toInt());
return NetworkId();
}
}
-
+
db.commit();
unlock();
return networkId;
QSqlDatabase db = logDb();
db.transaction();
-
+
QSqlQuery query(db);
query.prepare(queryString("select_connected_networks"));
query.bindValue(":userid", user.toInt());
QSqlQuery delBufferQuery(db);
delBufferQuery.prepare(queryString("delete_buffer_for_bufferid"));
delBufferQuery.bindValue(":bufferid", bufferId2.toInt());
+ delBufferQuery.bindValue(":userid", user.toInt());
safeExec(delBufferQuery);
if(!watchQuery(delBufferQuery)) {
db.rollback();
QSqlDatabase db = logDb();
db.transaction();
- QSet<QString> senders;
+ QSet<QString> senders;
QSqlQuery addSenderQuery(db);
addSenderQuery.prepare(queryString("insert_sender"));
}
backlog.messageid = value(0).toInt();
- backlog.time = QDateTime::fromTime_t(value(1).toInt());
+ backlog.time = QDateTime::fromTime_t(value(1).toInt()).toUTC();
backlog.bufferid = value(2).toInt();
backlog.type = value(3).toInt();
backlog.flags = value(4).toInt();