@@ -129,6 +129,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
129
129
{
130
130
var tableName = DestinationTableName ?? throw new InvalidOperationException ( "DestinationTableName must be set before calling WriteToServer" ) ;
131
131
132
+ Log . Info ( "Starting bulk copy to {0}" , tableName ) ;
132
133
var bulkLoader = new MySqlBulkLoader ( m_connection )
133
134
{
134
135
CharacterSet = "utf8mb4" ,
@@ -160,9 +161,10 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
160
161
var schema = reader . GetColumnSchema ( ) ;
161
162
for ( var i = 0 ; i < schema . Count ; i ++ )
162
163
{
164
+ var destinationColumn = reader . GetName ( i ) ;
163
165
if ( schema [ i ] . DataTypeName == "BIT" )
164
166
{
165
- AddColumnMapping ( columnMappings , addDefaultMappings , i , reader . GetName ( i ) , $ "@`\uE002 \b col{ i } `", $ "%COL% = CAST(%VAR% AS UNSIGNED)") ;
167
+ AddColumnMapping ( columnMappings , addDefaultMappings , i , destinationColumn , $ "@`\uE002 \b col{ i } `", $ "%COL% = CAST(%VAR% AS UNSIGNED)") ;
166
168
}
167
169
else if ( schema [ i ] . DataTypeName == "YEAR" )
168
170
{
@@ -174,11 +176,12 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
174
176
var type = schema [ i ] . DataType ;
175
177
if ( type == typeof ( byte [ ] ) || ( type == typeof ( Guid ) && ( m_connection . GuidFormat == MySqlGuidFormat . Binary16 || m_connection . GuidFormat == MySqlGuidFormat . LittleEndianBinary16 || m_connection . GuidFormat == MySqlGuidFormat . TimeSwapBinary16 ) ) )
176
178
{
177
- AddColumnMapping ( columnMappings , addDefaultMappings , i , reader . GetName ( i ) , $ "@`\uE002 \b col{ i } `", $ "%COL% = UNHEX(%VAR%)") ;
179
+ AddColumnMapping ( columnMappings , addDefaultMappings , i , destinationColumn , $ "@`\uE002 \b col{ i } `", $ "%COL% = UNHEX(%VAR%)") ;
178
180
}
179
181
else if ( addDefaultMappings )
180
182
{
181
- columnMappings . Add ( new MySqlBulkCopyColumnMapping ( i , reader . GetName ( i ) ) ) ;
183
+ Log . Debug ( "Adding default column mapping from SourceOrdinal {0} to DestinationColumn {1}" , i , destinationColumn ) ;
184
+ columnMappings . Add ( new MySqlBulkCopyColumnMapping ( i , destinationColumn ) ) ;
182
185
}
183
186
}
184
187
}
@@ -190,7 +193,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
190
193
var columnMapping = columnMappings . FirstOrDefault ( x => x . SourceOrdinal == i ) ;
191
194
if ( columnMapping is null )
192
195
{
193
- Log . Info ( "Ignoring column with SourceOrdinal {0}" , i ) ;
196
+ Log . Debug ( "Ignoring column with SourceOrdinal {0}" , i ) ;
194
197
bulkLoader . Columns . Add ( "@`\uE002 \b ignore`" ) ;
195
198
}
196
199
else
@@ -211,6 +214,8 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
211
214
if ( closeConnection )
212
215
m_connection . Close ( ) ;
213
216
217
+ Log . Info ( "Finished bulk copy to {0}" , tableName ) ;
218
+
214
219
#if ! NETSTANDARD2_1 && ! NETCOREAPP3_0
215
220
return default ;
216
221
#endif
@@ -225,16 +230,18 @@ static void AddColumnMapping(List<MySqlBulkCopyColumnMapping> columnMappings, bo
225
230
{
226
231
if ( columnMapping . Expression is object )
227
232
{
228
- Log . Warn ( "Column mapping for SourceOrdinal {0}, DestinationColumn {1} already has Expression {2}" , columnMapping . SourceOrdinal , columnMapping . DestinationColumn , columnMapping . Expression ) ;
233
+ Log . Warn ( "Column mapping for SourceOrdinal {0}, DestinationColumn {1} already has Expression {2}" , columnMapping . SourceOrdinal , destinationColumn , columnMapping . Expression ) ;
229
234
}
230
235
else
231
236
{
237
+ Log . Debug ( "Setting expression to map SourceOrdinal {0} to DestinationColumn {1}" , columnMapping . SourceOrdinal , destinationColumn ) ;
232
238
columnMappings . Remove ( columnMapping ) ;
233
239
columnMappings . Add ( new MySqlBulkCopyColumnMapping ( columnMapping . SourceOrdinal , variableName , expression ) ) ;
234
240
}
235
241
}
236
242
else if ( addDefaultMappings )
237
243
{
244
+ Log . Debug ( "Adding default column mapping from SourceOrdinal {0} to DestinationColumn {1}" , destinationOrdinal , destinationColumn ) ;
238
245
columnMappings . Add ( new MySqlBulkCopyColumnMapping ( destinationOrdinal , variableName , expression ) ) ;
239
246
}
240
247
}
0 commit comments