当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.Exec方法代码示例

本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.Exec方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Exec方法的具体用法?C# SQLiteConnection.Exec怎么用?C# SQLiteConnection.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SQLite.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.Exec方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SQLiteImageCache

        public SQLiteImageCache(string dbPath)
        {
            if (sqliteAssembly == null)
            {
                sqliteAssembly = System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(ApplicationPaths.AppConfigPath, "system.data.sqlite.dll"));
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(SqliteResolver);
            }

            SQLiteConnectionStringBuilder connectionstr = new SQLiteConnectionStringBuilder();
            connectionstr.PageSize = 4096;
            connectionstr.CacheSize = 4096;
            connectionstr.SyncMode = SynchronizationModes.Normal;
            connectionstr.DataSource = dbPath;
            connection = new SQLiteConnection(connectionstr.ConnectionString);
            connection.Open();

            string[] queries = {"create table if not exists images (guid, width, height, updated, stream_size, data blob)",
                                "create unique index if not exists idx_images on images(guid, width)",
                               };

            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("ImageCache Writer", DelayedWriter);
        }
开发者ID:rickbassham,项目名称:videobrowser,代码行数:32,代码来源:SQLiteImageCache.cs

示例2: SQLiteDisplayRepository

        public SQLiteDisplayRepository(string dbPath)
        {
            SQLiteConnectionStringBuilder connectionstr = new SQLiteConnectionStringBuilder();
            connectionstr.PageSize = 4096;
            connectionstr.CacheSize = 1024;
            connectionstr.SyncMode = SynchronizationModes.Normal;
            connectionstr.DataSource = dbPath;
            connectionstr.JournalMode = SQLiteJournalModeEnum.Persist; //maybe better performance...?
            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.");

            string[] queries = {
                               "create table if not exists 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 index if not exists idx_display on display_prefs (guid)"
                               };

            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 Display Writer", DelayedWriter);
        }
开发者ID:nickmayer,项目名称:mediabrowser,代码行数:45,代码来源:SQLiteDisplayRepository.cs

示例3: FixUpSchema

 public void FixUpSchema(SQLiteConnection connection)
 {
     //make sure all our columns are in the db
     var cmd = connection.CreateCommand();
     cmd.CommandText = "PRAGMA table_info(items)";
     List<string> dbCols = new List<string>();
     using (var reader = cmd.ExecuteReader())
     {
         while (reader.Read())
         {
             dbCols.Add(reader[1].ToString());
         }
     }
     if (!dbCols.Contains("obj_type")) connection.Exec("Alter table items add column obj_type");
     foreach (var col in this.AtomicColumns)
     {
         if (!dbCols.Contains(col.ColName))
         {
             Logger.ReportInfo("Discovered new attribute: " + col.ColName + " on object type: "+ ObjType+". Adding to schema.");
             connection.Exec("Alter table items add column "+col.ColName);
         }
     }
 }
开发者ID:rickbassham,项目名称:videobrowser,代码行数:23,代码来源:SqliteItemRepository.cs

示例4: SqliteItemRepository

        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);
        }
开发者ID:nickmayer,项目名称:mediabrowser,代码行数:67,代码来源:SqliteItemRepository.cs


注:本文中的System.Data.SQLite.SQLiteConnection.Exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。