]> Some of my projects - localmylist.git/commitdiff
Add new fields that were added to the schema to the database classes
authorAPTX <marek321@gmail.com>
Tue, 9 Apr 2013 12:57:12 +0000 (14:57 +0200)
committerAPTX <marek321@gmail.com>
Tue, 9 Apr 2013 12:57:12 +0000 (14:57 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/databaseclasses.cpp
localmylist/databaseclasses.h

index cf454a6ee0c651dd294e89af35d3ca727ac9fa79..e027f3c99b6040bd6555fbac6679ebd1a4efa456 100644 (file)
@@ -442,9 +442,9 @@ File Database::getFile(int fid)
        File f;
 
        QSqlQuery &q = prepare(
-       "SELECT fid, eid, aid, gid, entry_added, anidb_update, entry_update, my_update, "
+       "SELECT fid, eid, aid, gid, lid, entry_added, anidb_update, entry_update, my_update, "
        "               ed2k, size, length, extension, group_name, group_name_short, crc, "
-       "               release_date, version, censored, source, quality_id, quality, resolution, "
+       "               release_date, version, censored, deprecated, source, quality_id, quality, resolution, "
        "               video_codec, audio_codec, audio_language, subtitle_language, aspect_ratio, "
        "               my_watched, my_state, my_file_state, my_storage, my_source, my_other "
        "       FROM file "
@@ -456,7 +456,10 @@ File Database::getFile(int fid)
                return f;
 
        if (q.next())
-               f = readFile(q);
+       {
+               QSqlResultIterator it(q);
+               readFileData(it, f);
+       }
 
        q.finish();
 
@@ -615,12 +618,12 @@ bool Database::setFile(const File &file)
 {
        QSqlQuery &q = prepare(
        "UPDATE file SET "
-       "               eid = :eid, aid = :aid, gid = :gid, anidb_update = :anidbUpdate, "
+       "               eid = :eid, aid = :aid, gid = :gid, lid = :lid, anidb_update = :anidbUpdate, "
        "               entry_update = :entryUpdate, my_update = :myUpdate, "
        "               ed2k = :ed2k, size = :size, length = :length, extension = :extension, "
        "               group_name = :groupName, group_name_short = :groupNameShort, crc = :crc, "
        "               release_date = :releaseDate, version = :version, censored = :censored, "
-       "               source = :source, quality_id = :qualityId, quality = :quality, "
+       "               deprecated = :deprecated, source = :source, quality_id = :qualityId, quality = :quality, "
        "               resolution = :resolution, video_codec = :videoCodec, "
        "               audio_codec = :audioCodec, audio_language = :audioLanguage, "
        "               subtitle_language = :subtitleLanguage, aspect_ratio = :aspectRatio, "
@@ -632,6 +635,7 @@ bool Database::setFile(const File &file)
        q.bindValue(":eid", file.eid);
        q.bindValue(":aid", file.aid);
        q.bindValue(":gid", file.gid);
+       q.bindValue(":lid", file.lid);
        q.bindValue(":anidbUpdate", file.anidbUpdate);
        q.bindValue(":entryUpdate", file.entryUpdate);
        q.bindValue(":myUpdate", file.myUpdate);
@@ -645,6 +649,7 @@ bool Database::setFile(const File &file)
        q.bindValue(":releaseDate", file.releaseDate);
        q.bindValue(":version", file.version);
        q.bindValue(":censored", file.censored);
+       q.bindValue(":deprecated", file.deprecated);
        q.bindValue(":source", file.source);
        q.bindValue(":qualityId", file.qualityId);
        q.bindValue(":quality", file.quality);
@@ -754,7 +759,7 @@ bool Database::addFile(const File &file)
        q.bindValue(":eid", file.eid);
        q.bindValue(":aid", file.aid);
        q.bindValue(":gid", file.gid);
-       q.bindValue(":lid", 0);
+       q.bindValue(":lid", file.lid);
        q.bindValue(":anidbUpdate", file.anidbUpdate);
        q.bindValue(":entryUpdate", file.entryUpdate);
        q.bindValue(":myUpdate", file.myUpdate);
@@ -768,7 +773,7 @@ bool Database::addFile(const File &file)
        q.bindValue(":releaseDate", file.releaseDate);
        q.bindValue(":version", file.version);
        q.bindValue(":censored", file.censored);
-       q.bindValue(":deprecated", false);
+       q.bindValue(":deprecated", file.deprecated);
        q.bindValue(":source", file.source);
        q.bindValue(":qualityId", file.qualityId);
        q.bindValue(":quality", file.quality);
@@ -954,10 +959,10 @@ bool Database::addPendingMyListUpdate(const PendingMyListUpdate &request)
        "               DEFAULT, DEFAULT, DEFAULT, DEFAULT) ");
 
        q.bindValue(":fid", request.fid);
-       q.bindValue(":aid", 0);
-       q.bindValue(":epno", 0);
-       q.bindValue(":epmin", 0);
-       q.bindValue(":eptype", "");
+       q.bindValue(":aid", request.aid);
+       q.bindValue(":epno", request.epno);
+       q.bindValue(":epmin", request.epmin);
+       q.bindValue(":eptype", request.eptype.isNull() ? "" : request.eptype);
        q.bindValue(":setMyWatched", request.setMyWatched);
        q.bindValue(":myWatched", request.myWatched);
        q.bindValue(":setMyState", request.setMyState);
@@ -970,8 +975,8 @@ bool Database::addPendingMyListUpdate(const PendingMyListUpdate &request)
        q.bindValue(":mySource", request.mySource);
        q.bindValue(":setMyOther", request.setMyOther);
        q.bindValue(":myOther", request.myOther);
-       q.bindValue(":setVote", false);
-       q.bindValue(":vote", 0);
+       q.bindValue(":setVote", request.setVote);
+       q.bindValue(":vote", request.vote);
 
        return exec(q);
 }
@@ -979,9 +984,9 @@ bool Database::addPendingMyListUpdate(const PendingMyListUpdate &request)
 PendingMyListUpdate Database::getPendingMyListUpdate(qint64 updateId)
 {
        QSqlQuery &q = prepare(
-       "SELECT update_id, fid, set_my_watched, my_watched, set_my_state, my_state, "
+       "SELECT update_id, fid, aid, epno, epmin, eptype, set_my_watched, my_watched, set_my_state, my_state, "
        "               set_my_file_state, my_file_state, set_my_storage, my_storage, set_my_source, "
-       "               my_source, set_my_other, my_other, added, started, finished "
+       "               my_source, set_my_other, my_other, set_vote, vote, added, started, finished "
        "       FROM pending_mylist_update "
        "       WHERE update_id = :updateId ");
 
@@ -994,22 +999,8 @@ PendingMyListUpdate Database::getPendingMyListUpdate(qint64 updateId)
 
        if (q.next())
        {
-               request.updateId = q.value(0).toLongLong();
-               request.fid = q.value(1).toInt();
-               request.setMyWatched = q.value(2).toBool();
-               request.myWatched = q.value(3).toDateTime();
-               request.setMyState = q.value(4).toBool();
-               request.myState = q.value(5).toInt();
-               request.setMyFileState = q.value(6).toBool();
-               request.myFileState = q.value(7).toInt();
-               request.setMyStorage = q.value(8).toBool();
-               request.myStorage = q.value(9).toString();
-               request.setMySource = q.value(10).toBool();
-               request.mySource = q.value(11).toString();
-               request.setMyOther = q.value(12).toBool();
-               request.myOther = q.value(13).toString();
-               request.added = q.value(14).toDateTime();
-               request.started = q.value(15).toDateTime();
+               QSqlResultIterator it(q);
+               readPendingMyListUpdateData(it, request);
        }
 
        q.finish();
@@ -1026,9 +1017,9 @@ QList<PendingMyListUpdate> Database::getPendingMyListUpdateBatch(int limit)
        "                       WHERE started IS NULL "
        "                       ORDER BY added ASC "
        "                       LIMIT :limit) "
-       "       RETURNING update_id, fid, set_my_watched, my_watched, set_my_state, "
+       "       RETURNING update_id, fid, aid, epno, epmin, eptype, set_my_watched, my_watched, set_my_state, "
        "               my_state, set_my_file_state, my_file_state, set_my_storage, my_storage, "
-       "               set_my_source, my_source, set_my_other, my_other, added, started ");
+       "               set_my_source, my_source, set_my_other, my_other, set_vote, vote, added, started, finished ");
 
        q.bindValue(":limit", limit);
 
@@ -1040,22 +1031,8 @@ QList<PendingMyListUpdate> Database::getPendingMyListUpdateBatch(int limit)
        while (q.next())
        {
                PendingMyListUpdate request;
-               request.updateId = q.value(0).toLongLong();
-               request.fid = q.value(1).toInt();
-               request.setMyWatched = q.value(2).toBool();
-               request.myWatched = q.value(3).toDateTime();
-               request.setMyState = q.value(4).toBool();
-               request.myState = q.value(5).toInt();
-               request.setMyFileState = q.value(6).toBool();
-               request.myFileState = q.value(7).toInt();
-               request.setMyStorage = q.value(8).toBool();
-               request.myStorage = q.value(9).toString();
-               request.setMySource = q.value(10).toBool();
-               request.mySource = q.value(11).toString();
-               request.setMyOther = q.value(12).toBool();
-               request.myOther = q.value(13).toString();
-               request.added = q.value(14).toDateTime();
-               request.started = q.value(15).toDateTime();
+               QSqlResultIterator it(q);
+               readPendingMyListUpdateData(it, request);
                ret << request;
        }
 
@@ -1410,6 +1387,7 @@ void Database::readFileData(SqlResultIteratorInterface &result, File &data, int
        data.eid = result.value(offset++).toInt();
        data.aid = result.value(offset++).toInt();
        data.gid = result.value(offset++).toInt();
+       data.lid = result.value(offset++).toInt();
        data.entryAdded = result.value(offset++).toDateTime();
        data.anidbUpdate = result.value(offset++).toDateTime();
        data.entryUpdate = result.value(offset++).toDateTime();
@@ -1424,6 +1402,7 @@ void Database::readFileData(SqlResultIteratorInterface &result, File &data, int
        data.releaseDate = result.value(offset++).toDateTime();
        data.version = result.value(offset++).toInt();
        data.censored = result.value(offset++).toBool();
+       data.deprecated = result.value(offset++).toBool();
        data.source = result.value(offset++).toString();
        data.qualityId = result.value(offset++).toInt();
        data.quality = result.value(offset++).toString();
@@ -1468,6 +1447,32 @@ void Database::readUnknownFileData(SqlResultIteratorInterface &result, UnknownFi
        data.path = result.value(offset++).toString();
 }
 
+void Database::readPendingMyListUpdateData(SqlResultIteratorInterface &query, PendingMyListUpdate &data, int offset)
+{
+       data.updateId = query.value(offset++).toLongLong();
+       data.fid = query.value(offset++).toInt();
+       data.aid = query.value(offset++).toInt();
+       data.epno = query.value(offset++).toInt();
+       data.epmin = query.value(offset++).toInt();
+       data.eptype = query.value(offset++).toString();
+       data.setMyWatched = query.value(offset++).toBool();
+       data.myWatched = query.value(offset++).toDateTime();
+       data.setMyState = query.value(offset++).toBool();
+       data.myState = query.value(offset++).toInt();
+       data.setMyFileState = query.value(offset++).toBool();
+       data.myFileState = query.value(offset++).toInt();
+       data.setMyStorage = query.value(offset++).toBool();
+       data.myStorage = query.value(offset++).toString();
+       data.setMySource = query.value(offset++).toBool();
+       data.mySource = query.value(offset++).toString();
+       data.setMyOther = query.value(offset++).toBool();
+       data.myOther = query.value(offset++).toString();
+       data.setVote = query.value(offset++).toBool();
+       data.vote = query.value(offset++).toDouble();
+       data.added = query.value(offset++).toDateTime();
+       data.started = query.value(offset++).toDateTime();
+}
+
 QString Database::animeFields()
 {
        return
@@ -1489,9 +1494,9 @@ QString Database::episodeFields()
 QString Database::fileFields()
 {
        return
-       "f.fid, f.eid, f.aid, f.gid, f.entry_added, f.anidb_update, f.entry_update, f.my_update, "
+       "f.fid, f.eid, f.aid, f.gid, f.lid, f.entry_added, f.anidb_update, f.entry_update, f.my_update, "
        "f.ed2k, f.size, f.length, f.extension, f.group_name, f.group_name_short, f.crc, "
-       "f.release_date, f.version, f.censored, f.source, f.quality_id, f.quality, f.resolution, "
+       "f.release_date, f.version, f.censored, f.deprecated, f.source, f.quality_id, f.quality, f.resolution, "
        "f.video_codec, f.audio_codec, f.audio_language, f.subtitle_language, f.aspect_ratio, "
        "f.my_watched, f.my_state, f.my_file_state, f.my_storage, f.my_source, f.my_other ";
 }
@@ -1502,6 +1507,11 @@ QString Database::fileLocationFields()
        "fl.location_id, fl.fid, fl.host_id, fl.path, fl.renamed, fl.failed_rename ";
 }
 
+QString Database::pendingMyListUpdateFields()
+{
+       return "";
+}
+
 void Database::subscribeToNotifications()
 {
        d->db.driver()->subscribeToNotification("new_pending_request");
index bcc14c0370863c51e50294cad477e8d7a9d7ec45..71969ff3c0ec5e591e668857e136e20e4e4dedd3 100644 (file)
@@ -140,11 +140,13 @@ public slots:
        static void readFileLocationData(SqlResultIteratorInterface &result, FileLocation &data, int offset = 0);
        static void readOpenFileData(SqlResultIteratorInterface &result, OpenFileData &data, int offset = 0);
        static void readUnknownFileData(SqlResultIteratorInterface &result, UnknownFile &data, int offset = 0);
+       static void readPendingMyListUpdateData(SqlResultIteratorInterface &result, PendingMyListUpdate &data, int offset = 0);
 
        static QString animeFields();
        static QString episodeFields();
        static QString fileFields();
        static QString fileLocationFields();
+       static QString pendingMyListUpdateFields();
 
 signals:
        void connected();
index 831e8509e10630289791d5836a666b1febe6a0b8..cce522f3f59094bd48bf247fc5b92c79ea0c1db8 100644 (file)
@@ -44,10 +44,12 @@ File::File()
        eid = 0;
        aid = 0;
        gid = 0;
+       lid = 0;
        size = 0;
        length = 0;
        version = 1;
        censored = false;
+       deprecated = false;
        qualityId = 0;
        myState = 0;
        myFileState = 0;
@@ -58,6 +60,7 @@ FileLocation::FileLocation()
        locationId = 0;
        fid = 0;
        hostId = 0;
+       renameDisabled = false;
        failedRename = false;
 }
 
@@ -87,6 +90,9 @@ PendingRequest::PendingRequest()
 PendingMyListUpdate::PendingMyListUpdate()
 {
        fid = 0;
+       aid = 0;
+       epno = 0;
+       epmin = 0;
        myState = 0;
        myFileState = 0;
        setMyWatched = false;
@@ -95,6 +101,8 @@ PendingMyListUpdate::PendingMyListUpdate()
        setMyStorage = false;
        setMySource = false;
        setMyOther = false;
+       setVote = false;
+       vote = 0;
 }
 
 HostInfo::HostInfo()
index 23f1f27e291f28b785f974ea7410294cd0c05665..daddc02cff8ec83a180e5fee1be3c6ac26d0fb1c 100644 (file)
@@ -86,6 +86,7 @@ struct LOCALMYLISTSHARED_EXPORT File
        int eid;
        int aid;
        int gid;
+       int lid;
        QDateTime entryAdded;
        QDateTime anidbUpdate;
        QDateTime entryUpdate;
@@ -100,6 +101,7 @@ struct LOCALMYLISTSHARED_EXPORT File
        QDateTime releaseDate;
        int version;
        bool censored;
+       bool deprecated;
        QString source;
        int qualityId;
        QString quality;
@@ -125,8 +127,12 @@ struct LOCALMYLISTSHARED_EXPORT FileLocation
        int fid;
        int hostId;
        QString path;
+       bool renameDisabled;
+       QString originalName;
        QDateTime renamed;
+       QString renamePath;
        bool failedRename;
+       QString renameError;
 
        FileLocation();
 };
@@ -166,6 +172,10 @@ struct LOCALMYLISTSHARED_EXPORT PendingMyListUpdate
 {
        qint64 updateId;
        int fid;
+       int aid;
+       int epno;
+       int epmin;
+       QString eptype;
        bool setMyWatched;
        QDateTime myWatched;
        bool setMyState;
@@ -178,6 +188,8 @@ struct LOCALMYLISTSHARED_EXPORT PendingMyListUpdate
        QString mySource;
        bool setMyOther;
        QString myOther;
+       bool setVote;
+       double vote;
 
        QDateTime added;
        QDateTime started;