Skip to content

Commit 62548cb

Browse files
authored
Merge pull request #113 from tpflueger/master
Enable data masking
2 parents 680a15d + 8ca5f2a commit 62548cb

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace MySqlConnector.InfoObjects;
3+
public class ColumnWithValue
4+
{
5+
public string TableName { get; set; }
6+
public string ColumnName { get; set; }
7+
public string MySqlDataType { get; set; }
8+
public object Value { get; set; }
9+
}

source code/MySqlBackup(MySqlConnector)/InfoObjects/ExportInformations.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using MySqlConnector.InfoObjects;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45

@@ -267,6 +268,11 @@ public Dictionary<string, string> TablesToBeExportedDic
267268
/// </summary>
268269
public bool InsertLineBreakBetweenInserts = false;
269270

271+
/// <summary>
272+
/// Returns the row's default column value. Set this value if you wish to change the row's column value before exporting.
273+
/// </summary>
274+
public Func<ColumnWithValue, object> AdjustColumnValue = (ColumnWithValue columnInfo) => columnInfo.Value;
275+
270276
public ExportInformations()
271277
{
272278

source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,15 @@ private string Export_GetValueString(MySqlDataReader rdr, MySqlTable table)
804804
object ob = rdr[i];
805805
var col = table.Columns[columnName];
806806

807+
var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue
808+
{
809+
TableName = table.Name,
810+
Value = ob,
811+
ColumnName = columnName,
812+
MySqlDataType = col.MySqlDataType
813+
});
807814
//sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
808-
sb.Append(QueryExpress.ConvertToSqlFormat(ob, true, true, col, ExportInfo.BlobExportMode));
815+
sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode));
809816
}
810817

811818
sb.AppendFormat(")");
@@ -832,8 +839,16 @@ private void Export_GetUpdateString(MySqlDataReader rdr, MySqlTable table, Strin
832839
sb.Append("`");
833840
sb.Append(colName);
834841
sb.Append("`=");
842+
843+
var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue
844+
{
845+
TableName = table.Name,
846+
Value = rdr[i],
847+
ColumnName = colName,
848+
MySqlDataType = col.MySqlDataType
849+
});
835850
//sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
836-
sb.Append(QueryExpress.ConvertToSqlFormat(rdr[i], true, true, col, ExportInfo.BlobExportMode));
851+
sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode));
837852
}
838853
}
839854
}
@@ -858,8 +873,16 @@ private void Export_GetConditionString(MySqlDataReader rdr, MySqlTable table, St
858873
sb.Append("`");
859874
sb.Append(colName);
860875
sb.Append("`=");
876+
877+
var adjustedValue = ExportInfo.AdjustColumnValue(new InfoObjects.ColumnWithValue
878+
{
879+
TableName = table.Name,
880+
Value = rdr[i],
881+
ColumnName = colName,
882+
MySqlDataType = col.MySqlDataType
883+
});
861884
//sb.Append(QueryExpress.ConvertToSqlFormat(rdr, i, true, true, col));
862-
sb.Append(QueryExpress.ConvertToSqlFormat(rdr[i], true, true, col, ExportInfo.BlobExportMode));
885+
sb.Append(QueryExpress.ConvertToSqlFormat(adjustedValue, true, true, col, ExportInfo.BlobExportMode));
863886
}
864887
}
865888
}

0 commit comments

Comments
 (0)