Ejemplo n.º 1
0
        private static IDbConnection GetDatabaseConnectionSDS(string cs)
        {
            var rv = new Microsoft.Data.Sqlite.SqliteConnection(cs);

            if (rv == null)
            {
                throw new ArgumentException("no connection");
            }
            rv.Open();

            try {
                /*  rv.SetChunkSize(GROW_SIZE); */
            }
            catch (Exception ex) {
                LogManager.GetLogger(typeof(Sqlite)).Error(
                    "Failed to sqlite control", ex);
            }

            if (clearPool == null)
            {
                clearPool = conn =>
                {
                    /* SQLiteConnection.ClearPool(
                     * conn as SqliteConnection); */
                };
            }
            return(rv);
        }
Ejemplo n.º 2
0
        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();
                }
            }
        }
 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);
     }
 }
        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;");
        }
Ejemplo n.º 5
0
    public void SimpleReader_TypedDictionary()
    {
        using var sqlite = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");
        using var conn   = new DataConnection(sqlite, new DataSqlDialect());

        conn.Open();
        assert.Equal(ConnectionState.Open, conn.State);

        var parameters = new Dictionary <string, object>()
        {
            { "first", "one" },
        };

        var query  = conn.SqlDialect.CreateBuilder();
        var reader = conn.ExecuteReader(
            query.Append("SELECT @first AS first"), parameters);

        bool read = false;

        while (reader.Read())
        {
            var v = reader.GetString("first");
            assert.Equal("one", v);

            read = true;
        }

        assert.Ok(read);
    }
        /// <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;
            }
        }
        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();
            }
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
 public void CreateDatabase()
 {
     using (Microsoft.Data.Sqlite.SqliteConnection connection = new Microsoft.Data.Sqlite.SqliteConnection(connectionString))
     {
         connection.Open();
     }
 }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
 public void Dispose()
 {
     if (_conn != null)
     {
         _conn.Dispose();
         _conn = null;
     }
 }
Ejemplo n.º 12
0
        private SqliteTestStore CreateTransient(bool sharedCache)
        {
            _connection = new SqliteConnection(CreateConnectionString(_name, sharedCache));

            _connection.Open();

            return this.AsTransient();
        }
Ejemplo n.º 13
0
        // 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);
        }
Ejemplo n.º 14
0
 private SqliteConnection Open(string connectionString)
 {
     var connection = new SqliteConnection(connectionString);
     connection.Open();
     connection.EnableExtensions();
     connection.LoadExtension(_spatialiteExtensionName);
     return connection;
 }
        public void Ctor_sets_connection_string()
        {
            var connectionSring = "Data Source=test.db";

            var connection = new SqliteConnection(connectionSring);

            Assert.Equal(connectionSring, connection.ConnectionString);
        }
        public void ServerVersion_returns_value()
        {
            var connection = new SqliteConnection();

            var version = connection.ServerVersion;

            Assert.StartsWith("3.", version);
        }
        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);
        }
Ejemplo n.º 18
0
        public InspectionTest()
        {
            var logConn = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");

            logConn.Open();
            _insp = new JobLogDB(new FMSSettings(), logConn);
            _insp.CreateTables(firstSerialOnEmpty: null);
        }
Ejemplo n.º 19
0
 public void TestLite()
 {
     using (SqliteConnection conn = new SqliteConnection(_connectionString))
     {
         conn.Open();
         //var d = conn.Query("SELECT * FROM User;");
     }
 }
 private void ResetState()
 {
     _connection = null;
     _tableSelectionSet = null;
     _databaseModel = new DatabaseModel();
     _tables = new Dictionary<string, TableModel>(StringComparer.OrdinalIgnoreCase);
     _tableColumns = new Dictionary<string, ColumnModel>(StringComparer.OrdinalIgnoreCase);
 }
Ejemplo n.º 21
0
 public void Dispose()
 {
     if (_sqlCon != null)
     {
         _sqlCon.Dispose();
         _sqlConForDelete.Dispose();
         _sqlCon = null;
     }
 }
Ejemplo n.º 22
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "MQTTRawData.db" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);
            Debug.WriteLine($"Connecting to:{connection.ConnectionString}");

            optionsBuilder.UseSqlite(connection);
        }
Ejemplo n.º 23
0
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
      var connStringBuilder = new SqliteConnectionStringBuilder
      { DataSource = Path.Combine(_appEnv.ApplicationBasePath, _data.Configuration["App:DbFile"]) };
      var connString = connStringBuilder.ToString();
      var conn = new SqliteConnection(connString);

      optionsBuilder.UseSqlite(conn);
    }
        public void ConnectionString_gets_and_sets_value()
        {
            var connection = new SqliteConnection();
            var connectionSring = "Data Source=test.db";

            connection.ConnectionString = connectionSring;

            Assert.Equal(connectionSring, connection.ConnectionString);
        }
        public void ExecuteReader_throws_when_connection_closed()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                var ex = Assert.Throws<InvalidOperationException>(() => connection.CreateCommand().ExecuteReader());

                Assert.Equal(Strings.FormatCallRequiresOpenConnection("ExecuteReader"), ex.Message);
            }
        }
Ejemplo n.º 26
0
        private SqliteTestStore CreateTransient()
        {
            _connection = new SqliteConnection(CreateConnectionString(_name));

            _connection.Open();

            _deleteDatabase = true;

            return this;
        }
Ejemplo n.º 27
0
        private void CreateAndOpenConnection(bool sharedCache = false)
        {
            _connection = new SqliteConnection(CreateConnectionString(_name, sharedCache));

            _connection.Open();

            var command = _connection.CreateCommand();
            command.CommandText = "PRAGMA foreign_keys=ON;";
            command.ExecuteNonQuery();
        }
        protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes)
        {
            //  Return true if the file is read only, meaning we'll show the overlay.
            try
            {
                string app = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                string dbPath = Path.Combine(app, @"yliyun\db\file_status.db");
                using (SqliteConnection conn = new SqliteConnection("Data Source =" + dbPath))
                {
                    string rootDir = @"D:\一粒云盘";

                    conn.Open();

                    SqliteCommand cmd1 = new SqliteCommand("SELECT syncRoot FROM yliyun_conf", conn);

                    SqliteDataReader reader1 = cmd1.ExecuteReader();
                    if (reader1.Read())
                    {
                        rootDir = reader1.GetString(0);
                    }

                    if (path.StartsWith(Path.Combine(rootDir, @"个人空间\"))
                        || path.StartsWith(Path.Combine(rootDir, @"群组空间\"))
                        || path.StartsWith(Path.Combine(rootDir, @"部门空间\"))
                        || path.StartsWith(Path.Combine(rootDir, @"共享空间\")))
                    {
                        string sql = "SELECT lastModified FROM file_status WHERE filePath = @fp";
                        SqliteCommand cmd = new SqliteCommand(sql, conn);
                        cmd.Parameters.AddRange(new[]
                            {
                                new SqliteParameter("@fp", path)
                            });

                        SqliteDataReader reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Ejemplo n.º 29
0
        public void CreateTable()
        {
            using (Microsoft.Data.Sqlite.SqliteConnection connection = new Microsoft.Data.Sqlite.SqliteConnection(connectionString))
            {
                connection.Open();

                SqliteCommand cmd = connection.CreateCommand();
                cmd.CommandText = "CREATE TABLE IF NOT EXISTS favorite_beers(name VARCHAR(50))";
                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 30
0
        private SqliteTestStore CreateShared(Action initializeDatabase)
        {
            CreateShared(typeof(SqliteTestStore).Name + _name, initializeDatabase);

            _connection = new SqliteConnection(CreateConnectionString(_name));

            _connection.Open();
            _transaction = _connection.BeginTransaction();

            return this;
        }
Ejemplo n.º 31
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // Visual Studio 2015 | Use the LocalDb 12 instance created by Visual Studio
            //optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;");

            var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = "test254.sqlite" };
            var connectionString = connectionStringBuilder.ToString();
            var connection = new SqliteConnection(connectionString);
            
            optionsBuilder.UseSqlite(connection);
        }
        public override IModel ConstructRelationalModel([NotNull] string connectionString)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));

            var modelBuilder = new ModelBuilder(new ConventionSet());

            using (var connection = new SqliteConnection(connectionString))
            {
                connection.Open();
                var tables = new Dictionary<string, string>();
                var indexes = new List<SqliteIndexInfo>();
                var master = connection.CreateCommand();
                master.CommandText = "SELECT type, name, sql, tbl_name FROM sqlite_master";
                using (var reader = master.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var type = reader.GetString(0);
                        var name = reader.GetString(1);
                        var sql = reader.GetValue(2) as string; // can be null
                        var tableName = reader.GetString(3);

                        if (type == "table"
                            && name != "sqlite_sequence"
                            && _tableSelectionSet.Allows(TableSelection.Any, name))
                        {
                            tables.Add(name, sql);
                        }
                        else if (type == "index")
                        {
                            indexes.Add(new SqliteIndexInfo
                            {
                                Name = name,
                                TableName = tableName,
                                Sql = sql
                            });
                        }
                    }
                }

                LoadTablesAndColumns(connection, modelBuilder, tables.Keys);
                LoadIndexes(connection, modelBuilder, indexes);

                foreach (var item in tables)
                {
                    SqliteDmlParser.ParseTableDefinition(modelBuilder, item.Key, item.Value);
                }

                AddAlternateKeys(modelBuilder);
                LoadForeignKeys(connection, modelBuilder, tables.Keys);
            }

            return modelBuilder.Model;
        }
Ejemplo n.º 33
0
        public void DropTable()
        {
            using (Microsoft.Data.Sqlite.SqliteConnection connection = new Microsoft.Data.Sqlite.SqliteConnection(connectionString))
            {
                SqliteCommand cmd = connection.CreateCommand();
                cmd.CommandText = "DROP TABLE IF EXISTS favorite_beers";

                connection.Open();

                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 34
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var path       = FileSystem.Current.LocalStorage.Path;
            var connection = new Microsoft.Data.Sqlite.SqliteConnection($"Data Source= {path}/{filename}");

            connection.Open();

            var command = connection.CreateCommand();

            command.CommandText = "PRAGMA key = 'password';";
            command.ExecuteNonQuery();

            optionsBuilder.UseSqlite(connection);

            // optionsBuilder.UseSqlite($"Filename= {path}/{filename}");

            base.OnConfiguring(optionsBuilder);
        }
Ejemplo n.º 35
0
        public StorageDB(string filepath, PropertyInfo property)
        {
            _pro = property;
            if (System.IO.Directory.Exists(Path.GetDirectoryName(filepath)) == false)
            {
                System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filepath));
            }

            _sqlCon = new SQLiteConnection($"Data Source=\"{filepath}\"");
            _sqlCon.Open();
            FixFileSize();
            if (isTableExist("main") == false)
            {
                CreateTable(_pro.PropertyType);
            }

            _sqlConForDelete = new SQLiteConnection($"Data Source=\"{filepath}\"");
            _sqlConForDelete.Open();
        }
        public void GetSchemaTable_works()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();
                connection.ExecuteNonQuery(
                    "CREATE TABLE Person (ID INTEGER PRIMARY KEY, FirstName TEXT, LastName TEXT NOT NULL, Code INT UNIQUE);");
                connection.ExecuteNonQuery("INSERT INTO Person VALUES(101, 'John', 'Dee', 123);");
                connection.ExecuteNonQuery("INSERT INTO Person VALUES(105, 'Jane', 'Doe', 456);");

                using (var reader = connection.ExecuteReader("SELECT LastName, ID, Code, ID+1 AS IncID FROM Person;"))
                {
                    var schema = reader.GetSchemaTable();
                    Assert.True(schema.Columns.Contains("ColumnName"));
                    Assert.True(schema.Columns.Contains("ColumnOrdinal"));
                    Assert.True(schema.Columns.Contains("ColumnSize"));
                    Assert.True(schema.Columns.Contains("NumericPrecision"));
                    Assert.True(schema.Columns.Contains("NumericScale"));
                    Assert.True(schema.Columns.Contains("IsUnique"));
                    Assert.True(schema.Columns.Contains("IsKey"));
                    Assert.True(schema.Columns.Contains("BaseServerName"));
                    Assert.True(schema.Columns.Contains("BaseCatalogName"));
                    Assert.True(schema.Columns.Contains("BaseColumnName"));
                    Assert.True(schema.Columns.Contains("BaseSchemaName"));
                    Assert.True(schema.Columns.Contains("BaseTableName"));
                    Assert.True(schema.Columns.Contains("DataType"));
                    Assert.True(schema.Columns.Contains("DataTypeName"));
                    Assert.True(schema.Columns.Contains("AllowDBNull"));
                    Assert.True(schema.Columns.Contains("IsAliased"));
                    Assert.True(schema.Columns.Contains("IsExpression"));
                    Assert.True(schema.Columns.Contains("IsAutoIncrement"));
                    Assert.True(schema.Columns.Contains("IsLong"));

                    Assert.Equal(4, schema.Rows.Count);

                    Assert.Equal("LastName", schema.Rows[0]["ColumnName"]);
                    Assert.Equal(0, schema.Rows[0]["ColumnOrdinal"]);
                    Assert.Equal(DBNull.Value, schema.Rows[0]["ColumnSize"]);
                    Assert.Equal(DBNull.Value, schema.Rows[0]["NumericPrecision"]);
                    Assert.Equal(DBNull.Value, schema.Rows[0]["NumericScale"]);
                    Assert.False((bool)schema.Rows[0]["IsUnique"]);
                    Assert.False((bool)schema.Rows[0]["IsKey"]);
                    Assert.Equal("", schema.Rows[0]["BaseServerName"]);
                    Assert.Equal("main", schema.Rows[0]["BaseCatalogName"]);
                    Assert.Equal("LastName", schema.Rows[0]["BaseColumnName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[0]["BaseSchemaName"]);
                    Assert.Equal("Person", schema.Rows[0]["BaseTableName"]);
                    Assert.Equal(typeof(string), schema.Rows[0]["DataType"]);
                    Assert.Equal("TEXT", schema.Rows[0]["DataTypeName"]);
                    Assert.False((bool)schema.Rows[0]["AllowDBNull"]);
                    Assert.False((bool)schema.Rows[0]["IsAliased"]);
                    Assert.False((bool)schema.Rows[0]["IsExpression"]);
                    Assert.False((bool)schema.Rows[0]["IsAutoIncrement"]);
                    Assert.Equal(DBNull.Value, schema.Rows[0]["IsLong"]);

                    Assert.Equal("ID", schema.Rows[1]["ColumnName"]);
                    Assert.Equal(1, schema.Rows[1]["ColumnOrdinal"]);
                    Assert.Equal(DBNull.Value, schema.Rows[1]["ColumnSize"]);
                    Assert.Equal(DBNull.Value, schema.Rows[1]["NumericPrecision"]);
                    Assert.Equal(DBNull.Value, schema.Rows[1]["NumericScale"]);
                    Assert.False((bool)schema.Rows[1]["IsUnique"]);
                    Assert.True((bool)schema.Rows[1]["IsKey"]);
                    Assert.Equal("", schema.Rows[1]["BaseServerName"]);
                    Assert.Equal("main", schema.Rows[1]["BaseCatalogName"]);
                    Assert.Equal("ID", schema.Rows[1]["BaseColumnName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[1]["BaseSchemaName"]);
                    Assert.Equal("Person", schema.Rows[1]["BaseTableName"]);
                    Assert.Equal(typeof(long), schema.Rows[1]["DataType"]);
                    Assert.Equal("INTEGER", schema.Rows[1]["DataTypeName"]);
                    Assert.True((bool)schema.Rows[1]["AllowDBNull"]);
                    Assert.False((bool)schema.Rows[1]["IsAliased"]);
                    Assert.False((bool)schema.Rows[1]["IsExpression"]);
                    Assert.False((bool)schema.Rows[1]["IsAutoIncrement"]);
                    Assert.Equal(DBNull.Value, schema.Rows[1]["IsLong"]);

                    Assert.Equal("Code", schema.Rows[2]["ColumnName"]);
                    Assert.Equal(2, schema.Rows[2]["ColumnOrdinal"]);
                    Assert.Equal(DBNull.Value, schema.Rows[2]["ColumnSize"]);
                    Assert.Equal(DBNull.Value, schema.Rows[2]["NumericPrecision"]);
                    Assert.Equal(DBNull.Value, schema.Rows[2]["NumericScale"]);
                    Assert.True((bool)schema.Rows[2]["IsUnique"]);
                    Assert.False((bool)schema.Rows[2]["IsKey"]);
                    Assert.Equal("", schema.Rows[2]["BaseServerName"]);
                    Assert.Equal("main", schema.Rows[2]["BaseCatalogName"]);
                    Assert.Equal("Code", schema.Rows[2]["BaseColumnName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[2]["BaseSchemaName"]);
                    Assert.Equal("Person", schema.Rows[2]["BaseTableName"]);
                    Assert.Equal(typeof(long), schema.Rows[2]["DataType"]);
                    Assert.Equal("INT", schema.Rows[2]["DataTypeName"]);
                    Assert.True((bool)schema.Rows[2]["AllowDBNull"]);
                    Assert.False((bool)schema.Rows[2]["IsAliased"]);
                    Assert.False((bool)schema.Rows[2]["IsExpression"]);
                    Assert.False((bool)schema.Rows[2]["IsAutoIncrement"]);
                    Assert.Equal(DBNull.Value, schema.Rows[2]["IsLong"]);

                    Assert.Equal("IncID", schema.Rows[3]["ColumnName"]);
                    Assert.Equal(3, schema.Rows[3]["ColumnOrdinal"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["ColumnSize"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["NumericPrecision"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["NumericScale"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["IsUnique"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["IsKey"]);
                    Assert.Equal("", schema.Rows[3]["BaseServerName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["BaseCatalogName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["BaseColumnName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["BaseSchemaName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["BaseTableName"]);
                    Assert.Equal(typeof(long), schema.Rows[3]["DataType"]);
                    Assert.Equal("INTEGER", schema.Rows[3]["DataTypeName"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["AllowDBNull"]);
                    Assert.True((bool)schema.Rows[3]["IsAliased"]);
                    Assert.True((bool)schema.Rows[3]["IsExpression"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["IsAutoIncrement"]);
                    Assert.Equal(DBNull.Value, schema.Rows[3]["IsLong"]);
                }
            }
        }
Ejemplo n.º 37
0
 private void Complete()
 {
     _connection.Transaction = null;
     _connection             = null;
     _completed = true;
 }
Ejemplo n.º 38
-1
 //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);
 }
        public void Ctor_throws_when_invalid_isolation_level()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                var ex = Assert.Throws<ArgumentException>(() => connection.BeginTransaction(IsolationLevel.Snapshot));

                Assert.Equal(Strings.FormatInvalidIsolationLevel(IsolationLevel.Snapshot), ex.Message);
            }
        }
        public void ConnectionString_setter_throws_when_open()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                var ex = Assert.Throws<InvalidOperationException>(() => connection.ConnectionString = "Data Source=test.db");

                Assert.Equal(Strings.ConnectionStringRequiresClosedConnection, ex.Message);
            }
        }
        public void Can_add_extension_with_connection_using_generic_options()
        {
            var optionsBuilder = new EntityOptionsBuilder<DbContext>();
            var connection = new SqliteConnection();

            optionsBuilder.UseSqlite(connection);

            var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();

            Assert.Same(connection, extension.Connection);
            Assert.Null(extension.ConnectionString);
        }