111
111
return libraryTrackId;
114
QList<int> TrackDAO::getTrackIds(QList<QFileInfo> files) {
115
QStringList pathList;
116
FieldEscaper escaper(m_database);
117
foreach (QFileInfo file, files) {
118
pathList << escaper.escapeString(file.absoluteFilePath());
120
QSqlQuery query(m_database);
121
query.prepare(QString("SELECT library.id FROM library INNER JOIN "
122
"track_locations ON library.location = track_locations.id "
123
"WHERE track_locations.location in (%1)").arg(pathList.join(",")));
126
LOG_FAILED_QUERY(query);
130
while (query.next()) {
131
ids.append(query.value(query.record().indexOf("id")).toInt());
114
137
// Some code (eg. drag and drop) needs to just get a track's location, and it's
115
138
// not worth retrieving a whole TrackInfoObject.
116
139
QString TrackDAO::getTrackLocation(int trackId) {
118
141
<< QThread::currentThread() << m_database.connectionName();
119
142
QSqlQuery query(m_database);
120
143
QString trackLocation = "";
121
query.prepare("SELECT track_locations.location FROM track_locations INNER JOIN library ON library.location = track_locations.id WHERE library.id=:id");
144
query.prepare("SELECT track_locations.location FROM track_locations "
145
"INNER JOIN library ON library.location = track_locations.id "
146
"WHERE library.id=:id");
122
147
query.bindValue(":id", trackId);
123
148
if (!query.exec()) {
124
149
LOG_FAILED_QUERY(query);
289
314
m_pQueryLibraryInsert->bindValue(":header_parsed", pTrack->getHeaderParsed() ? 1 : 0);
291
316
const QByteArray* pBeatsBlob = NULL;
292
QString blobVersion = "";
317
QString beatsVersion = "";
318
QString beatsSubVersion = "";
293
319
BeatsPointer pBeats = pTrack->getBeats();
294
320
// Fall back on cached BPM
295
321
double dBpm = pTrack->getBpm();
298
324
pBeatsBlob = pBeats->toByteArray();
299
blobVersion = pBeats->getVersion();
325
beatsVersion = pBeats->getVersion();
326
beatsSubVersion = pBeats->getSubVersion();
300
327
dBpm = pBeats->getBpm();
303
330
m_pQueryLibraryInsert->bindValue(":bpm", dBpm);
304
m_pQueryLibraryInsert->bindValue(":beats_version", blobVersion);
331
m_pQueryLibraryInsert->bindValue(":beats_version", beatsVersion);
332
m_pQueryLibraryInsert->bindValue(":beats_sub_version", beatsSubVersion);
305
333
m_pQueryLibraryInsert->bindValue(":beats", pBeatsBlob ? *pBeatsBlob : QVariant(QVariant::ByteArray));
306
334
delete pBeatsBlob;
498
526
addTracksFinish();
501
QList<int> TrackDAO::addTracks(QList<QFileInfo> fileInfoList, bool unremove) {
529
QList<int> TrackDAO::addTracks(const QList<QFileInfo> &fileInfoList,
531
QSqlQuery query(m_database);
502
532
QList<int> trackIDs;
503
TrackInfoObject* pTrack;
534
// Create a temporary database of the paths of all the imported tracks.
535
query.prepare("CREATE TEMP TABLE playlist_import "
536
"(location varchar (512))");
538
LOG_FAILED_QUERY(query);
542
// Prepare to add tracks to the database.
543
// This also begins an SQL transaction.
505
544
addTracksPrepare();
507
//create the list of TrackInfoObjects from the fileInfoList
508
QMutableListIterator<QFileInfo> it(fileInfoList);
509
while (it.hasNext()) {
510
QFileInfo& info = it.next();
511
pTrack = new TrackInfoObject(info);
546
// All all the track paths to this database.
547
query.prepare("INSERT INTO playlist_import (location) "
548
"VALUES (:location)");
549
foreach (const QFileInfo &rFileInfo, fileInfoList) {
550
query.bindValue(":location", rFileInfo.absoluteFilePath());
552
LOG_FAILED_QUERY(query);
556
query.prepare("SELECT library.id FROM playlist_import, "
557
"track_locations, library WHERE library.location = track_locations.id "
558
"AND playlist_import.location = track_locations.location");
560
LOG_FAILED_QUERY(query);
562
while (query.next()) {
563
int trackId = query.value(query.record().indexOf("id")).toInt();
564
trackIDs.append(trackId);
567
// If imported-playlist tracks are to be unremoved, do that for all playlist
568
// tracks that were already in the database.
570
QStringList idStringList;
571
foreach (int id, trackIDs) {
572
idStringList.append(QString::number(id));
574
query.prepare(QString("UPDATE library SET mixxx_deleted=0 "
575
"WHERE id in (%1) AND mixxx_deleted=1")
576
.arg(idStringList.join (",")));
578
LOG_FAILED_QUERY(query);
582
// Any tracks not already in the database need to be added.
583
query.prepare("SELECT location FROM playlist_import "
584
"WHERE NOT EXISTS (SELECT location FROM track_locations "
585
"WHERE playlist_import.location = track_locations.location)");
587
LOG_FAILED_QUERY(query);
589
while (query.next()) {
590
QString filePath = query.value(query.record().indexOf("location")).toString();
591
TrackInfoObject* pTrack = new TrackInfoObject(QFileInfo(filePath));
512
592
addTracksAdd(pTrack, unremove);
513
593
int trackID = pTrack->getId();
514
594
if (trackID >= 0) {