Esempio n. 1
0
QList<Cue*> CueDAO::getCuesForTrack(const int trackId) const {
    //qDebug() << "CueDAO::getCuesForTrack" << QThread::currentThread() << m_database.connectionName();
    QList<Cue*> cues;
    QSqlQuery query(m_database);
    query.prepare("SELECT * FROM " CUE_TABLE " WHERE track_id = :id");
    query.bindValue(":id", trackId);
    if (query.exec()) {
        while (query.next()) {
            Cue* cue = NULL;
            int cueId = query.value(query.record().indexOf("id")).toInt();
            if (m_cues.contains(cueId)) {
                cue = m_cues[cueId];
            }
            if (cue == NULL) {
                cue = cueFromRow(query);
            }
            if (cue != NULL) {
                cues.push_back(cue);
            }
        }
    } else {
        LOG_FAILED_QUERY(query);
    }
    return cues;
}
Esempio n. 2
0
Cue* CueDAO::getCue(const int cueId) {
    qDebug() << "CueDAO::getCue" << QThread::currentThread() << m_database.connectionName();
    if (m_cues.contains(cueId)) {
        return m_cues[cueId];
    }

    QSqlQuery query(m_database);
    query.prepare("SELECT * FROM " CUE_TABLE " WHERE id = :id");
    query.bindValue(":id", cueId);
    if (query.exec()) {
        if (query.next()) {
            return cueFromRow(query);
        }
    } else {
        LOG_FAILED_QUERY(query);
    }
    return NULL;
}
Esempio n. 3
0
QList<Cue*> CueDAO::getCuesForTrack(const int trackId) const {
    //qDebug() << "CueDAO::getCuesForTrack" << QThread::currentThread() << m_database.connectionName();
    QList<Cue*> cues;
    // A hash from hotcue index to cue id and cue*, used to detect if more
    // than one cue has been assigned to a single hotcue id.
    QMap<int, QPair<int, Cue*> > dupe_hotcues;

    QSqlQuery query(m_database);
    query.prepare("SELECT * FROM " CUE_TABLE " WHERE track_id = :id");
    query.bindValue(":id", trackId);
    if (query.exec()) {
        const int idColumn = query.record().indexOf("id");
        const int hotcueIdColumn = query.record().indexOf("hotcue");
        while (query.next()) {
            Cue* cue = NULL;
            int cueId = query.value(idColumn).toInt();
            if (m_cues.contains(cueId)) {
                cue = m_cues[cueId];
            }
            if (cue == NULL) {
                cue = cueFromRow(query);
            }
            int hotcueId = query.value(hotcueIdColumn).toInt();
            if (hotcueId != -1) {
                if (dupe_hotcues.contains(hotcueId)) {
                    m_cues.remove(dupe_hotcues[hotcueId].first);
                    cues.removeOne(dupe_hotcues[hotcueId].second);
                }
                dupe_hotcues[hotcueId] = qMakePair(cueId, cue);
            }
            if (cue != NULL) {
                cues.push_back(cue);
            }
        }
    } else {
        LOG_FAILED_QUERY(query);
    }
    return cues;
}