return exec(q);
}
+bool Database::pendingRequestDataError(const PendingRequest &request)
+{
+ QSqlQuery &q = prepare(
+ "UPDATE pending_request "
+ " SET connection_error_count = 0, data_error_count = data_error_count + 1 "
+ " WHERE aid = :aid "
+ " AND eid = :eid "
+ " AND fid = :fid "
+ " AND ed2k = :ed2k "
+ " AND size = :size ");
+
+ q.bindValue(":aid", request.aid);
+ q.bindValue(":eid", request.eid);
+ q.bindValue(":fid", request.fid);
+ q.bindValue(":ed2k", (request.ed2k.isNull() ? QByteArray("") : request.ed2k).constData());
+ q.bindValue(":size", request.size);
+
+ return exec(q);
+}
+
bool Database::clearStartedPendingRequests()
{
return exec(
bool removeReport(int reportId);
bool failPendingRequestsFromOldClients();
+ bool pendingRequestDataError(const PendingRequest &request);
+
bool clearStartedPendingRequests();
bool clearStartedMyListUpdateRequests();
bool clearFileRenames();
Q_ASSERT(reply);
reply->deleteLater();
+ RaiiTransaction t(db);
+ t.commit();
+
if (!success)
+ {
+ PendingRequest r;
+ r.aid = reply->command().aid();
+ db->pendingRequestDataError(r);
return;
+ }
- db->transaction();
// If entry exists we get to update fields we know.
// Entry might exist just with my values and aid from vote command
Anime next = db->getAnime(reply->command().aid());
db->addAnime(next);
else
db->setAnime(next);
- db->commit();
// my values obtained with VoteCommand
Q_ASSERT(reply);
reply->deleteLater();
+ RaiiTransaction t(db);
+ t.commit();
+
if (!success)
+ {
+ PendingRequest r;
+ r.eid = reply->command().eid();
+ db->pendingRequestDataError(r);
return;
+ }
- db->transaction();
Episode next = db->getEpisode(reply->command().eid());
bool isNew = !next.eid;
db->addEpisode(next);
else
db->setEpisode(next);
- db->commit();
// Obtain my values
VoteReply *voteReply = Client::instance()->send(VoteCommand(VoteCommand::AnimeVote, next.aid, VoteCommand::Retrieve, reply->epnoAsInt()));
Q_ASSERT(reply);
reply->deleteLater();
+ RaiiTransaction t(db);
+ t.commit();
+
if (!success)
+ {
+ PendingRequest r;
+
+ if (reply->command().fid())
+ {
+ r.fid = reply->command().fid();
+ }
+ else if (!reply->command().ed2k().isEmpty())
+ {
+ r.ed2k = reply->command().ed2k();
+ r.size = reply->command().size();
+ }
+ else
+ {
+ Q_ASSERT_X(false, "Request Handler", "Filerequest with no fid/ed2k&size");
+ }
+
+ db->pendingRequestDataError(r);
return;
+ }
- db->transaction();
// Fid might not be known in command
File next = db->getFile(reply->fid());
}
}
- db->commit();
-
if (addedNewRequest)
emit batchFinished();
Q_ASSERT(reply);
reply->deleteLater();
+ RaiiTransaction t(db);
+ t.commit();
+
if (!success)
+ {
+ PendingRequest r;
+ r.fid = reply->command().fid();
+ db->pendingRequestDataError(r);
return;
+ }
- db->transaction();
-
+ // TODO is this if necessary?
if (reply->command().fid())
{
File f = db->getFile(reply->command().fid());