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

Don't mark one-time requests as static

parent 21462918
......@@ -331,7 +331,7 @@ bool Album::removeArtist(Artist* artist)
bool Album::createTable(DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::AlbumTable::Name +
"("
"id_album INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -346,7 +346,7 @@ bool Album::createTable(DBConnection dbConnection )
"FOREIGN KEY( artist_id ) REFERENCES " + policy::ArtistTable::Name
+ "(id_artist) ON DELETE CASCADE"
")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS AlbumArtistRelation("
const std::string reqRel = "CREATE TABLE IF NOT EXISTS AlbumArtistRelation("
"album_id INTEGER,"
"artist_id INTEGER,"
"PRIMARY KEY (album_id, artist_id),"
......@@ -355,12 +355,12 @@ bool Album::createTable(DBConnection dbConnection )
"FOREIGN KEY(artist_id) REFERENCES " + policy::ArtistTable::Name + "("
+ policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")";
static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
+ policy::AlbumTable::Name + "Fts USING FTS3("
"title,"
"artist"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_artist_id_idx ON " +
const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_artist_id_idx ON " +
policy::AlbumTable::Name + "(artist_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, reqRel ) &&
......
......@@ -97,7 +97,7 @@ bool AlbumTrack::setArtist( std::shared_ptr<Artist> artist )
bool AlbumTrack::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id INTEGER,"
"artist_id UNSIGNED INTEGER,"
......@@ -114,12 +114,12 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
"FOREIGN KEY (album_id) REFERENCES Album(id_album) "
" ON DELETE CASCADE"
")";
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_track_present AFTER UPDATE OF is_present "
const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_track_present AFTER UPDATE OF is_present "
"ON " + policy::MediaTable::Name +
" BEGIN"
" UPDATE " + policy::AlbumTrackTable::Name + " SET is_present = new.is_present WHERE media_id = new.id_media;"
" END";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_media_artist_genre_album_idx ON " +
const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_media_artist_genre_album_idx ON " +
policy::AlbumTrackTable::Name + "(media_id, artist_id, genre_id, album_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
......
......@@ -191,7 +191,7 @@ bool Artist::setMusicBrainzId( const std::string& mbId )
bool Artist::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::ArtistTable::Name +
"("
"id_artist INTEGER PRIMARY KEY AUTOINCREMENT,"
......@@ -202,7 +202,7 @@ bool Artist::createTable( DBConnection dbConnection )
"mb_id TEXT,"
"is_present BOOLEAN NOT NULL DEFAULT 1"
")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
"media_id INTEGER NOT NULL,"
"artist_id INTEGER,"
"PRIMARY KEY (media_id, artist_id),"
......@@ -211,7 +211,7 @@ bool Artist::createTable( DBConnection dbConnection )
"FOREIGN KEY(artist_id) REFERENCES " + policy::ArtistTable::Name + "("
+ policy::ArtistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")";
static const std::string reqFts = "CREATE VIRTUAL TABLE IF NOT EXISTS " +
const std::string reqFts = "CREATE VIRTUAL TABLE IF NOT EXISTS " +
policy::ArtistTable::Name + "Fts USING FTS3("
"name"
")";
......
......@@ -100,7 +100,7 @@ const std::string& AudioTrack::description() const
bool AudioTrack::createTable( DBConnection dbConnection )
{
//FIXME: Index on media_id ? Unless it's already implied by the foreign key
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
+ "(" +
policy::AudioTrackTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
"codec TEXT,"
......@@ -113,7 +113,7 @@ bool AudioTrack::createTable( DBConnection dbConnection )
"FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name
+ "( id_media ) ON DELETE CASCADE"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS audio_track_media_idx ON " +
const std::string indexReq = "CREATE INDEX IF NOT EXISTS audio_track_media_idx ON " +
policy::AudioTrackTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
......
......@@ -95,7 +95,7 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u
bool Device::createTable(DBConnection connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::DeviceTable::Name + "("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::DeviceTable::Name + "("
"id_device INTEGER PRIMARY KEY AUTOINCREMENT,"
"uuid TEXT UNIQUE ON CONFLICT FAIL,"
"is_removable BOOLEAN,"
......
......@@ -87,22 +87,22 @@ std::vector<AlbumPtr> Genre::albums( SortingCriteria sort, bool desc ) const
bool Genre::createTable( DBConnection dbConn )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::GenreTable::Name +
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::GenreTable::Name +
"("
"id_genre INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT UNIQUE ON CONFLICT FAIL"
")";
static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
+ policy::GenreTable::Name + "Fts USING FTS3("
"name"
")";
static const std::string vtableInsertTrigger = "CREATE TRIGGER IF NOT EXISTS insert_genre_fts"
const std::string vtableInsertTrigger = "CREATE TRIGGER IF NOT EXISTS insert_genre_fts"
" AFTER INSERT ON " + policy::GenreTable::Name +
" BEGIN"
" INSERT INTO " + policy::GenreTable::Name + "Fts(rowid,name) VALUES(new.id_genre, new.name);"
" END";
static const std::string vtableDeleteTrigger = "CREATE TRIGGER IF NOT EXISTS delete_genre_fts"
const std::string vtableDeleteTrigger = "CREATE TRIGGER IF NOT EXISTS delete_genre_fts"
" BEFORE DELETE ON " + policy::GenreTable::Name +
" BEGIN"
" DELETE FROM " + policy::GenreTable::Name + "Fts WHERE rowid = old.id_genre;"
......
......@@ -51,14 +51,14 @@ History::History( MediaLibraryPtr ml, sqlite::Row& row )
bool History::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::HistoryTable::Name +
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::HistoryTable::Name +
"("
"id_record INTEGER PRIMARY KEY AUTOINCREMENT,"
"mrl TEXT UNIQUE ON CONFLICT FAIL,"
"insertion_date UNSIGNED INT NOT NULL DEFAULT (strftime('%s', 'now')),"
"favorite BOOLEAN NOT NULL DEFAULT 0"
")";
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS limit_nb_records AFTER INSERT ON "
const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS limit_nb_records AFTER INSERT ON "
+ policy::HistoryTable::Name +
" BEGIN "
"DELETE FROM " + policy::HistoryTable::Name + " WHERE id_record in "
......
......@@ -82,17 +82,17 @@ LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name )
bool Label::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
"name TEXT UNIQUE ON CONFLICT FAIL"
")";
static const std::string relReq = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
const std::string relReq = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"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);";
static const std::string ftsTrigger = "CREATE TRIGGER IF NOT EXISTS delete_label_fts "
const std::string ftsTrigger = "CREATE TRIGGER IF NOT EXISTS delete_label_fts "
"BEFORE DELETE ON " + policy::LabelTable::Name +
" BEGIN"
" UPDATE " + policy::MediaTable::Name + "Fts SET labels = TRIM(REPLACE(labels, old.name, ''))"
......
......@@ -451,9 +451,9 @@ bool Media::createTable( DBConnection connection )
"is_favorite BOOLEAN NOT NULL DEFAULT 0,"
"is_present BOOLEAN NOT NULL DEFAULT 1"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS index_last_played_date ON "
const std::string indexReq = "CREATE INDEX IF NOT EXISTS index_last_played_date ON "
+ policy::MediaTable::Name + "(last_played_date DESC)";
static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
+ policy::MediaTable::Name + "Fts USING FTS3("
"title,"
"labels"
......
......@@ -118,7 +118,7 @@ std::vector<MediaPtr> Movie::files()
bool Movie::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MovieTable::Name
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MovieTable::Name
+ "("
"id_movie INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id UNSIGNED INTEGER NOT NULL,"
......@@ -129,7 +129,7 @@ bool Movie::createTable( DBConnection dbConnection )
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS movie_media_idx ON " +
const std::string indexReq = "CREATE INDEX IF NOT EXISTS movie_media_idx ON " +
policy::MovieTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
......
......@@ -145,12 +145,12 @@ bool Playlist::remove( int64_t mediaId )
bool Playlist::createTable( DBConnection dbConn )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT UNIQUE,"
"creation_date UNSIGNED INT NOT NULL"
")";
static const std::string relTableReq = "CREATE TABLE IF NOT EXISTS PlaylistMediaRelation("
const std::string relTableReq = "CREATE TABLE IF NOT EXISTS PlaylistMediaRelation("
"media_id INTEGER,"
"playlist_id INTEGER,"
"position INTEGER,"
......@@ -160,7 +160,7 @@ bool Playlist::createTable( DBConnection dbConn )
"FOREIGN KEY(playlist_id) REFERENCES " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + ") ON DELETE CASCADE"
")";
static const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
const std::string vtableReq = "CREATE VIRTUAL TABLE IF NOT EXISTS "
+ policy::PlaylistTable::Name + "Fts USING FTS3("
"name"
")";
......
......@@ -108,7 +108,7 @@ std::shared_ptr<VideoTrack> VideoTrack::create( MediaLibraryPtr ml, const std::s
bool VideoTrack::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::VideoTrackTable::Name
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::VideoTrackTable::Name
+ "(" +
policy::VideoTrackTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
"codec TEXT,"
......@@ -121,7 +121,7 @@ bool VideoTrack::createTable( DBConnection dbConnection )
"FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name +
"(id_media) ON DELETE CASCADE"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS video_track_media_idx ON " +
const std::string indexReq = "CREATE INDEX IF NOT EXISTS video_track_media_idx ON " +
policy::VideoTrackTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
......
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