コード例 #1
0
        private SqliteItemRepository(string dbPath)
        {
            Logger.ReportInfo("==========Using new SQL Repo========");
            dbFileName = dbPath;

            if (!ConnectToDB(dbPath)) throw new ApplicationException("CRITICAL ERROR - Unable to connect to database: " + dbPath + ".  Program cannot function.");

            displayRepo = new SQLiteDisplayRepository(Path.Combine(ApplicationPaths.AppUserSettingsPath, "display.db"));
            using (new MediaBrowser.Util.Profiler("Playstate initialization"))
            playbackStatus = new FileBasedDictionary<PlaybackStatus>(GetPath("playstate", ApplicationPaths.AppUserSettingsPath));

            //string playStateDBPath = Path.Combine(ApplicationPaths.AppUserSettingsPath, "playstate.db");

            string[] queries = {"create table if not exists provider_data (guid, full_name, data)",
                                "create unique index if not exists idx_provider on provider_data(guid, full_name)",
                                "create table if not exists items (guid primary key)",
                                "create index if not exists idx_items on items(guid)",
                                "create table if not exists children (guid, child)",
                                "create unique index if not exists idx_children on children(guid, child)",
                                "create table if not exists list_items(guid, property, value, sort_order)",
                                "create index if not exists idx_list on list_items(guid, property)",
                                "create unique index if not exists idx_list_constraint on list_items(guid, property, value)",
                                "create table if not exists schema_version (table_name primary key, version)",
                                //triggers
                                triggerSQL,
                                //pragmas
                                "pragma temp_store = memory",
                               // @"create table display_prefs (guid primary key, view_type, show_labels, vertical_scroll
                               //        sort_order, index_by, use_banner, thumb_constraint_width, thumb_constraint_height, use_coverflow, use_backdrop )"
                                //,   "create table play_states (guid primary key, play_count, position_ticks, playlist_position, last_played)"
                               };

            RunQueries(queries);
            alive = true; // tell writer to keep going
            Async.Queue("Sqlite Writer", DelayedWriter);
        }
コード例 #2
0
        private SqliteItemRepository(string dbPath)
        {
            Logger.ReportInfo("==========Using new SQL Repo========");
            dbFileName = dbPath;

            SQLiteConnectionStringBuilder connectionstr = new SQLiteConnectionStringBuilder();
            connectionstr.PageSize = 4096;
            connectionstr.CacheSize = 4096;
            connectionstr.SyncMode = SynchronizationModes.Normal;
            connectionstr.DataSource = dbPath;
            connectionstr.JournalMode = SQLiteJournalModeEnum.Delete;
            connection = new SQLiteConnection(connectionstr.ConnectionString);
            int retries = 0;
            bool connected = false;
            while (!connected && retries < MAX_RETRIES)
            {
                try
                {
                    connection.Open();
                    connected = true;
                }
                catch (Exception e)
                {
                    Logger.ReportException("Error connecting to database! Will retry "+MAX_RETRIES+" times.", e);
                    retries++;
                    Thread.Sleep(250);
                }
            }

            if (!connected) throw new ApplicationException("CRITICAL ERROR - Unable to connect to database: " + dbPath + ".  Program cannot function.");

            displayRepo = new SQLiteDisplayRepository(Path.Combine(ApplicationPaths.AppUserSettingsPath, "display.db"));
            playbackStatus = new FileBasedDictionary<PlaybackStatus>(GetPath("playstate", ApplicationPaths.AppUserSettingsPath));

            //string playStateDBPath = Path.Combine(ApplicationPaths.AppUserSettingsPath, "playstate.db");

            string[] queries = {"create table if not exists provider_data (guid, full_name, data)",
                                "create unique index if not exists idx_provider on provider_data(guid, full_name)",
                                "create table if not exists items (guid primary key)",
                                "create index if not exists idx_items on items(guid)",
                                "create table if not exists children (guid, child)",
                                "create unique index if not exists idx_children on children(guid, child)",
                                "create table if not exists list_items(guid, property, value, sort_order)",
                                "create index if not exists idx_list on list_items(guid, property)",
                                "create unique index if not exists idx_list_constraint on list_items(guid, property, value)",
                                "create table if not exists schema_version (table_name primary key, version)",
                                //"create table if not exists recent_list(top_parent, child, date_added)",
                                //"create index if not exists idx_recent on recent_list(top_parent, child)",
                                //"attach database '"+playStateDBPath+"' as playstate_db",
                                //"create table if not exists playstate_db.play_states (guid primary key, play_count, position_ticks, playlist_position, last_played)",
                                "pragma temp_store = memory",
                               // @"create table display_prefs (guid primary key, view_type, show_labels, vertical_scroll
                               //        sort_order, index_by, use_banner, thumb_constraint_width, thumb_constraint_height, use_coverflow, use_backdrop )"
                                //,   "create table play_states (guid primary key, play_count, position_ticks, playlist_position, last_played)"
                               };

            foreach (var query in queries) {
                try {
                    connection.Exec(query);
                } catch (Exception e) {
                    Logger.ReportInfo(e.ToString());
                }
            }

            alive = true; // tell writer to keep going
            Async.Queue("Sqlite Writer", DelayedWriter);
        }