/* Echo Media Player
* Copyright (C) 2008 Shane O'Connell
*
* [ The original file includes a copyright header in this location describing
* the file as being released under the terms of the GNU General Public
* License. It has been removed in order to display the file as part of the
* archive. ]
*/
#ifndef DATABASE_H_
#define DATABASE_H_
#include "Library.h"
#include "SQL.h"
#include "../PlaySource.h"
#include <cassert>
#include <vector>
#include <map>
#include <gtkmm.h>
class Database
{
public:
static void init();
static const std::vector<LibraryRef>& get_libraries()
{ return m_instance->m_libraries; }
private:
Database();
static Database* m_instance;
SQL db;
void run(const Glib::ustring& sql)
{ db.run(sql); }
void prepare(SQLstmt& stmt, const Glib::ustring& sql)
{ db.prepare(stmt, sql); }
long long last_rowid() const
{ return db.last_rowid(); }
int get_row_count(const Glib::ustring& table);
long long get_artist_id(const Glib::ustring& artist_name);
SQLstmt m_get_artist_id_stmt;
SQLstmt m_add_artist_id_stmt;
long long get_album_id(long long artist_id, const Glib::ustring& album_name);
SQLstmt m_get_album_id_stmt;
SQLstmt m_add_album_id_stmt;
long long get_track_id(const Glib::ustring& uri);
SQLstmt m_get_track_id_stmt;
SQLstmt m_add_track_id_stmt;
StringRef get_artist_from_id(long long artist_id)
{ return m_artist_id_lookup[artist_id]; }
StringRef get_album_from_id(long long artist_id)
{ return m_album_id_lookup[artist_id]; }
std::vector<LibraryRef> m_libraries;
std::map<long long, StringRef> m_artist_id_lookup;
std::map<long long, StringRef> m_album_id_lookup;
friend class DbPlaySource;
friend class Playlist;
friend class Library;
};
#endif /* DATABASE_H_ */