Skip to content

Commit 0df985e

Browse files
committed
Fix smaller issues and add TODOs.
1 parent bdfbafa commit 0df985e

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/EFCore.Jet/Migrations/JetMigrationsSqlGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ protected override void Generate(
364364
Check.NotNull(operation, nameof(operation));
365365
Check.NotNull(builder, nameof(builder));
366366

367+
// CHECK: Rename table operations require extensions like ADOX or DAO.
368+
// A native way to do this would be to:
369+
// 1. CREATE TABLE `destination table`
370+
// 2. INSERT INTO ... SELECT ... FROM
371+
// 3. DROP TABLE `source table`
372+
// 4. Recrete indices and references.
367373
builder.Append("RENAME TABLE ")
368374
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name))
369375
.Append(" TO ")

src/System.Data.Jet/AdoxWrapper.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public static void RenameTable(string connectionString, string tableName, string
2424
}
2525
catch (Exception e)
2626
{
27+
// TODO: Try interating over the _Tables collection instead of using Item["TableName"].
28+
2729
throw new Exception("Cannot rename table", e);
2830
}
2931
finally
@@ -48,7 +50,8 @@ public static void RenameColumn(string connectionString, string tableName, strin
4850
try
4951
{
5052
using var tables = catalog.Tables;
51-
using var columns = tables[tableName].Columns;
53+
using var table = tables[tableName];
54+
using var columns = table.Columns;
5255
using var column = columns[columnName];
5356
column.Name = newColumnName;
5457
}
@@ -92,8 +95,7 @@ public static string CreateEmptyDatabase(string fileNameOrConnectionString, DbPr
9295
connection.DataAccessProviderFactory = dataAccessProviderFactory;
9396
connection.Open();
9497

95-
string sql = @"
96-
CREATE TABLE `MSysAccessStorage` (
98+
var sql = @"CREATE TABLE `MSysAccessStorage` (
9799
`DateCreate` DATETIME NULL,
98100
`DateUpdate` DATETIME NULL,
99101
`Id` COUNTER NOT NULL,
@@ -136,9 +138,9 @@ private static dynamic GetCatalogInstanceAndOpen(string errorPrefix, string conn
136138

137139
try
138140
{
139-
using dynamic cnn = new ComObject("ADODB.Connection");
140-
cnn.Open(connectionString);
141-
catalog.ActiveConnection = cnn;
141+
using dynamic connection = new ComObject("ADODB.Connection");
142+
connection.Open(connectionString);
143+
catalog.ActiveConnection = connection;
142144
}
143145
catch (Exception e)
144146
{

src/System.Data.Jet/ComObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private static object WrapIfRequired(object obj)
110110

111111
public void Dispose()
112112
{
113-
// The RCW is a .NET object and cannot be released from the finalizer anymore,
113+
// The RCW is a .NET object and cannot be released from the finalizer,
114114
// because it might not exist anymore.
115115
if (_instance != null)
116116
{

src/System.Data.Jet/JetConnection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ public static void ClearAllPools()
489489
public void CreateEmptyDatabase()
490490
=> CreateEmptyDatabase(DataSource, DataAccessProviderFactory);
491491

492+
// TODO: Use the `CREATE_DB` connection string option instead of calling ADOX when using ODBC, to create
493+
// a new database file.
494+
// Alternatively, use DAO in conjunction with ODBC.
492495
public static string CreateEmptyDatabase(string fileNameOrConnectionString, DbProviderFactory dataAccessProviderFactory)
493496
=> AdoxWrapper.CreateEmptyDatabase(fileNameOrConnectionString, dataAccessProviderFactory);
494497

src/System.Data.Jet/JetStoreSchemaDefinition/JetRenameHandling.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public static bool TryDatabaseOperation(string connectionString, string commandT
2222
{
2323
string tableName = match.Groups["tableName"].Value;
2424
string newTableName = match.Groups["newTableName"].Value;
25+
26+
// TODO: Only use ADOX in an OLE DB context. Use DAO in an ODBC context.
2527
AdoxWrapper.RenameTable(connectionString, RemoveBrackets(tableName), RemoveBrackets(newTableName));
28+
2629
return true;
2730
}
2831

0 commit comments

Comments
 (0)