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

Remove hardcoded table names

parent 1ed5704b
......@@ -41,8 +41,9 @@ bool File::insert( sqlite3* dbConnection )
assert( m_dbConnection == NULL );
assert( m_id == 0 );
sqlite3_stmt* stmt;
const char* req = "INSERT INTO File VALUES(NULL, ?, ?, ?, ?, ?, ?)";
if ( sqlite3_prepare_v2( dbConnection, req, -1, &stmt, NULL ) != SQLITE_OK )
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
" VALUES(NULL, ?, ?, ?, ?, ?, ?)";
if ( sqlite3_prepare_v2( dbConnection, req.c_str(), -1, &stmt, NULL ) != SQLITE_OK )
{
std::cerr << "Failed to insert record: " << sqlite3_errmsg( dbConnection ) << std::endl;
return false;
......@@ -87,10 +88,10 @@ std::shared_ptr<IShowEpisode> File::showEpisode()
std::vector<std::shared_ptr<ILabel> > File::labels()
{
std::vector<std::shared_ptr<ILabel> > labels;
const char* req = "SELECT l.* FROM Label l "
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_file = ?";
SqliteTools::fetchAll<Label>( m_dbConnection, req, m_id, labels );
SqliteTools::fetchAll<Label>( m_dbConnection, req.c_str(), m_id, labels );
return labels;
}
......@@ -111,8 +112,7 @@ unsigned int File::id() const
bool File::createTable(sqlite3* connection)
{
//FIXME: File is hardcoded
const char* req = "CREATE TABLE IF NOT EXISTS File("
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER,"
"duration UNSIGNED INTEGER,"
......@@ -121,7 +121,7 @@ bool File::createTable(sqlite3* connection)
"show_episode_id UNSIGNED INTEGER,"
"mrl TEXT"
")";
return SqliteTools::createTable( connection, req );
return SqliteTools::createTable( connection, req.c_str() );
}
bool File::addLabel( LabelPtr label )
......
......@@ -41,10 +41,10 @@ std::vector<FilePtr>& Label::files()
if ( m_files == nullptr )
{
m_files = new std::vector<std::shared_ptr<IFile>>;
const char* req = "SELECT f.* FROM Files f "
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
SqliteTools::fetchAll<File>( m_dbConnection, req, m_id, *m_files );
SqliteTools::fetchAll<File>( m_dbConnection, req.c_str(), m_id, *m_files );
}
return *m_files;
}
......@@ -71,11 +71,11 @@ bool Label::insert( sqlite3* dbConnection )
bool Label::createTable(sqlite3* dbConnection)
{
const char* req = "CREATE TABLE IF NOT EXISTS Label("
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
"name TEXT"
")";
if ( SqliteTools::createTable( dbConnection, req ) == false )
if ( SqliteTools::createTable( dbConnection, req.c_str() ) == false )
return false;
req = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER,"
......@@ -83,6 +83,6 @@ bool Label::createTable(sqlite3* dbConnection)
"PRIMARY KEY (id_label, id_file)"
"FOREIGN KEY(id_label) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(id_file) REFERENCES File(id_file) ON DELETE CASCADE);";
return SqliteTools::createTable( dbConnection, req );
return SqliteTools::createTable( dbConnection, req.c_str() );
}
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