diff --git a/src/EFCore.Jet/Migrations/JetMigrationsSqlGenerator.cs b/src/EFCore.Jet/Migrations/JetMigrationsSqlGenerator.cs index c7644b6..cc11d0f 100644 --- a/src/EFCore.Jet/Migrations/JetMigrationsSqlGenerator.cs +++ b/src/EFCore.Jet/Migrations/JetMigrationsSqlGenerator.cs @@ -364,6 +364,12 @@ namespace Microsoft.EntityFrameworkCore.Migrations Check.NotNull(operation, nameof(operation)); Check.NotNull(builder, nameof(builder)); + // CHECK: Rename table operations require extensions like ADOX or DAO. + // A native way to do this would be to: + // 1. CREATE TABLE `destination table` + // 2. INSERT INTO ... SELECT ... FROM + // 3. DROP TABLE `source table` + // 4. Recrete indices and references. builder.Append("RENAME TABLE ") .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name)) .Append(" TO ") diff --git a/src/System.Data.Jet/AdoxWrapper.cs b/src/System.Data.Jet/AdoxWrapper.cs index 7fff2d2..b1f0de4 100644 --- a/src/System.Data.Jet/AdoxWrapper.cs +++ b/src/System.Data.Jet/AdoxWrapper.cs @@ -24,6 +24,8 @@ namespace System.Data.Jet } catch (Exception e) { + // TODO: Try interating over the _Tables collection instead of using Item["TableName"]. + throw new Exception("Cannot rename table", e); } finally @@ -48,7 +50,8 @@ namespace System.Data.Jet try { using var tables = catalog.Tables; - using var columns = tables[tableName].Columns; + using var table = tables[tableName]; + using var columns = table.Columns; using var column = columns[columnName]; column.Name = newColumnName; } @@ -92,8 +95,7 @@ namespace System.Data.Jet connection.DataAccessProviderFactory = dataAccessProviderFactory; connection.Open(); - string sql = @" -CREATE TABLE `MSysAccessStorage` ( + var sql = @"CREATE TABLE `MSysAccessStorage` ( `DateCreate` DATETIME NULL, `DateUpdate` DATETIME NULL, `Id` COUNTER NOT NULL, @@ -136,9 +138,9 @@ CREATE UNIQUE INDEX `ParentIdName` ON `MSysAccessStorage` (`ParentId`, `Name`);" try { - using dynamic cnn = new ComObject("ADODB.Connection"); - cnn.Open(connectionString); - catalog.ActiveConnection = cnn; + using dynamic connection = new ComObject("ADODB.Connection"); + connection.Open(connectionString); + catalog.ActiveConnection = connection; } catch (Exception e) { diff --git a/src/System.Data.Jet/ComObject.cs b/src/System.Data.Jet/ComObject.cs index 4ab5e91..a6c3676 100644 --- a/src/System.Data.Jet/ComObject.cs +++ b/src/System.Data.Jet/ComObject.cs @@ -110,7 +110,7 @@ namespace System.Data.Jet public void Dispose() { - // The RCW is a .NET object and cannot be released from the finalizer anymore, + // The RCW is a .NET object and cannot be released from the finalizer, // because it might not exist anymore. if (_instance != null) { diff --git a/src/System.Data.Jet/JetConnection.cs b/src/System.Data.Jet/JetConnection.cs index a153f86..3469052 100644 --- a/src/System.Data.Jet/JetConnection.cs +++ b/src/System.Data.Jet/JetConnection.cs @@ -489,6 +489,9 @@ namespace System.Data.Jet public void CreateEmptyDatabase() => CreateEmptyDatabase(DataSource, DataAccessProviderFactory); + // TODO: Use the `CREATE_DB` connection string option instead of calling ADOX when using ODBC, to create + // a new database file. + // Alternatively, use DAO in conjunction with ODBC. public static string CreateEmptyDatabase(string fileNameOrConnectionString, DbProviderFactory dataAccessProviderFactory) => AdoxWrapper.CreateEmptyDatabase(fileNameOrConnectionString, dataAccessProviderFactory); diff --git a/src/System.Data.Jet/JetStoreSchemaDefinition/JetRenameHandling.cs b/src/System.Data.Jet/JetStoreSchemaDefinition/JetRenameHandling.cs index a62b8c3..f9db0e0 100644 --- a/src/System.Data.Jet/JetStoreSchemaDefinition/JetRenameHandling.cs +++ b/src/System.Data.Jet/JetStoreSchemaDefinition/JetRenameHandling.cs @@ -22,7 +22,10 @@ namespace System.Data.Jet.JetStoreSchemaDefinition { string tableName = match.Groups["tableName"].Value; string newTableName = match.Groups["newTableName"].Value; + + // TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context. AdoxWrapper.RenameTable(connectionString, RemoveBrackets(tableName), RemoveBrackets(newTableName)); + return true; }