diff --git a/source code/MySqlBackup(MySqlConnector)/InfoObjects/ColumnInfo.cs b/source code/MySqlBackup(MySqlConnector)/InfoObjects/ColumnInfo.cs new file mode 100644 index 0000000..9857917 --- /dev/null +++ b/source code/MySqlBackup(MySqlConnector)/InfoObjects/ColumnInfo.cs @@ -0,0 +1,9 @@ + +namespace MySqlConnector.InfoObjects; +public class ColumnWithValue +{ + public string TableName { get; set; } + public string ColumnName { get; set; } + public string MySqlDataType { get; set; } + public object Value { get; set; } +} diff --git a/source code/MySqlBackup(MySqlConnector)/InfoObjects/ExportInformations.cs b/source code/MySqlBackup(MySqlConnector)/InfoObjects/ExportInformations.cs index 006d47a..98b66f4 100644 --- a/source code/MySqlBackup(MySqlConnector)/InfoObjects/ExportInformations.cs +++ b/source code/MySqlBackup(MySqlConnector)/InfoObjects/ExportInformations.cs @@ -1,4 +1,5 @@ -using System; +using MySqlConnector.InfoObjects; +using System; using System.Collections.Generic; using System.Text; @@ -267,6 +268,11 @@ public Dictionary TablesToBeExportedDic /// public bool InsertLineBreakBetweenInserts = false; + /// + /// Returns the row's default column value. Set this value if you wish to change the row's column value before exporting. + /// + public Func AdjustColumnValue = (ColumnWithValue columnInfo) => columnInfo.Value; + public ExportInformations() { diff --git a/source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs b/source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs index 8a34742..5043b94 100644 --- a/source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs +++ b/source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs @@ -804,8 +804,15 @@ private string Export_GetValueString(MySqlDataReader rdr, MySqlTable table) object ob = rdr[i]; var col = table.Columns[columnName]; + var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue + { + TableName = table.Name, + Value = ob, + ColumnName = columnName, + MySqlDataType = col.MySqlDataType + }); //sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col)); - sb.Append(QueryExpress.ConvertToSqlFormat(ob, true, true, col, ExportInfo.BlobExportMode)); + sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode)); } sb.AppendFormat(")"); @@ -832,8 +839,16 @@ private void Export_GetUpdateString(MySqlDataReader rdr, MySqlTable table, Strin sb.Append("`"); sb.Append(colName); sb.Append("`="); + + var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue + { + TableName = table.Name, + Value = rdr[i], + ColumnName = colName, + MySqlDataType = col.MySqlDataType + }); //sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col)); - sb.Append(QueryExpress.ConvertToSqlFormat(rdr[i], true, true, col, ExportInfo.BlobExportMode)); + sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode)); } } } @@ -858,8 +873,16 @@ private void Export_GetConditionString(MySqlDataReader rdr, MySqlTable table, St sb.Append("`"); sb.Append(colName); sb.Append("`="); + + var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue + { + TableName = table.Name, + Value = rdr[i], + ColumnName = colName, + MySqlDataType = col.MySqlDataType + }); //sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col)); - sb.Append(QueryExpress.ConvertToSqlFormat(rdr[i], true, true, col, ExportInfo.BlobExportMode)); + sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode)); } } }