Synchronization code

This commit is contained in:
sunkaixuan 2023-08-12 16:29:08 +08:00
parent 9695626416
commit e517e3b4de
2 changed files with 19 additions and 6 deletions

View File

@ -678,11 +678,7 @@ namespace SqlSugar
var whereSql = Regex.Replace(sql, ".* WHERE ", "", RegexOptions.Singleline);
if (IsExists(sql))
{
whereSql = Regex.Match(sql, @"\(EXISTS.+").Value;
if (sql.Contains("((EXISTS"))
{
whereSql = $"({whereSql}";
}
whereSql = UtilMethods.RemoveBeforeFirstWhere(sql);
}
dt = this.Context.Queryable<T>().Filter(null, true).Where(whereSql).AddParameters(parameters).ToDataTable();
}
@ -724,7 +720,7 @@ namespace SqlSugar
private static bool IsExists(string sql)
{
return sql.Contains("WHERE (EXISTS") || sql.Contains("((EXISTS (");
return UtilMethods.CountSubstringOccurrences(sql,"WHERE")>1;
}
private void ThrowUpdateByExpression()

View File

@ -18,6 +18,23 @@ namespace SqlSugar
{
public class UtilMethods
{
public static int CountSubstringOccurrences(string mainString, string searchString)
{
string[] substrings = mainString.Split(new string[] { searchString }, StringSplitOptions.None);
return substrings.Length - 1;
}
public static string RemoveBeforeFirstWhere(string query)
{
int whereIndex = query.IndexOf("WHERE", StringComparison.OrdinalIgnoreCase);
if (whereIndex >= 0)
{
return query.Substring(whereIndex + "WHERE".Length);
}
else
{
return query;
}
}
public static List<object> ConvertToListOfObjects(object inValues)
{
// 创建一个新的List<object>并逐个将元素转换并添加到其中