- QSqlQuery query(logDb());
- query.prepare(queryString("select_authuser"));
- query.bindValue(":username", user);
- query.bindValue(":password", cryptedPassword(password));
-
- 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_authuser"));
+ query.bindValue(":username", user);
+ query.bindValue(":password", cryptedPassword(password));
+
+ lockForRead();
+ safeExec(query);
+
+ if(query.first()) {
+ userId = query.value(0).toInt();
+ }