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