Commit 724599b0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Remove global DBConnection typedef

parent 911c31d9
......@@ -25,13 +25,7 @@
namespace medialibrary
{
namespace sqlite
{
class Connection;
}
class MediaLibrary;
using DBConnection = sqlite::Connection*;
using MediaLibraryPtr = const MediaLibrary*;
}
......@@ -331,7 +331,7 @@ bool Album::removeArtist(Artist* artist)
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_id, artist->id() );
}
bool Album::createTable(DBConnection dbConnection )
bool Album::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::AlbumTable::Name +
......@@ -370,7 +370,7 @@ bool Album::createTable(DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
bool Album::createTriggers(DBConnection dbConnection)
bool Album::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS is_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTrackTable::Name +
......
......@@ -98,8 +98,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
bool addArtist( std::shared_ptr<Artist> artist );
bool removeArtist( Artist* artist );
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static std::shared_ptr<Album> create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl );
static std::shared_ptr<Album> createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist );
///
......
......@@ -98,7 +98,7 @@ bool AlbumTrack::setArtist( std::shared_ptr<Artist> artist )
return true;
}
bool AlbumTrack::createTable( DBConnection dbConnection )
bool AlbumTrack::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -68,14 +68,14 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
virtual std::shared_ptr<IAlbum> album() override;
virtual std::shared_ptr<IMedia> media() override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AlbumTrack> create(MediaLibraryPtr ml, int64_t albumId,
std::shared_ptr<Media> media, unsigned int trackNb,
unsigned int discNumber, int64_t artistId, int64_t genreId,
int64_t duration );
static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
static std::vector<MediaPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
static std::vector<MediaPtr> search(DBConnection dbConn, const std::string& title );
static std::vector<MediaPtr> search( sqlite::Connection* dbConn, const std::string& title );
private:
MediaLibraryPtr m_ml;
......
......@@ -189,7 +189,7 @@ bool Artist::setMusicBrainzId( const std::string& mbId )
return true;
}
bool Artist::createTable( DBConnection dbConnection )
bool Artist::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " +
policy::ArtistTable::Name +
......@@ -220,7 +220,7 @@ bool Artist::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, reqFts );
}
bool Artist::createTriggers(DBConnection dbConnection)
bool Artist::createTriggers( sqlite::Connection* dbConnection )
{
static const std::string triggerReq = "CREATE TRIGGER IF NOT EXISTS has_album_present AFTER UPDATE OF "
"is_present ON " + policy::AlbumTable::Name +
......@@ -261,7 +261,7 @@ bool Artist::createTriggers(DBConnection dbConnection)
sqlite::Tools::executeRequest( dbConnection, ftsDeleteTrigger );
}
bool Artist::createDefaultArtists( DBConnection dbConnection )
bool Artist::createDefaultArtists( sqlite::Connection* dbConnection )
{
// Don't rely on Artist::create, since we want to insert or do nothing here.
// This will skip the cache for those new entities, but they will be inserted soon enough anyway.
......
......@@ -63,9 +63,9 @@ public:
virtual const std::string& musicBrainzId() const override;
bool setMusicBrainzId( const std::string& musicBrainzId );
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
static bool createDefaultArtists( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static bool createTriggers( sqlite::Connection* dbConnection );
static bool createDefaultArtists( sqlite::Connection* dbConnection );
static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
static std::vector<ArtistPtr> search( MediaLibraryPtr ml, const std::string& name );
static std::vector<ArtistPtr> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
......
......@@ -97,7 +97,7 @@ const std::string& AudioTrack::description() const
return m_description;
}
bool AudioTrack::createTable( DBConnection dbConnection )
bool AudioTrack::createTable( sqlite::Connection* dbConnection )
{
//FIXME: Index on media_id ? Unless it's already implied by the foreign key
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AudioTrackTable::Name
......
......@@ -58,7 +58,7 @@ class AudioTrack : public IAudioTrack, public DatabaseHelpers<AudioTrack, policy
virtual const std::string& language() const override;
virtual const std::string& description() const override;
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<AudioTrack> create( MediaLibraryPtr ml, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels,
const std::string& language, const std::string& desc, int64_t mediaId );
......
......@@ -100,7 +100,7 @@ std::shared_ptr<Device> Device::create( MediaLibraryPtr ml, const std::string& u
return self;
}
bool Device::createTable(DBConnection connection)
bool Device::createTable( sqlite::Connection* connection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::DeviceTable::Name + "("
"id_device INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -59,7 +59,7 @@ public:
const std::string& scheme() const;
static std::shared_ptr<Device> create( MediaLibraryPtr ml, const std::string& uuid, const std::string& scheme, bool isRemovable );
static bool createTable( DBConnection connection );
static bool createTable( sqlite::Connection* connection );
static std::shared_ptr<Device> fromUuid( MediaLibraryPtr ml, const std::string& uuid );
private:
......
......@@ -190,7 +190,7 @@ int64_t File::folderId()
return m_folderId;
}
bool File::createTable( DBConnection dbConnection )
bool File::createTable( sqlite::Connection* dbConnection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
......
......@@ -77,7 +77,7 @@ public:
bool destroy();
int64_t folderId();
static bool createTable( DBConnection dbConnection );
static bool createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
const fs::IFile& file, int64_t folderId, bool isRemovable );
static std::shared_ptr<File> createFromMedia( MediaLibraryPtr ml, int64_t mediaId, Type type,
......
......@@ -70,7 +70,7 @@ Folder::Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent, int6
{
}
bool Folder::createTable( DBConnection connection)
bool Folder::createTable( sqlite::Connection* connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FolderTable::Name +
"("
......
......@@ -60,7 +60,7 @@ public:
Folder( MediaLibraryPtr ml, sqlite::Row& row );
Folder(MediaLibraryPtr ml, const std::string& path, int64_t parent , int64_t deviceId , bool isRemovable );
static bool createTable( DBConnection connection );
static bool createTable( sqlite::Connection* connection );
static std::shared_ptr<Folder> create( MediaLibraryPtr ml, const std::string& mrl, int64_t parentId, Device& device, fs::IDevice& deviceFs );
static bool blacklist( MediaLibraryPtr ml, const std::string& mrl );
static std::vector<std::shared_ptr<Folder>> fetchRootFolders( MediaLibraryPtr ml );
......
......@@ -97,7 +97,7 @@ std::vector<AlbumPtr> Genre::albums( SortingCriteria sort, bool desc ) const
return Album::fromGenre( m_ml, m_id, sort, desc );
}
bool Genre::createTable( DBConnection dbConn )
bool Genre::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::GenreTable::Name +
"("
......@@ -126,7 +126,7 @@ bool Genre::createTable( DBConnection dbConn )
sqlite::Tools::executeRequest( dbConn, vtableDeleteTrigger );
}
bool Genre::createTriggers( DBConnection dbConn )
bool Genre::createTriggers( sqlite::Connection* dbConn )
{
const std::string onGenreChanged = "CREATE TRIGGER IF NOT EXISTS on_track_genre_changed AFTER UPDATE OF "
" genre_id ON " + policy::AlbumTrackTable::Name +
......
......@@ -54,8 +54,8 @@ public:
virtual std::vector<MediaPtr> tracks(SortingCriteria sort, bool desc) const override;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort, bool desc ) const override;
static bool createTable( DBConnection dbConn );
static bool createTriggers( DBConnection dbConn );
static bool createTable( sqlite::Connection* dbConn );
static bool createTriggers( sqlite::Connection* dbConn );
static std::shared_ptr<Genre> create( MediaLibraryPtr ml, const std::string& name );
static std::shared_ptr<Genre> fromName( MediaLibraryPtr ml, const std::string& name );
static std::vector<GenrePtr> search( MediaLibraryPtr ml, const std::string& name );
......
......@@ -49,7 +49,7 @@ History::History( MediaLibraryPtr ml, sqlite::Row& row )
row >> m_date;
}
bool History::createTable( DBConnection dbConnection )
bool History::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::HistoryTable::Name +
"("
......@@ -70,7 +70,7 @@ bool History::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
bool History::insert( DBConnection dbConn, int64_t mediaId )
bool History::insert( sqlite::Connection* dbConn, int64_t mediaId )
{
static const std::string req = "INSERT OR REPLACE INTO " + policy::HistoryTable::Name +
"(id_media, insertion_date) VALUES(?, strftime('%s', 'now'))";
......
......@@ -49,8 +49,8 @@ class History : public IHistoryEntry, public DatabaseHelpers<History, policy::Hi
{
public:
History( MediaLibraryPtr ml, sqlite::Row& row );
static bool createTable( DBConnection dbConnection );
static bool insert( DBConnection dbConn, int64_t mediaId );
static bool createTable( sqlite::Connection* dbConnection );
static bool insert( sqlite::Connection* dbConn, int64_t mediaId );
static std::vector<HistoryPtr> fetch( MediaLibraryPtr ml );
static bool clearStreams( MediaLibraryPtr ml );
......
......@@ -80,7 +80,7 @@ LabelPtr Label::create( MediaLibraryPtr ml, const std::string& name )
return self;
}
bool Label::createTable( DBConnection dbConnection )
bool Label::createTable( sqlite::Connection* dbConnection )
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
......
Supports Markdown
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