Commit 11b7de91 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Rename foreign key to XXX_id instead of id_XXX

parent b519cad1
...@@ -195,8 +195,8 @@ bool Album::setAlbumArtist( Artist* artist ) ...@@ -195,8 +195,8 @@ bool Album::setAlbumArtist( Artist* artist )
std::vector<ArtistPtr> Album::artists() const std::vector<ArtistPtr> Album::artists() const
{ {
static const std::string req = "SELECT art.* FROM " + policy::ArtistTable::Name + " art " static const std::string req = "SELECT art.* FROM " + policy::ArtistTable::Name + " art "
"LEFT JOIN AlbumArtistRelation aar ON aar.id_artist = art.id_artist " "LEFT JOIN AlbumArtistRelation aar ON aar.artist_id = art.id_artist "
"WHERE aar.id_album = ?"; "WHERE aar.album_id = ?";
return Artist::fetchAll<IArtist>( m_dbConnection, req, m_id ); return Artist::fetchAll<IArtist>( m_dbConnection, req, m_id );
} }
...@@ -213,7 +213,7 @@ bool Album::addArtist( std::shared_ptr<Artist> artist ) ...@@ -213,7 +213,7 @@ bool Album::addArtist( std::shared_ptr<Artist> artist )
bool Album::removeArtist(Artist* artist) bool Album::removeArtist(Artist* artist)
{ {
static const std::string req = "DELETE FROM AlbumArtistRelation WHERE id_album = ? " static const std::string req = "DELETE FROM AlbumArtistRelation WHERE album_id = ? "
"AND id_artist = ?"; "AND id_artist = ?";
return sqlite::Tools::executeDelete( m_dbConnection, req, m_id, artist->id() ); return sqlite::Tools::executeDelete( m_dbConnection, req, m_id, artist->id() );
} }
...@@ -235,12 +235,12 @@ bool Album::createTable(DBConnection dbConnection ) ...@@ -235,12 +235,12 @@ bool Album::createTable(DBConnection dbConnection )
+ "(id_artist) ON DELETE CASCADE" + "(id_artist) ON DELETE CASCADE"
")"; ")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS AlbumArtistRelation(" static const std::string reqRel = "CREATE TABLE IF NOT EXISTS AlbumArtistRelation("
"id_album INTEGER," "album_id INTEGER,"
"id_artist INTEGER," "artist_id INTEGER,"
"PRIMARY KEY (id_album, id_artist)," "PRIMARY KEY (album_id, artist_id),"
"FOREIGN KEY(id_album) REFERENCES " + policy::AlbumTable::Name + "(" "FOREIGN KEY(album_id) REFERENCES " + policy::AlbumTable::Name + "("
+ policy::AlbumTable::PrimaryKeyColumn + ") ON DELETE CASCADE," + policy::AlbumTable::PrimaryKeyColumn + ") ON DELETE CASCADE,"
"FOREIGN KEY(id_artist) REFERENCES " + policy::ArtistTable::Name + "(" "FOREIGN KEY(artist_id) REFERENCES " + policy::ArtistTable::Name + "("
+ policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE" + policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")"; ")";
return sqlite::Tools::executeRequest( dbConnection, req ) && return sqlite::Tools::executeRequest( dbConnection, req ) &&
......
...@@ -91,8 +91,8 @@ std::vector<MediaPtr> Artist::media() const ...@@ -91,8 +91,8 @@ std::vector<MediaPtr> Artist::media() const
if ( m_id ) if ( m_id )
{ {
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med " static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media " "LEFT JOIN MediaArtistRelation mar ON mar.media_id = med.id_media "
"WHERE mar.id_artist = ? AND med.is_present = 1"; "WHERE mar.artist_id = ? AND med.is_present = 1";
return Media::fetchAll<IMedia>( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
else else
...@@ -100,8 +100,8 @@ std::vector<MediaPtr> Artist::media() const ...@@ -100,8 +100,8 @@ std::vector<MediaPtr> Artist::media() const
// Not being able to rely on ForeignKey here makes me a saaaaad panda... // Not being able to rely on ForeignKey here makes me a saaaaad panda...
// But sqlite only accepts "IS NULL" to compare against NULL... // But sqlite only accepts "IS NULL" to compare against NULL...
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med " static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media " "LEFT JOIN MediaArtistRelation mar ON mar.media_id = med.id_media "
"WHERE mar.id_artist IS NULL"; "WHERE mar.artist_id IS NULL";
return Media::fetchAll<IMedia>( m_dbConnection, req ); return Media::fetchAll<IMedia>( m_dbConnection, req );
} }
} }
...@@ -194,12 +194,12 @@ bool Artist::createTable( DBConnection dbConnection ) ...@@ -194,12 +194,12 @@ bool Artist::createTable( DBConnection dbConnection )
"is_present BOOLEAN NOT NULL DEFAULT 1" "is_present BOOLEAN NOT NULL DEFAULT 1"
")"; ")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation(" static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
"id_media INTEGER NOT NULL," "media_id INTEGER NOT NULL,"
"id_artist INTEGER," "artist_id INTEGER,"
"PRIMARY KEY (id_media, id_artist)," "PRIMARY KEY (media_id, artist_id),"
"FOREIGN KEY(id_media) REFERENCES " + policy::MediaTable::Name + "FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name +
"(id_media) ON DELETE CASCADE," "(id_media) ON DELETE CASCADE,"
"FOREIGN KEY(id_artist) REFERENCES " + policy::ArtistTable::Name + "(" "FOREIGN KEY(artist_id) REFERENCES " + policy::ArtistTable::Name + "("
+ policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE" + policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")"; ")";
return sqlite::Tools::executeRequest( dbConnection, req ) && return sqlite::Tools::executeRequest( dbConnection, req ) &&
......
...@@ -58,8 +58,8 @@ const std::string& Label::name() const ...@@ -58,8 +58,8 @@ const std::string& Label::name() const
std::vector<MediaPtr> Label::files() std::vector<MediaPtr> Label::files()
{ {
static const std::string req = "SELECT f.* FROM " + policy::MediaTable::Name + " f " static const std::string req = "SELECT f.* FROM " + policy::MediaTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_media = f.id_media " "LEFT JOIN LabelFileRelation lfr ON lfr.media_id = f.id_media "
"WHERE lfr.id_label = ?"; "WHERE lfr.label_id = ?";
return Media::fetchAll<IMedia>( m_dbConnection, req, m_id ); return Media::fetchAll<IMedia>( m_dbConnection, req, m_id );
} }
...@@ -82,10 +82,10 @@ bool Label::createTable(DBConnection dbConnection) ...@@ -82,10 +82,10 @@ bool Label::createTable(DBConnection dbConnection)
if ( sqlite::Tools::executeRequest( dbConnection, req ) == false ) if ( sqlite::Tools::executeRequest( dbConnection, req ) == false )
return false; return false;
req = "CREATE TABLE IF NOT EXISTS LabelFileRelation(" req = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER," "label_id INTEGER,"
"id_media INTEGER," "media_id INTEGER,"
"PRIMARY KEY (id_label, id_media)," "PRIMARY KEY (label_id, media_id),"
"FOREIGN KEY(id_label) REFERENCES Label(id_label) ON DELETE CASCADE," "FOREIGN KEY(label_id) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(id_media) REFERENCES Media(id_media) ON DELETE CASCADE);"; "FOREIGN KEY(media_id) REFERENCES Media(id_media) ON DELETE CASCADE);";
return sqlite::Tools::executeRequest( dbConnection, req ); return sqlite::Tools::executeRequest( dbConnection, req );
} }
...@@ -167,8 +167,8 @@ void Media::setShowEpisode( ShowEpisodePtr showEpisode ) ...@@ -167,8 +167,8 @@ void Media::setShowEpisode( ShowEpisodePtr showEpisode )
std::vector<LabelPtr> Media::labels() std::vector<LabelPtr> Media::labels()
{ {
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l " static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label " "LEFT JOIN LabelFileRelation lfr ON lfr.label_id = l.id_label "
"WHERE lfr.id_media = ?"; "WHERE lfr.media_id = ?";
return Label::fetchAll<ILabel>( m_dbConnection, req, m_id ); return Label::fetchAll<ILabel>( m_dbConnection, req, m_id );
} }
...@@ -411,6 +411,6 @@ bool Media::removeLabel( LabelPtr label ) ...@@ -411,6 +411,6 @@ bool Media::removeLabel( LabelPtr label )
LOG_ERROR( "Can't unlink a label/file not inserted in database" ); LOG_ERROR( "Can't unlink a label/file not inserted in database" );
return false; return false;
} }
const char* req = "DELETE FROM LabelFileRelation WHERE id_label = ? AND id_media = ?"; const char* req = "DELETE FROM LabelFileRelation WHERE label_id = ? AND media_id = ?";
return sqlite::Tools::executeDelete( m_dbConnection, req, label->id(), m_id ); return sqlite::Tools::executeDelete( m_dbConnection, req, label->id(), m_id );
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment