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


C# Sqlite.SqliteConnection类代码示例

本文整理汇总了C#中Microsoft.Data.Sqlite.SqliteConnection的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection类的具体用法?C# SqliteConnection怎么用?C# SqliteConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SqliteConnection类属于Microsoft.Data.Sqlite命名空间,在下文中一共展示了SqliteConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnConfiguring

 //Add-Migration vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
 //Update-Database vyzva-sqlite-001 -c NewData.Vyzva57Context_Sqlite
 protected override void OnConfiguring(DbContextOptionsBuilder options) {
   base.OnConfiguring(options);
   var config = ConfigurationManager.ConnectionStrings["Vyzva57-sqlite"];
   var conn = new SqliteConnection(config.ConnectionString);
   //var conn = new SqliteConnection("Data Source=" + MachinesLow.rootDir +  config.ConnectionString);
   options.UseSqlite(conn);
 }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:9,代码来源:Vyzva57Context.cs

示例2: Create

        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual DatabaseModel Create(string connectionString, TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));
            Check.NotNull(tableSelectionSet, nameof(tableSelectionSet));

            ResetState();

            using (_connection = new SqliteConnection(connectionString))
            {
                _connection.Open();
                _tableSelectionSet = tableSelectionSet;

                string databaseName = null;
                try
                {
                    databaseName = Path.GetFileNameWithoutExtension(_connection.DataSource);
                }
                catch (ArgumentException)
                {
                    // graceful fallback
                }

                _databaseModel.DatabaseName = !string.IsNullOrEmpty(databaseName)
                    ? databaseName
                    : _connection.DataSource;

                GetTables();
                GetColumns();
                GetIndexes();
                GetForeignKeys();
                return _databaseModel;
            }
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:37,代码来源:SqliteDatabaseModelFactory.cs

示例3: BaseDataSQLite

        static BaseDataSQLite()
        {
            #if DEBUG
            _sqliteFile = Paths.DebugSQLitePath;
            #else
            _sqliteFile = Paths.ReleaseSQLitePath;
            #endif

            //_connectionString = String.Format("Data Source=:memory:");
            //_connectionString = String.Format("Data Source={0};Version=3;Pooling=True;Max Pool Size=100;Synchronous=Normal;Journal Mode=WAL", _sqliteFile);
            _connectionString = String.Format("Data Source={0}", _sqliteFile);

            if (!File.Exists(_sqliteFile))
            {
                if (!File.Exists(Paths.SqlPath))
                    throw new FileNotFoundException("Cannot find SQL file: " + Paths.SqlPath);
                else {
                    // Generate database
                    var conn = new SqliteConnection(_connectionString);
                    conn.Open();
                    var sql = File.ReadAllText(Paths.SqlPath);
                    conn.Execute(sql);
                    conn.Dispose();
                }
            }
        }
开发者ID:McBits,项目名称:DungeonR,代码行数:26,代码来源:BaseDataSQLite.cs

示例4: LocateIPv6Async

 private async Task<IEnumerable<IPRangeInfo>> LocateIPv6Async(IPAddress ip)
 {
     var flatIP = new FlatIPAddress(ip);
     using (var connection = new SqliteConnection(_connectionString))
     {
         connection.Open();
         return await connection.ExecuteReaderAsync(dataReader =>
         {
             return new IPRangeInfo
             {
                 IPRange = new IPRange
                 {
                     Start = new FlatIPAddress { Low = (long)dataReader["StartLow"], High = (long)dataReader["StartHigh"] }.ToIPAddress(),
                     End = new FlatIPAddress { Low = (long)dataReader["EndLow"], High = (long)dataReader["EndHigh"] }.ToIPAddress(),
                 },
                 AreaId = Convert.ToInt32(dataReader["AreaId"]),
                 ProviderId = Convert.ToInt32(dataReader["ProviderId"]),
             };
         }, @"
             SELECT * FROM IPRangeInfos 
             WHERE (StartHigh < {1} OR (StartHigh = {1} AND StartLow <= {0}))
             AND (EndHigh > {1} OR (EndHigh = {1} AND EndLow >= {0}));",
         flatIP.Low, flatIP.High);
     }
 }
开发者ID:rgripper,项目名称:SillyGeo,代码行数:25,代码来源:SqliteIPGeoLocationService.cs

示例5: AddHistoricMessage

        private static void AddHistoricMessage(Message message)
        {
            var sql = string.Format("INSERT INTO {0} (MessageId, MessageType, Topic, Timestamp, HeaderBag, Body) VALUES (@MessageId, @MessageType, @Topic, @Timestamp, @HeaderBag, @Body)", _sqliteTestHelper.TableName_Messages);
            var parameters = new[]
            {
                new SqliteParameter("MessageId", message.Id.ToString()),
                new SqliteParameter("MessageType", message.Header.MessageType.ToString()),
                new SqliteParameter("Topic", message.Header.Topic),
                new SqliteParameter("Timestamp", SqliteType.Text) { Value =message.Header.TimeStamp.ToString("s")},
                new SqliteParameter("HeaderBag",SqliteType.Text) { Value = JsonConvert.SerializeObject(message.Header.Bag)},
                new SqliteParameter("Body", message.Body.Value),
            };

            using (var connection = new SqliteConnection(_sqliteTestHelper.ConnectionString))
            using (var command = connection.CreateCommand())
            {
                connection.Open();

                command.CommandText = sql;
                //command.Parameters.AddRange(parameters); used to work... but can't with current Sqlite lib. Iterator issue
                for (var index = 0; index < parameters.Length; index++)
                {
                    command.Parameters.Add(parameters[index]);
                }
                command.ExecuteNonQuery();
            }
        }
开发者ID:iancooper,项目名称:Paramore,代码行数:27,代码来源:SqlMessageStoreMigrationTests.cs

示例6: RunSqlite

        public void RunSqlite()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "CREATE TABLE Test(Value);";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "INSERT INTO Test VALUES(1);";
                    cmd.ExecuteNonQuery();
                }
                using (var cmd = connection.CreateCommand())
                {
                    cmd.CommandText =
                        "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [main].[sqlite_master] WHERE [type] LIKE 'table'";
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            System.Console.WriteLine(dr[2].ToString());
                        }
                    }
                }

                var databaseReader = new DatabaseSchemaReader.DatabaseReader(connection);
                var schema = databaseReader.ReadAll();
                var tableList = databaseReader.TableList();
                var tables = databaseReader.AllTables();
                var views = databaseReader.AllViews();
                Assert.NotEmpty(tableList);
            }
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:34,代码来源:TestSqLite.cs

示例7: SqliteTransaction

        internal SqliteTransaction(SqliteConnection connection, IsolationLevel isolationLevel)
        {
            _connection = connection;
            _isolationLevel = isolationLevel;

            if (isolationLevel == IsolationLevel.ReadUncommitted)
            {
                if (connection.ConnectionStringBuilder.CacheMode != CacheMode.Shared)
                {
                    throw new ArgumentException(Strings.FormatInvalidIsolationLevelForUnsharedCache(isolationLevel));
                }
                connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;");
            }
            else if (isolationLevel == IsolationLevel.Serializable)
            {
                connection.ExecuteNonQuery("PRAGMA read_uncommitted = 0;");
            }
            else if (isolationLevel != IsolationLevel.Unspecified)
            {
                throw new ArgumentException(Strings.FormatInvalidIsolationLevel(isolationLevel));
            }

            // TODO: Register transaction hooks to detect when a user manually completes a transaction created using this API
            connection.ExecuteNonQuery("BEGIN;");
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:25,代码来源:SqliteTransaction.cs

示例8: Ctor_sets_connection_string

        public void Ctor_sets_connection_string()
        {
            var connectionSring = "Data Source=test.db";

            var connection = new SqliteConnection(connectionSring);

            Assert.Equal(connectionSring, connection.ConnectionString);
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:8,代码来源:SqliteConnectionTest.cs

示例9: OnConfiguring

        // This method connects the context with the database
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "ef6NotesManagerV3.sqlite" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseSqlite(connection);
        }
开发者ID:WallyWest21,项目名称:Notes-Manager,代码行数:9,代码来源:Database.cs

示例10: ServerVersion_returns_value

        public void ServerVersion_returns_value()
        {
            var connection = new SqliteConnection();

            var version = connection.ServerVersion;

            Assert.StartsWith("3.", version);
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:8,代码来源:SqliteConnectionTest.cs

示例11: OnConfiguring

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = DATABASE_NAME };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseSqlite(connection);
        }
开发者ID:ncclu,项目名称:FastQueryStock_Git,代码行数:8,代码来源:StockContext.cs

示例12: OnConfiguring

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "WeatherDressing.db" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);

            //optionsBuilder.UseSqlite(connection);
        }
开发者ID:dsokac,项目名称:C_sharp_tutoring,代码行数:8,代码来源:WeatherDressingContext.cs

示例13: Open

 private SqliteConnection Open(string connectionString)
 {
     var connection = new SqliteConnection(connectionString);
     connection.Open();
     connection.EnableExtensions();
     connection.LoadExtension(_spatialiteExtensionName);
     return connection;
 }
开发者ID:rgripper,项目名称:SillyGeo,代码行数:8,代码来源:SqliteImportService.cs

示例14: TestLite

 public void TestLite()
 {
     using (SqliteConnection conn = new SqliteConnection(_connectionString))
     {
         conn.Open();
         //var d = conn.Query("SELECT * FROM User;");
     }
 }
开发者ID:openauth,项目名称:WiFiDog-Auth,代码行数:8,代码来源:WiFiAuthService.cs

示例15: CreateTransient

        private SqliteTestStore CreateTransient(bool sharedCache)
        {
            _connection = new SqliteConnection(CreateConnectionString(_name, sharedCache));

            _connection.Open();

            return this.AsTransient();
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:8,代码来源:SqliteTestStore.cs


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