static void pragha_application_provider_want_upgrade (PraghaDatabaseProvider *provider, gint provider_id, PraghaApplication *pragha) { PraghaDatabase *database; PraghaScanner *scanner; PraghaPreparedStatement *statement; const gchar *sql, *provider_type = NULL; sql = "SELECT name FROM provider_type WHERE id IN (SELECT type FROM provider WHERE id = ?)"; database = pragha_application_get_database (pragha); statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, provider_id); if (pragha_prepared_statement_step (statement)) provider_type = pragha_prepared_statement_get_string (statement, 0); if (g_ascii_strcasecmp (provider_type, "local") == 0) { scanner = pragha_application_get_scanner (pragha); pragha_scanner_scan_library (scanner); } pragha_prepared_statement_free (statement); }
void pragha_database_delete_radio (PraghaDatabase *database, const gchar *radio) { gint radio_id; if (string_is_empty(radio)) { g_warning("Radio name is NULL"); return; } radio_id = pragha_database_find_radio (database, radio); if (!radio_id) { g_warning("Radio doesn't exist"); return; } pragha_database_flush_radio (database, radio_id); const gchar *sql = "DELETE FROM RADIO WHERE id = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, radio_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_delete_playlist (PraghaDatabase *database, const gchar *playlist) { gint playlist_id; if (string_is_empty(playlist)) { g_warning("Playlist name is NULL"); return; } playlist_id = pragha_database_find_playlist (database, playlist); if (!playlist_id) { g_warning("Playlist doesn't exist"); return; } pragha_database_flush_playlist (database, playlist_id); const gchar *sql = "DELETE FROM PLAYLIST WHERE id = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, playlist_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_flush_radio (PraghaDatabase *database, gint radio_id) { const gchar *sql = "DELETE FROM RADIO_TRACKS WHERE radio = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, radio_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_forget_location (PraghaDatabase *database, gint location_id) { const gchar *sql; PraghaPreparedStatement *statement; sql = "DELETE FROM TRACK WHERE location = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); sql = "DELETE FROM LOCATION WHERE id = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_flush_playlist (PraghaDatabase *database, gint playlist_id) { const gchar *sql = "DELETE FROM PLAYLIST_TRACKS WHERE playlist = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, playlist_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_add_radio_track (PraghaDatabase *database, gint radio_id, const gchar *uri) { const gchar *sql = "INSERT INTO RADIO_TRACKS (uri, radio) VALUES (?, ?)"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_string (statement, 1, uri); pragha_prepared_statement_bind_int (statement, 2, radio_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_add_playlist_track (PraghaDatabase *database, gint playlist_id, const gchar *file) { const gchar *sql = "INSERT INTO PLAYLIST_TRACKS (file, playlist) VALUES (?, ?)"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_string (statement, 1, file); pragha_prepared_statement_bind_int (statement, 2, playlist_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
gint pragha_database_add_new_year (PraghaDatabase *database, guint year) { const gchar *sql = "INSERT INTO YEAR (year) VALUES (?)"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, year); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); return pragha_database_find_year (database, year); }
gint pragha_database_find_year (PraghaDatabase *database, gint year) { gint year_id = 0; const gchar *sql = "SELECT id FROM YEAR WHERE year = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, year); if (pragha_prepared_statement_step (statement)) year_id = pragha_prepared_statement_get_int (statement, 0); pragha_prepared_statement_free (statement); return year_id; }
void pragha_database_update_radio_name (PraghaDatabase *database, const gchar *old_name, const gchar *new_name) { gint radio_id = pragha_database_find_radio (database, old_name); if (!radio_id) return; const gchar *sql = "UPDATE RADIO SET name = ? WHERE id = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_string (statement, 1, new_name); pragha_prepared_statement_bind_int (statement, 2, radio_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
void pragha_database_update_playlist_name (PraghaDatabase *database, const gchar *old_name, const gchar *new_name) { gint playlist_id = pragha_database_find_playlist (database, old_name); if (!playlist_id) return; const gchar *sql = "UPDATE PLAYLIST SET name = ? WHERE id = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_string (statement, 1, new_name); pragha_prepared_statement_bind_int (statement, 2, playlist_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
gchar * pragha_database_get_filename_from_location_id (PraghaDatabase *database, gint location_id) { PraghaPreparedStatement *statement; const gchar *sql; gchar *file = NULL; sql = "SELECT name FROM LOCATION WHERE id = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, location_id); if (pragha_prepared_statement_step (statement)) file = g_strdup (pragha_prepared_statement_get_string (statement, 0)); else g_warning ("Unable to find filename for location id: %d", location_id); pragha_prepared_statement_free (statement); return file; }
static void pragha_database_update_track (PraghaDatabase *database, gint location_id, gint changed, gint track_no, const gchar *title, gint artist_id, gint album_id, gint genre_id, gint year_id, gint comment_id) { const gchar *sql; PraghaPreparedStatement *statement; if (changed & TAG_TNO_CHANGED) { sql = "UPDATE TRACK SET track_no = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, track_no); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_TITLE_CHANGED) { sql = "UPDATE TRACK SET title = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_string (statement, 1, title); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_ARTIST_CHANGED) { sql = "UPDATE TRACK SET artist = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, artist_id); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_ALBUM_CHANGED) { sql = "UPDATE TRACK SET album = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, album_id); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_GENRE_CHANGED) { sql = "UPDATE TRACK SET genre = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, genre_id); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_YEAR_CHANGED) { sql = "UPDATE TRACK SET year = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, year_id); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } if (changed & TAG_COMMENT_CHANGED) { sql = "UPDATE TRACK SET comment = ? WHERE LOCATION = ?"; statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, comment_id); pragha_prepared_statement_bind_int (statement, 2, location_id); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); } }
static void pragha_database_add_new_track (PraghaDatabase *database, gint location_id, gint mime_type_id, gint artist_id, gint album_id, gint genre_id, gint year_id, gint comment_id, guint track_no, gint length, gint channels, gint bitrate, gint samplerate, const gchar *title) { const gchar *sql = "INSERT INTO TRACK (" "location, " "file_type, " "track_no, " "artist, " "album, " "genre, " "year, " "comment, " "bitrate, " "samplerate, " "length, " "channels, " "title) " "VALUES " "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql); pragha_prepared_statement_bind_int (statement, 1, location_id); pragha_prepared_statement_bind_int (statement, 2, mime_type_id); pragha_prepared_statement_bind_int (statement, 3, track_no); pragha_prepared_statement_bind_int (statement, 4, artist_id); pragha_prepared_statement_bind_int (statement, 5, album_id); pragha_prepared_statement_bind_int (statement, 6, genre_id); pragha_prepared_statement_bind_int (statement, 7, year_id); pragha_prepared_statement_bind_int (statement, 8, comment_id); pragha_prepared_statement_bind_int (statement, 9, bitrate); pragha_prepared_statement_bind_int (statement, 10, samplerate); pragha_prepared_statement_bind_int (statement, 11, length); pragha_prepared_statement_bind_int (statement, 12, channels); pragha_prepared_statement_bind_string (statement, 13, title); pragha_prepared_statement_step (statement); pragha_prepared_statement_free (statement); }
PraghaMusicobject * new_musicobject_from_db(PraghaDatabase *cdbase, gint location_id) { PraghaMusicobject *mobj = NULL; CDEBUG(DBG_MOBJ, "Creating new musicobject with location id: %d", location_id); const gchar *sql = "SELECT \ MIME_TYPE.name, \ TRACK.samplerate, \ TRACK.channels, \ TRACK.length, \ TRACK.bitrate, \ COMMENT.name, \ YEAR.year, \ TRACK.track_no, \ GENRE.name, \ ALBUM.name, \ ARTIST.name, \ TRACK.title, \ LOCATION.name \ FROM MIME_TYPE, TRACK, COMMENT, YEAR, GENRE, ALBUM, ARTIST, LOCATION \ WHERE TRACK.location = ? \ AND MIME_TYPE.id = TRACK.file_type \ AND COMMENT.id = TRACK.comment \ AND YEAR.id = TRACK.year \ AND GENRE.id = TRACK.genre \ AND ALBUM.id = TRACK.album \ AND ARTIST.id = TRACK.artist \ AND LOCATION.id = ?"; PraghaPreparedStatement *statement = pragha_database_create_statement (cdbase, sql); pragha_prepared_statement_bind_int (statement, 1, location_id); pragha_prepared_statement_bind_int (statement, 2, location_id); if (pragha_prepared_statement_step (statement)) { mobj = g_object_new (PRAGHA_TYPE_MUSICOBJECT, "file", pragha_prepared_statement_get_string (statement, 12), "source", FILE_LOCAL, "mime-type", pragha_prepared_statement_get_string (statement, 0), "title", pragha_prepared_statement_get_string (statement, 11), "artist", pragha_prepared_statement_get_string (statement, 10), "album", pragha_prepared_statement_get_string (statement, 9), "genre", pragha_prepared_statement_get_string (statement, 8), "comment", pragha_prepared_statement_get_string (statement, 5), "year", pragha_prepared_statement_get_int (statement, 6), "track-no", pragha_prepared_statement_get_int (statement, 7), "length", pragha_prepared_statement_get_int (statement, 3), "bitrate", pragha_prepared_statement_get_int (statement, 4), "channels", pragha_prepared_statement_get_int (statement, 2), "samplerate", pragha_prepared_statement_get_int (statement, 1), NULL); } else { g_critical("Track with location id : %d not found in DB", location_id); } pragha_prepared_statement_free (statement); return mobj; }