Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable data masking #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MySqlConnector.InfoObjects;
using System;
using System.Collections.Generic;
using System.Text;

Expand Down Expand Up @@ -267,6 +268,11 @@ public Dictionary<string, string> TablesToBeExportedDic
/// </summary>
public bool InsertLineBreakBetweenInserts = false;

/// <summary>
/// Returns the row's default column value. Set this value if you wish to change the row's column value before exporting.
/// </summary>
public Func<ColumnWithValue, object> AdjustColumnValue = (ColumnWithValue columnInfo) => columnInfo.Value;

public ExportInformations()
{

Expand Down
29 changes: 26 additions & 3 deletions source code/MySqlBackup(MySqlConnector)/MySqlBackup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(")");
Expand All @@ -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));
}
}
}
Expand All @@ -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));
}
}
}
Expand Down