- 修复 MySql 字符串反斜杠无效的 bug;

This commit is contained in:
28810 2020-04-12 19:00:29 +08:00
parent bd79fc803e
commit 613940df20
15 changed files with 87 additions and 22 deletions

View File

@ -275,7 +275,7 @@ namespace FreeSql.Tests.MySqlConnector
testFieldSByteNullable = 99,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromSeconds(999),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
testFieldUInt = uint.MaxValue,
@ -288,6 +288,11 @@ namespace FreeSql.Tests.MySqlConnector
};
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -270,7 +270,7 @@ namespace FreeSql.Tests.Odbc.Dameng
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "我是中国人string",
String = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
@ -287,6 +287,11 @@ namespace FreeSql.Tests.Odbc.Dameng
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
var items = select.ToList();
}

View File

@ -98,7 +98,7 @@ namespace FreeSql.Tests.Odbc.Default
testFieldSByteNullable = sbyte.MinValue,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldUInt = uint.MaxValue,
testFieldUIntNullable = uint.MinValue,
testFieldULong = ulong.MaxValue,
@ -116,6 +116,11 @@ namespace FreeSql.Tests.Odbc.Default
var item3 = insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -244,7 +244,7 @@ namespace FreeSql.Tests.Odbc.MySql
testFieldSByteNullable = 99,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromSeconds(999),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
testFieldUInt = uint.MaxValue,
@ -263,6 +263,11 @@ namespace FreeSql.Tests.Odbc.MySql
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -270,7 +270,7 @@ namespace FreeSql.Tests.Odbc.Oracle
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "我是中国人string",
String = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
@ -287,6 +287,11 @@ namespace FreeSql.Tests.Odbc.Oracle
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
var items = select.ToList();
}

View File

@ -182,7 +182,7 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
testFieldSByteNullable = sbyte.MinValue,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人String",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromDays(1),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(90),
testFieldUInt = uint.MaxValue,
@ -200,6 +200,11 @@ namespace FreeSql.Tests.Odbc.PostgreSQL
var item3 = insert.AppendData(item2).ExecuteInserted().First();
var newitem2 = select.Where(a => a.Id == item3.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted().First();
newitem2 = select.Where(a => a.Id == item3.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -178,7 +178,7 @@ namespace FreeSql.Tests.Odbc.SqlServer
testFieldSByteNullable = sbyte.MinValue,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromSeconds(999),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
testFieldUInt = uint.MaxValue,
@ -197,7 +197,12 @@ namespace FreeSql.Tests.Odbc.SqlServer
var sqlTestUpdate = g.sqlserver.Update<TableAllType>().SetSource(item3NP).NoneParameter().ToSql();
var item3 = insert.AppendData(item2).ExecuteInserted();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
var newitem2 = select.Where(a => a.Id == item3[0].Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted();
newitem2 = select.Where(a => a.Id == item3[0].Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -266,7 +266,7 @@ namespace FreeSql.Tests.MsAccess
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "我是中国人string",
String = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
@ -279,6 +279,11 @@ namespace FreeSql.Tests.MsAccess
};
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
var items = select.ToList();
}

View File

@ -274,7 +274,7 @@ namespace FreeSql.Tests.MySql
testFieldSByteNullable = 99,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromSeconds(999),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(60),
testFieldUInt = uint.MaxValue,
@ -293,6 +293,11 @@ namespace FreeSql.Tests.MySql
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -368,7 +368,7 @@ namespace FreeSql.Tests.Oracle
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "我是中国人string",
String = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
@ -385,6 +385,11 @@ namespace FreeSql.Tests.Oracle
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
var items = select.ToList();
}

View File

@ -353,7 +353,7 @@ namespace FreeSql.Tests.PostgreSQL
testFieldShortArray = new short[] { 1, 2, 3, 4, 5 },
testFieldShortArrayNullable = new short?[] { 1, 2, 3, null, 4, 5 },
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人String",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldStringArray = new[] { "我是中国人String1", "我是中国人String2", null, "我是中国人String3" },
testFieldTimeSpan = TimeSpan.FromDays(1),
testFieldTimeSpanArray = new[] { TimeSpan.FromDays(1), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(60) },
@ -385,6 +385,11 @@ namespace FreeSql.Tests.PostgreSQL
var item3 = insert.AppendData(item2).ExecuteInserted().First();
var newitem2 = select.Where(a => a.Id == item3.Id && object.Equals(a.testFieldJToken["a"], "1")).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted().First();
newitem2 = select.Where(a => a.Id == item3.Id && object.Equals(a.testFieldJToken["a"], "1")).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -181,7 +181,7 @@ namespace FreeSql.Tests.SqlServer
testFieldSByteNullable = sbyte.MinValue,
testFieldShort = short.MaxValue,
testFieldShortNullable = short.MinValue,
testFieldString = "我是中国人string",
testFieldString = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
testFieldTimeSpan = TimeSpan.FromSeconds(999),
testFieldTimeSpanNullable = TimeSpan.FromSeconds(30),
testFieldUInt = uint.MaxValue,
@ -200,7 +200,12 @@ namespace FreeSql.Tests.SqlServer
var sqlTestUpdate = g.sqlserver.Update<TableAllType>().SetSource(item3NP).NoneParameter().ToSql();
var item3 = insert.AppendData(item2).ExecuteInserted();
var newitem2 = select.Where(a => a.Id == item3NP[0].Id).ToOne();
var newitem2 = select.Where(a => a.Id == item3[0].Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
item3 = insert.NoneParameter().AppendData(item2).ExecuteInserted();
newitem2 = select.Where(a => a.Id == item3[0].Id).ToOne();
Assert.Equal(item2.testFieldString, newitem2.testFieldString);
var items = select.ToList();
}

View File

@ -293,7 +293,7 @@ namespace FreeSql.Tests.Sqlite
SByteNullable = 99,
Short = short.MaxValue,
ShortNullable = short.MinValue,
String = "我是中国人string",
String = "ÎÒÊÇÖйúÈËstring'\\?!@#$%^&*()_+{}}{~?><<>",
TimeSpan = TimeSpan.FromSeconds(999),
TimeSpanNullable = TimeSpan.FromSeconds(60),
UInt = uint.MaxValue,
@ -306,6 +306,11 @@ namespace FreeSql.Tests.Sqlite
};
item2.Id = (int)insert.AppendData(item2).ExecuteIdentity();
var newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity();
newitem2 = select.Where(a => a.Id == item2.Id).ToOne();
Assert.Equal(item2.String, newitem2.String);
var items = select.ToList();
}

View File

@ -42,9 +42,9 @@ namespace FreeSql.MySql
if (param is bool || param is bool?)
return (bool)param ? 1 : 0;
else if (param is string || param is char)
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'"); //只有 mysql 需要处理反斜杠
else if (param is Enum)
return string.Concat("'", param.ToString().Replace("'", "''"), "'"); //((Enum)val).ToInt64();
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'"); //((Enum)val).ToInt64();
else if (decimal.TryParse(string.Concat(param), out var trydec))
return param;
else if (param is DateTime || param is DateTime?)
@ -54,11 +54,11 @@ namespace FreeSql.MySql
else if (param is byte[])
return $"0x{CommonUtils.BytesSqlRaw(param as byte[])}";
else if (param is MygisGeometry)
return string.Concat("ST_GeomFromText('", (param as MygisGeometry).AsText().Replace("'", "''"), "')");
return string.Concat("ST_GeomFromText('", (param as MygisGeometry).AsText().Replace("'", "''").Replace("\\", "\\\\"), "')");
else if (param is IEnumerable)
return AddslashesIEnumerable(param, mapType, mapColumn);
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'");
}
protected override DbCommand CreateCommand()

View File

@ -42,9 +42,9 @@ namespace FreeSql.Odbc.MySql
if (param is bool || param is bool?)
return (bool)param ? 1 : 0;
else if (param is string || param is char)
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'"); //只有 mysql 需要处理反斜杠
else if (param is Enum)
return string.Concat("'", param.ToString().Replace("'", "''"), "'"); //((Enum)val).ToInt64();
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'"); //((Enum)val).ToInt64();
else if (decimal.TryParse(string.Concat(param), out var trydec))
return param;
else if (param is DateTime || param is DateTime?)
@ -56,7 +56,7 @@ namespace FreeSql.Odbc.MySql
else if (param is IEnumerable)
return AddslashesIEnumerable(param, mapType, mapColumn);
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
return string.Concat("'", param.ToString().Replace("'", "''").Replace("\\", "\\\\"), "'");
}
protected override DbCommand CreateCommand()