@@ -129,6 +129,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
129129 {
130130 var tableName = DestinationTableName ?? throw new InvalidOperationException ( "DestinationTableName must be set before calling WriteToServer" ) ;
131131
132+ Log . Info ( "Starting bulk copy to {0}" , tableName ) ;
132133 var bulkLoader = new MySqlBulkLoader ( m_connection )
133134 {
134135 CharacterSet = "utf8mb4" ,
@@ -160,9 +161,10 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
160161 var schema = reader . GetColumnSchema ( ) ;
161162 for ( var i = 0 ; i < schema . Count ; i ++ )
162163 {
164+ var destinationColumn = reader . GetName ( i ) ;
163165 if ( schema [ i ] . DataTypeName == "BIT" )
164166 {
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)") ;
166168 }
167169 else if ( schema [ i ] . DataTypeName == "YEAR" )
168170 {
@@ -174,11 +176,12 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
174176 var type = schema [ i ] . DataType ;
175177 if ( type == typeof ( byte [ ] ) || ( type == typeof ( Guid ) && ( m_connection . GuidFormat == MySqlGuidFormat . Binary16 || m_connection . GuidFormat == MySqlGuidFormat . LittleEndianBinary16 || m_connection . GuidFormat == MySqlGuidFormat . TimeSwapBinary16 ) ) )
176178 {
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%)") ;
178180 }
179181 else if ( addDefaultMappings )
180182 {
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 ) ) ;
182185 }
183186 }
184187 }
@@ -190,7 +193,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
190193 var columnMapping = columnMappings . FirstOrDefault ( x => x . SourceOrdinal == i ) ;
191194 if ( columnMapping is null )
192195 {
193- Log . Info ( "Ignoring column with SourceOrdinal {0}" , i ) ;
196+ Log . Debug ( "Ignoring column with SourceOrdinal {0}" , i ) ;
194197 bulkLoader . Columns . Add ( "@`\uE002 \b ignore`" ) ;
195198 }
196199 else
@@ -211,6 +214,8 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
211214 if ( closeConnection )
212215 m_connection . Close ( ) ;
213216
217+ Log . Info ( "Finished bulk copy to {0}" , tableName ) ;
218+
214219#if ! NETSTANDARD2_1 && ! NETCOREAPP3_0
215220 return default ;
216221#endif
@@ -225,16 +230,18 @@ static void AddColumnMapping(List<MySqlBulkCopyColumnMapping> columnMappings, bo
225230 {
226231 if ( columnMapping . Expression is object )
227232 {
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 ) ;
229234 }
230235 else
231236 {
237+ Log . Debug ( "Setting expression to map SourceOrdinal {0} to DestinationColumn {1}" , columnMapping . SourceOrdinal , destinationColumn ) ;
232238 columnMappings . Remove ( columnMapping ) ;
233239 columnMappings . Add ( new MySqlBulkCopyColumnMapping ( columnMapping . SourceOrdinal , variableName , expression ) ) ;
234240 }
235241 }
236242 else if ( addDefaultMappings )
237243 {
244+ Log . Debug ( "Adding default column mapping from SourceOrdinal {0} to DestinationColumn {1}" , destinationOrdinal , destinationColumn ) ;
238245 columnMappings . Add ( new MySqlBulkCopyColumnMapping ( destinationOrdinal , variableName , expression ) ) ;
239246 }
240247 }
0 commit comments