Inheritance: HyenaSqliteConnection, IInitializeService, IRequiredService
示例#1
0
        public void Migrate ()
        {
            Paths.ApplicationName = Application.InternalName;

            int count = 0;
            foreach (string file in Directory.GetFiles (Path.Combine (TestsDir, "data"))) {
                if (file.EndsWith (".db")) {
                    var db_file = file + ".test-tmp-copy";
                    try {
                        File.Delete (db_file);
                        File.Copy (file, db_file);

                        // Call the magic methods to test the migration path
                        var db = new BansheeDbConnection (db_file);
                        SortKeyUpdater.Disable = true;
                        ((IInitializeService)db).Initialize ();
                        Assert.IsTrue (db.ValidateSchema ());
                        count++;
                    } catch (Exception e) {
                        Assert.Fail (String.Format ("Failed to migrate db: {0}", e));
                    } finally {
                        File.Delete (db_file);
                    }
                }
            }
            Assert.IsTrue (count > 0);
        }
示例#2
0
        public void Migrate()
        {
            Application.InitializePaths();

            int count = 0;

            foreach (string file in Directory.GetFiles(Path.Combine(TestsDir, "data")))
            {
                if (file.EndsWith(".db"))
                {
                    var db_file = file + ".test-tmp-copy";
                    try {
                        File.Delete(db_file);
                        File.Copy(file, db_file);

                        // Call the magic methods to test the migration path
                        var db = new BansheeDbConnection(db_file);
                        SortKeyUpdater.Disable = true;
                        ((IInitializeService)db).Initialize();
                        Assert.IsTrue(db.ValidateSchema());
                        count++;
                    } catch (Exception e) {
                        Assert.Fail(String.Format("Failed to migrate db: {0}", e));
                    } finally {
                        File.Delete(db_file);
                    }
                }
            }
            Assert.IsTrue(count > 0);
        }
示例#3
0
        public bool ValidateSchema()
        {
            bool is_valid    = true;
            var  new_db_path = Paths.GetTempFileName(Paths.TempDir);
            var  new_db      = new BansheeDbConnection(new_db_path);

            ((IInitializeService)new_db).Initialize();

            Hyena.Log.DebugFormat("Validating db schema for {0}", DbPath);

            var tables = new_db.QueryEnumerable <string> (
                "select name from sqlite_master where type='table' order by name"
                );

            foreach (var table in tables)
            {
                if (!TableExists(table))
                {
                    Log.ErrorFormat("Table {0} does not exist!", table);
                    is_valid = false;
                }
                else
                {
                    var a = new_db.SortedTableColumns(table);
                    var b = SortedTableColumns(table);

                    a.Except(b).ForEach(c => { is_valid = false; Hyena.Log.ErrorFormat("Table {0} should contain column {1}", table, c); });
                    b.Except(a).ForEach(c => Hyena.Log.DebugFormat("Table {0} has extra (probably obsolete) column {1}", table, c));
                }
            }

            using (var reader = new_db.Query(
                       "select name,sql from sqlite_master where type='index' AND name NOT LIKE 'sqlite_autoindex%' order by name")) {
                while (reader.Read())
                {
                    string name = (string)reader[0];
                    string sql  = (string)reader[1];
                    if (!IndexExists(name))
                    {
                        Log.ErrorFormat("Index {0} does not exist!", name);
                        is_valid = false;
                    }
                    else
                    {
                        string our_sql = Query <string> ("select sql from sqlite_master where type='index' and name=?", name);
                        if (our_sql != sql)
                        {
                            Log.ErrorFormat("Index definition of {0} differs, should be `{1}` but is `{2}`", name, sql, our_sql);
                            is_valid = false;
                        }
                    }
                }
            }

            Hyena.Log.DebugFormat("Done validating db schema for {0}", DbPath);
            System.IO.File.Delete(new_db_path);
            return(is_valid);
        }
        public PodcastTrackListModel (BansheeDbConnection conn, IDatabaseTrackModelProvider provider, DatabaseSource source) : base (conn, provider, source)
        {
            From = String.Format ("{0}, {1}, {2}, {3}", provider.From, Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName);

            int podcast_library_dbid = (source as PodcastSource ?? source.Parent as PodcastSource).DbId;
            AddCondition (From, String.Format (
                "CoreTracks.PrimarySourceID = {3} AND {0}.FeedID = {1}.FeedID AND CoreTracks.ExternalID = {1}.ItemID AND {1}.ItemID = {2}.ItemID",
                Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName, podcast_library_dbid
            ));
        }
示例#5
0
        public AudiobookModel(AudiobookLibrarySource source, DatabaseTrackListModel trackModel, BansheeDbConnection connection, string uuid)
            : base(source, trackModel, connection, uuid)
        {
            Selection = new Hyena.Collections.Selection ();
            HasSelectAllItem = false;

            ReloadFragmentFormat = String.Format (@"
                FROM CoreAlbums WHERE CoreAlbums.AlbumID IN (SELECT AlbumID FROM CoreTracks WHERE PrimarySourceID = {0})
                ORDER BY CoreAlbums.TitleSortKey, CoreAlbums.ArtistNameSortKey",
                source.DbId);
        }
        public DatabaseTrackListModel (BansheeDbConnection connection, IDatabaseTrackModelProvider provider, Banshee.Sources.DatabaseSource source)
        {
            this.connection = connection;
            this.provider = provider;
            this.source = source;

            SelectAggregates = "SUM(CoreTracks.Duration), SUM(CoreTracks.FileSize)";

            Selection.Changed += delegate {
                if (SelectionAggregatesHandler != null) {
                    cache.UpdateSelectionAggregates (SelectionAggregatesHandler);
                }
            };
        }
        public PodcastTrackListModel (BansheeDbConnection conn, IDatabaseTrackModelProvider provider, DatabaseSource source) : base (conn, provider, source)
        {
            From = String.Format ("{0}, {1}, {2}, {3}", provider.From, Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName);

            int podcast_library_dbid = (source as PodcastSource ?? source.Parent as PodcastSource).DbId;
            AddCondition (From, String.Format (
                "CoreTracks.PrimarySourceID = {3} AND {0}.FeedID = {1}.FeedID AND CoreTracks.ExternalID = {1}.ItemID AND {1}.ItemID = {2}.ItemID",
                Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName, podcast_library_dbid
            ));

            SelectAggregates += ",COUNT(NULLIF(CoreTracks.Uri LIKE 'file:%', 0)), COUNT(NULLIF(CoreTracks.PlayCount = 0, 0)), COUNT(DISTINCT(CoreTracks.AlbumID))";
            SelectionAggregatesHandler = (reader) => {
                SelectionDownloadedCount = Convert.ToInt32 (reader[3]);
                SelectionUnheardCount = Convert.ToInt32 (reader[4]);
                SelectionPodcastCount = Convert.ToInt32 (reader[5]);
            };
        }
        public CS_TrackInfoDb(BansheeDbConnection con)
        {
            _con=con;
            _sql_check=new HyenaSqliteCommand("SELECT COUNT(*) FROM cuesheet_info WHERE key=?");
            _sql_get=new HyenaSqliteCommand("SELECT type,value FROM cuesheet_info WHERE key=?");
            _sql_insert=new HyenaSqliteCommand("INSERT INTO cuesheet_info VALUES(?,?,?)");
            _sql_update=new HyenaSqliteCommand("UPDATE cuesheet_info SET type=?, value=? WHERE key=?");
            _sql_key_begin=new HyenaSqliteCommand("SELECT key FROM cuesheet_info WHERE key LIKE ?");
            try {
                if (!_con.TableExists ("cuesheet_info")) {
                    _con.Query ("CREATE TABLE cuesheet_info(key varchar,type varchar,value varchar)");
                    _con.Query ("CREATE INDEX cuesheet_idx1 ON cuesheet_info(key)");
                }

            } catch (System.Exception ex) {
                Hyena.Log.Information (ex.ToString ());
            }
        }
        public bool ValidateSchema()
        {
            bool is_valid = true;
            var new_db_path = Paths.GetTempFileName (Paths.TempDir);
            var new_db = new BansheeDbConnection (new_db_path);
            ((IInitializeService)new_db).Initialize ();

            Hyena.Log.DebugFormat ("Validating db schema for {0}", DbPath);

            var tables = new_db.QueryEnumerable<string> (
                "select name from sqlite_master where type='table' order by name"
            );

            foreach (var table in tables) {
                if (!TableExists (table)) {
                    Log.ErrorFormat ("Table {0} does not exist!", table);
                    is_valid = false;
                } else {
                    var a = new_db.SortedTableColumns (table);
                    var b = SortedTableColumns (table);

                    a.Except (b).ForEach (c => { is_valid = false; Hyena.Log.ErrorFormat ("Table {0} should contain column {1}", table, c); });
                    b.Except (a).ForEach (c => Hyena.Log.DebugFormat ("Table {0} has extra (probably obsolete) column {1}", table, c));
                }
            }

            using (var reader = new_db.Query (
                "select name,sql from sqlite_master where type='index' AND name NOT LIKE 'sqlite_autoindex%' order by name")) {
                while (reader.Read ()) {
                    string name = (string)reader[0];
                    string sql = (string)reader[1];
                    if (!IndexExists (name)) {
                        Log.ErrorFormat ("Index {0} does not exist!", name);
                        is_valid = false;
                    } else {
                        string our_sql = Query<string> ("select sql from sqlite_master where type='index' and name=?", name);
                        if (our_sql != sql) {
                            Log.ErrorFormat ("Index definition of {0} differs, should be `{1}` but is `{2}`", name, sql, our_sql);
                            is_valid = false;
                        }
                    }
                }
            }

            Hyena.Log.DebugFormat ("Done validating db schema for {0}", DbPath);
            System.IO.File.Delete (new_db_path);
            return is_valid;
        }
        public DatabaseTrackListModel(BansheeDbConnection connection, IDatabaseTrackModelProvider provider, Banshee.Sources.DatabaseSource source)
        {
            this.connection = connection;
            this.provider = provider;
            this.source = source;

            SelectAggregates = String.Format ("SUM({0}), SUM({1})",
                                              BansheeQuery.DurationField.Column, BansheeQuery.FileSizeField.Column);

            Selection.Changed += delegate {
                if (SelectionAggregatesHandler != null) {
                    cache.UpdateSelectionAggregates (SelectionAggregatesHandler);
                }
            };
        }
示例#11
0
 public BansheeModelProvider(BansheeDbConnection connection, string table_name)
     : base(connection, table_name, BansheeDatabaseSettings.CheckTables)
 {
 }
 public PlayQueueTrackListModel(
     BansheeDbConnection conn, IDatabaseTrackModelProvider provider, PlayQueueSource source)
     : base(conn, provider, source)
 {
     this.source = source;
 }
 public DatabaseTrackListModel (BansheeDbConnection connection, IDatabaseTrackModelProvider provider, Banshee.Sources.DatabaseSource source)
 {
     this.connection = connection;
     this.provider = provider;
     this.source = source;
 }