~keithsalisbury/mixxx/mixxx

« back to all changes in this revision

Viewing changes to mixxx/src/library/dao/trackdao.cpp

  • Committer: Keith Salisbury
  • Date: 2012-05-06 13:44:20 UTC
  • mfrom: (2994.1.100 mixxx-trunk)
  • Revision ID: keithsalisbury@gmail.com-20120506134420-8k1dqq10aqmx0ecq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
358
358
    QSqlQuery track_lookup(m_database);
359
359
    // Mapping of track library record id to mixxx_deleted field.
360
360
    QHash<int, QPair<int, bool> > tracksPresent;
361
 
    track_lookup.prepare("SELECT location, id, mixxx_deleted from library WHERE location IN (" +
362
 
                         trackLocationIds.join(",")+ ")");
 
361
    track_lookup.prepare(
 
362
        QString("SELECT location, id, mixxx_deleted from library WHERE location IN (%1)")
 
363
        .arg(trackLocationIds.join(",")));
 
364
 
363
365
    if (!track_lookup.exec()) {
364
366
        LOG_FAILED_QUERY(track_lookup)
365
367
                << "Failed to lookup existing tracks:";
456
458
    return trackId;
457
459
}
458
460
 
 
461
QList<int> TrackDAO::addTracks(QList<QFileInfo> fileInfoList, bool unremove) {
 
462
    QList<int> trackIDs;
 
463
 
 
464
    //create the list of TrackInfoObjects from the fileInfoList
 
465
    QList<TrackInfoObject*> pTrackList;
 
466
    QMutableListIterator<QFileInfo> it(fileInfoList);
 
467
    while (it.hasNext()) {
 
468
        QFileInfo& info = it.next();
 
469
        pTrackList.append(new TrackInfoObject(info));
 
470
    }
 
471
 
 
472
    addTracks(pTrackList, unremove);
 
473
 
 
474
    foreach (TrackInfoObject* pTrack, pTrackList) {
 
475
        int trackID = pTrack->getId();
 
476
        if (trackID >= 0) {
 
477
            trackIDs.append(trackID);
 
478
        }
 
479
        delete pTrack;
 
480
    }
 
481
    return trackIDs;
 
482
}
 
483
 
459
484
int TrackDAO::addTrack(QString absoluteFilePath, bool unremove)
460
485
{
461
486
    QFileInfo fileInfo(absoluteFilePath);
492
517
}
493
518
 
494
519
void TrackDAO::removeTracks(QList<int> ids) {
495
 
    QString idList = "";
496
 
 
 
520
    QStringList idList;
497
521
    foreach (int id, ids) {
498
 
        idList.append(QString("%1,").arg(id));
499
 
    }
500
 
 
501
 
    // Strip the last ,
502
 
    if (idList.count() > 0) {
503
 
        idList.truncate(idList.count() - 1);
 
522
        idList.append(QString::number(id));
504
523
    }
505
524
 
506
525
    QSqlQuery query(m_database);
507
 
    query.prepare(QString("UPDATE library SET mixxx_deleted=1 WHERE id in (%1)").arg(idList));
 
526
    query.prepare(QString("UPDATE library SET mixxx_deleted=1 WHERE id in (%1)")
 
527
                  .arg(idList.join(",")));
508
528
    if (!query.exec()) {
509
529
        LOG_FAILED_QUERY(query);
510
530
    }
525
545
    QSqlQuery query(m_database);
526
546
    query.prepare("UPDATE library "
527
547
                  "SET mixxx_deleted=0 "
528
 
                  "WHERE id = " + QString("%1").arg(trackId));
 
548
                  "WHERE id = " + QString::number(trackId));
529
549
    if (!query.exec()) {
530
550
        LOG_FAILED_QUERY(query)
531
551
                << "Failed to set track" << trackId << "as undeleted";
709
729
        "FROM Library "
710
730
        "INNER JOIN track_locations "
711
731
            "ON library.location = track_locations.id "
712
 
        "WHERE library.id=" + QString("%1").arg(id)
713
 
    );
 
732
        "WHERE library.id=:track_id");
 
733
    query.bindValue(":track_id", id);
714
734
 
715
735
    TrackPointer pTrack;
716
736
 
752
772
                  "channels=:channels, header_parsed=:header_parsed, "
753
773
                  "beats_version=:beats_version, beats_sub_version=:beats_sub_version, beats=:beats, "
754
774
                  "bpm_lock=:bpm_lock "
755
 
                  "WHERE id="+QString("%1").arg(trackId));
 
775
                  "WHERE id=:track_id");
756
776
    query.bindValue(":artist", pTrack->getArtist());
757
777
    query.bindValue(":title", pTrack->getTitle());
758
778
    query.bindValue(":album", pTrack->getAlbum());
776
796
    query.bindValue(":channels", pTrack->getChannels());
777
797
    query.bindValue(":header_parsed", pTrack->getHeaderParsed() ? 1 : 0);
778
798
    //query.bindValue(":location", pTrack->getLocation());
 
799
    query.bindValue(":track_id", trackId);
779
800
 
780
801
    query.bindValue(":bpm_lock", pTrack->hasBpmLock() ? 1 : 0);
781
802
 
856
877
    }
857
878
}
858
879
 
859
 
void TrackDAO::markTracksInDirectoryAsVerified(QString directory) {
 
880
void TrackDAO::markTracksInDirectoriesAsVerified(QStringList directories) {
860
881
    //qDebug() << "TrackDAO::markTracksInDirectoryAsVerified" << QThread::currentThread() << m_database.connectionName();
861
882
    //qDebug() << "markTracksInDirectoryAsVerified()" << directory;
862
883
 
 
884
    FieldEscaper escaper(m_database);
 
885
    QMutableStringListIterator it(directories);
 
886
    while (it.hasNext()) {
 
887
        it.setValue(escaper.escapeString(it.next()));
 
888
    }
 
889
 
863
890
    QSqlQuery query(m_database);
864
 
    query.prepare("UPDATE track_locations "
865
 
                  "SET needs_verification=0 "
866
 
                  "WHERE directory=:directory");
867
 
    query.bindValue(":directory", directory);
 
891
    query.prepare(
 
892
        QString("UPDATE track_locations "
 
893
                "SET needs_verification=0 "
 
894
                "WHERE directory IN (%1)").arg(directories.join(",")));
868
895
    if (!query.exec()) {
869
896
        LOG_FAILED_QUERY(query)
870
 
                << "Couldn't mark tracks in" << directory << " as verified.";
 
897
                << "Couldn't mark tracks in" << directories.size() << "directories as verified.";
871
898
    }
872
899
}
873
900