1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
5
* Tomahawk is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Tomahawk is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
19
#include "DatabaseCommand_SetTrackAttributes.h"
20
#include "TomahawkSqlQuery.h"
21
#include "DatabaseImpl.h"
23
#include "utils/Logger.h"
25
using namespace Tomahawk;
27
DatabaseCommand_SetTrackAttributes::DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::AttributeType type, QList< QPair< QID, QString > > ids, bool toDelete )
28
: DatabaseCommandLoggable()
30
, m_delete( toDelete )
36
DatabaseCommand_SetTrackAttributes::DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::AttributeType type )
37
: DatabaseCommandLoggable()
47
DatabaseCommand_SetTrackAttributes::exec( DatabaseImpl* dbi )
49
TomahawkSqlQuery checkquery = dbi->newquery();
50
TomahawkSqlQuery delquery = dbi->newquery();
51
TomahawkSqlQuery insertquery = dbi->newquery();
56
case EchonestCatalogId:
57
k = "echonestcatalogid";
61
if ( m_delete && m_tracks.isEmpty() )
64
TomahawkSqlQuery delAll = dbi->newquery();
65
delAll.prepare( "DELETE FROM track_attributes WHERE k = ?" );
66
delAll.bindValue( 0, k );
71
checkquery.prepare( "SELECT id, sortname FROM track WHERE id = ?" );
72
delquery.prepare( "DELETE FROM track_attributes WHERE id = ? AND k = ?" );
73
insertquery.prepare( "INSERT INTO track_attributes ( id, k, v ) VALUES( ?, ?, ? )" );
75
QPair< QID, QString > track;
76
foreach ( track, m_tracks )
78
checkquery.bindValue( 0, track.first );
79
if ( !checkquery.exec() )
81
tLog() << "No track in track table for set track attribute command...aborting:" << track.first;
85
delquery.bindValue( 0, track.first );
86
delquery.bindValue( 1, k );
90
continue; // stop at deleting, don't insert
92
insertquery.bindValue( 0, track.first );
93
insertquery.bindValue( 1, k );
94
insertquery.bindValue( 2, track.second );
95
if ( !insertquery.exec() )
96
tLog() << "Failed to insert track attribute:" << k << track.first << track.second;