Browse Source

Add check fieldname format

pull/19/head
sunkaixuan 3 years ago
parent
commit
d6e9d2cebb
  1. 2
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 2
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs
  3. 20
      Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs

2
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -735,6 +735,7 @@ namespace SqlSugar
}
public virtual ISugarQueryable<T> OrderBy(string orderFileds)
{
orderFileds = orderFileds.ToCheckField();
var orderByValue = QueryBuilder.OrderByValue;
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
{
@ -771,6 +772,7 @@ namespace SqlSugar
public virtual ISugarQueryable<T> GroupBy(string groupFileds)
{
groupFileds = groupFileds.ToCheckField();
var croupByValue = QueryBuilder.GroupByValue;
if (QueryBuilder.GroupByValue.IsNullOrEmpty())
{

2
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -160,7 +160,7 @@ namespace SqlSugar
}
string oldName = item.FieldName;
item.FieldName = GetTranslationColumnName(item.FieldName);
Check.Exception(item.FieldName.Contains("--"), "Field name is error format");
item.FieldName = item.FieldName.ToCheckField();
switch (item.ConditionalType)
{
case ConditionalType.Equal:

20
Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs

@ -47,6 +47,26 @@ namespace SqlSugar
return value;
}
/// <summary>
/// Check field format
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string ToCheckField(this string value)
{
if (value != null)
{
if (value.IsContainsIn(";", "--"))
{
throw new Exception($"{value} format error ");
}
else if (value.IsContainsIn("'")&&(value.Length- value.Replace("'","").Length)%2!=0)
{
throw new Exception($"{value} format error ");
}
}
return value;
}
internal static string ToLower(this string value ,bool isAutoToLower)
{
if (value == null) return null;

Loading…
Cancel
Save