public override void OpenConnection() { Connection.Open(); ((SqliteConnection)Connection).EnableExtensions(); SpatialiteLoader.TryLoad(Connection); }
protected override void OpenConnection(IRelationalConnection connection) { connection.Open(); ((SqliteConnection)connection.DbConnection).EnableExtensions(); SpatialiteLoader.TryLoad(connection.DbConnection); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public override DatabaseModel Create(DbConnection connection, DatabaseModelFactoryOptions options) { Check.NotNull(connection, nameof(connection)); Check.NotNull(options, nameof(options)); if (options.Schemas.Any()) { _logger.SchemasNotSupportedWarning(); } var databaseModel = new DatabaseModel(); var connectionStartedOpen = connection.State == ConnectionState.Open; if (!connectionStartedOpen) { connection.Open(); if (HasGeometryColumns(connection)) { SpatialiteLoader.TryLoad(connection); } } try { databaseModel.DatabaseName = GetDatabaseName(connection); GetTables(connection, databaseModel, options.Tables); foreach (var table in databaseModel.Tables) { GetForeignKeys(connection, table, databaseModel.Tables); } var nullableKeyColumns = databaseModel.Tables .SelectMany(t => t.PrimaryKey?.Columns ?? Array.Empty <DatabaseColumn>()) .Concat(databaseModel.Tables.SelectMany(t => t.ForeignKeys).SelectMany(fk => fk.PrincipalColumns)) .Where(c => c.IsNullable) .Distinct(); foreach (var column in nullableKeyColumns) { // TODO: Consider warning column.IsNullable = false; } } finally { if (!connectionStartedOpen) { connection.Close(); } } return(databaseModel); }
public override void OpenConnection() { Connection.Open(); ((SqliteConnection)Connection).EnableExtensions(); SpatialiteLoader.TryLoad(Connection); using (var command = Connection.CreateCommand()) { command.CommandText = "PRAGMA foreign_keys=ON;"; command.ExecuteNonQuery(); } }
private SqliteTestStore(string name, bool seed = true, bool sharedCache = true, bool shared = true) : base(name, shared) { _seed = seed; ConnectionString = new SqliteConnectionStringBuilder { DataSource = Name + ".db", Cache = sharedCache ? SqliteCacheMode.Shared : SqliteCacheMode.Private }.ToString(); var connection = new SqliteConnection(ConnectionString); SpatialiteLoader.TryLoad(connection); Connection = connection; }
/// <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(DbConnection connection, IEnumerable <string> tables, IEnumerable <string> schemas) { Check.NotNull(connection, nameof(connection)); Check.NotNull(tables, nameof(tables)); Check.NotNull(schemas, nameof(schemas)); if (schemas.Any()) { _logger.SchemasNotSupportedWarning(); } var databaseModel = new DatabaseModel(); var connectionStartedOpen = connection.State == ConnectionState.Open; if (!connectionStartedOpen) { connection.Open(); SpatialiteLoader.TryLoad((SqliteConnection)connection); } try { databaseModel.DatabaseName = GetDatabaseName(connection); foreach (var table in GetTables(connection, tables)) { table.Database = databaseModel; databaseModel.Tables.Add(table); } foreach (var table in databaseModel.Tables) { foreach (var foreignKey in GetForeignKeys(connection, table, databaseModel.Tables)) { foreignKey.Table = table; table.ForeignKeys.Add(foreignKey); } } var nullableKeyColumns = databaseModel.Tables .Where(t => t.PrimaryKey != null).SelectMany(t => t.PrimaryKey.Columns) .Concat(databaseModel.Tables.SelectMany(t => t.ForeignKeys).SelectMany(fk => fk.PrincipalColumns)) .Where(c => c.IsNullable) .Distinct(); foreach (var column in nullableKeyColumns) { // TODO: Consider warning column.IsNullable = false; } } finally { if (!connectionStartedOpen) { connection.Close(); } } return(databaseModel); }
protected override void OpenConnection(IRelationalConnection connection) { connection.Open(); SpatialiteLoader.TryLoad(connection.DbConnection); }