The API for MySqlBulkCopy was patterned on SqlBulkCopy, which has no return value from its WriteToServer method.
#1005 points out that warnings are not surfaced to the user. MySqlBulkCopy.WriteToServer will throw if any rows fail to be inserted, but the warnings could be indications of significant data loss. You can attach an InfoMessage handler, or manually execute SHOW WARNINGS after, but it's not obvious that you should do either of those things.
The MySqlBulkCopy API should be improved to help clients use it without data loss.
One possibility would be returning a Results type, that has WarningCount, RowsCopiedCount and RowsInsertedCount. Clients could be told to check that RowsCopiedCount == RowsInsertedCount && WarningCount ==0. Getting the actual warnings would still take additional work. (Add a helper method that invokes SHOW WARNINGS; and returns an IReadOnlyList<MySqlError>?)
Or the API could return IReadOnlyList<MySqlError> and automatically call SHOW WARNINGS behind the scenes if the warning count from the operation was non-zero. However, because these aren't easily parseable (e.g., to identify the rows/cells that were wrong), it's not clear what should be done with them (display them directly to the end user?) beyond just checking if the collection is non-empty, which can be accomplished simply by checking a warning count.
The API for
MySqlBulkCopywas patterned onSqlBulkCopy, which has no return value from itsWriteToServermethod.#1005 points out that warnings are not surfaced to the user.
MySqlBulkCopy.WriteToServerwill throw if any rows fail to be inserted, but the warnings could be indications of significant data loss. You can attach anInfoMessagehandler, or manually executeSHOW WARNINGSafter, but it's not obvious that you should do either of those things.The
MySqlBulkCopyAPI should be improved to help clients use it without data loss.One possibility would be returning a
Resultstype, that hasWarningCount,RowsCopiedCountandRowsInsertedCount. Clients could be told to check thatRowsCopiedCount == RowsInsertedCount && WarningCount ==0. Getting the actual warnings would still take additional work. (Add a helper method that invokesSHOW WARNINGS;and returns anIReadOnlyList<MySqlError>?)Or the API could return
IReadOnlyList<MySqlError>and automatically callSHOW WARNINGSbehind the scenes if the warning count from the operation was non-zero. However, because these aren't easily parseable (e.g., to identify the rows/cells that were wrong), it's not clear what should be done with them (display them directly to the end user?) beyond just checking if the collection is non-empty, which can be accomplished simply by checking a warning count.