mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-26 05:32:53 +08:00
Update Core
This commit is contained in:
@@ -16,10 +16,25 @@ namespace SqlSugar
|
||||
{
|
||||
#region Fields
|
||||
private bool _IsSingle = true;
|
||||
private IDbMethods _DbMehtods { get; set; }
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
public IDbMethods DbMehtods { get; set; }
|
||||
public IDbMethods DbMehtods
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DbMehtods == null)
|
||||
{
|
||||
_DbMehtods = new DefaultDbMethod();
|
||||
}
|
||||
return _DbMehtods;
|
||||
}
|
||||
set
|
||||
{
|
||||
_DbMehtods = value;
|
||||
}
|
||||
}
|
||||
public int Index { get; set; }
|
||||
public int ParameterIndex { get; set; }
|
||||
public MappingColumnList MappingColumns { get; set; }
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DefaultDbMethod : IDbMethods
|
||||
public partial class DefaultDbMethod : IDbMethods
|
||||
{
|
||||
public virtual string IIF(MethodCallExpressionModel model)
|
||||
{
|
||||
@@ -260,5 +260,15 @@ namespace SqlSugar
|
||||
var parameter1 = model.Args[1];
|
||||
return string.Format("{0}", parameter1.MemberValue);
|
||||
}
|
||||
|
||||
public virtual string True()
|
||||
{
|
||||
return "( 1 = 1 ) ";
|
||||
}
|
||||
|
||||
public virtual string False()
|
||||
{
|
||||
return "( 1 = 2 ) ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,5 +47,7 @@ namespace SqlSugar
|
||||
string AggregateMax(MethodCallExpressionModel model);
|
||||
string AggregateCount(MethodCallExpressionModel model);
|
||||
string MappingColumn(MethodCallExpressionModel model);
|
||||
string True();
|
||||
string False();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ namespace SqlSugar
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void AppendMember(ExpressionParameter parameter, bool? isLeft, object appendValue)
|
||||
{
|
||||
|
||||
@@ -197,6 +198,25 @@ namespace SqlSugar
|
||||
this.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index);
|
||||
}
|
||||
}
|
||||
protected string AppendParameter(object paramterValue)
|
||||
{
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;;
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
||||
return parameterName;
|
||||
}
|
||||
protected void AppendNot(object Value)
|
||||
{
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.Format0);
|
||||
if (isAppend)
|
||||
{
|
||||
this.Context.Result.Append("NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, "NOT");
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodCallExpressionArgs GetMethodCallArgs(ExpressionParameter parameter, Expression item)
|
||||
{
|
||||
@@ -215,23 +235,39 @@ namespace SqlSugar
|
||||
};
|
||||
return methodCallExpressionArgs;
|
||||
}
|
||||
|
||||
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string memberName)
|
||||
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
|
||||
{
|
||||
if (item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
if (item.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
else if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
|
||||
{
|
||||
var paramterValue = ExpressionTool.GetPropertyValue(item as MemberExpression);
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
||||
}
|
||||
else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
else if (item is MethodCallExpression)
|
||||
{
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||
}
|
||||
else if (item is MemberExpression)
|
||||
{
|
||||
@@ -243,7 +279,7 @@ namespace SqlSugar
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
@@ -260,17 +296,17 @@ namespace SqlSugar
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
else if (expression.Expression is ConstantExpression)
|
||||
{
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
this.Context.Result.CurrentParameter = parameter;
|
||||
this.Context.Result.IsLockCurrentParameter = true;
|
||||
@@ -278,7 +314,7 @@ namespace SqlSugar
|
||||
this.Expression = item;
|
||||
this.Start();
|
||||
parameter.IsAppendResult();
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
@@ -291,7 +327,7 @@ namespace SqlSugar
|
||||
this.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||
this.Context.ParameterIndex++;
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||
}
|
||||
}
|
||||
@@ -308,7 +344,7 @@ namespace SqlSugar
|
||||
{
|
||||
this.Context.Parameters.AddRange(newContext.Parameters);
|
||||
}
|
||||
this.Context.Result.Append(this.Context.GetAsString(memberName, newContext.Result.GetString()));
|
||||
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
|
||||
this.Context.Result.CurrentParameter = null;
|
||||
}
|
||||
}
|
||||
@@ -320,9 +356,8 @@ namespace SqlSugar
|
||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||
foreach (var property in listProperties)
|
||||
{
|
||||
if (this.Context.IgnoreComumnList != null
|
||||
&& this.Context.IgnoreComumnList.Any(
|
||||
it => it.EntityName == item.Type.Name && it.PropertyName == property.Name))
|
||||
var hasIgnore = this.Context.IgnoreComumnList != null && this.Context.IgnoreComumnList.Any(it => it.EntityName.Equals(item.Type.Name, StringComparison.CurrentCultureIgnoreCase) && it.PropertyName.Equals(property.Name, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (hasIgnore)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -332,7 +367,7 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
var asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
|
||||
asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
|
||||
var columnName = property.Name;
|
||||
if (Context.IsJoin)
|
||||
{
|
||||
@@ -350,18 +385,5 @@ namespace SqlSugar
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void AppendNot(object Value)
|
||||
{
|
||||
var isAppend = !this.Context.Result.Contains(ExpressionConst.Format0);
|
||||
if (isAppend)
|
||||
{
|
||||
this.Context.Result.Append("NOT");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.Format0, "NOT");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,13 @@ namespace SqlSugar
|
||||
{
|
||||
var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
|
||||
var parentIsRoot = parameter.BaseParameter.CurrentExpression is LambdaExpression;
|
||||
if (parentIsRoot && value != null && value.GetType() == PubConst.BoolType)
|
||||
var isBool = value != null && value.GetType() == PubConst.BoolType;
|
||||
if (parentIsRoot && isBool)
|
||||
{
|
||||
this.Context.Result.Append(value.ObjToBool() ? "( 1 = 1 ) " : "( 1 = 2 ) ");
|
||||
this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
|
||||
break;
|
||||
}
|
||||
if (parentIsBinary && value != null && value.GetType() == PubConst.BoolType && parameter.BaseExpression != null)
|
||||
if (parentIsBinary && isBool)
|
||||
{
|
||||
var isLogicOperator =
|
||||
parameter.BaseExpression.NodeType == ExpressionType.And ||
|
||||
@@ -47,7 +48,7 @@ namespace SqlSugar
|
||||
parameter.BaseExpression.NodeType == ExpressionType.OrElse;
|
||||
if (isLogicOperator)
|
||||
{
|
||||
AppendMember(parameter, isLeft, (value.ObjToBool() ? "( 1 = 1 ) " : "( 1 = 2 ) "));
|
||||
AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (isMember)
|
||||
{
|
||||
var isComparisonOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue)||baseParameter.OperatorValue.IsNullOrEmpty();
|
||||
var memberExpression = (base.Expression as MemberExpression);
|
||||
if (memberExpression.Type== PubConst.BoolType&& isComparisonOperator)
|
||||
{
|
||||
Append(parameter, nodeType);
|
||||
}
|
||||
else
|
||||
{
|
||||
Result(parameter, nodeType);
|
||||
}
|
||||
MemberLogic(parameter, baseParameter, nodeType);
|
||||
}
|
||||
else if (isConst)
|
||||
{
|
||||
@@ -59,6 +50,52 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
private void MemberLogic(ExpressionParameter parameter, ExpressionParameter baseParameter, ExpressionType nodeType)
|
||||
{
|
||||
var memberExpression = (base.Expression as MemberExpression);
|
||||
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
|
||||
var isHasValue = isLogicOperator && memberExpression.Member.Name == "HasValue" && memberExpression.Expression != null && memberExpression.NodeType == ExpressionType.MemberAccess;
|
||||
if (isHasValue)
|
||||
{
|
||||
var member = memberExpression.Expression as MemberExpression;
|
||||
parameter.CommonTempData = CommonTempDataType.Result;
|
||||
var isConst = member.Expression != null && member.Expression is ConstantExpression;
|
||||
if (isConst)
|
||||
{
|
||||
var paramterValue = ExpressionTool.DynamicInvoke(member);
|
||||
var paramterName= base.AppendParameter(paramterValue);
|
||||
var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
new MethodCallExpressionArgs() { IsMember=false, MemberName=paramterName, MemberValue=paramterValue } }
|
||||
});
|
||||
this.Context.Result.Append(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Expression = isConst ? member.Expression : member;
|
||||
this.Start();
|
||||
var methodParamter = isConst ? new MethodCallExpressionArgs() { IsMember = false } : new MethodCallExpressionArgs() { IsMember = true, MemberName = parameter.CommonTempData, MemberValue = null };
|
||||
var result = this.Context.DbMehtods.HasValue(new MethodCallExpressionModel()
|
||||
{
|
||||
Args = new List<MethodCallExpressionArgs>() {
|
||||
methodParamter
|
||||
}
|
||||
});
|
||||
this.Context.Result.Append(result);
|
||||
parameter.CommonTempData = null;
|
||||
}
|
||||
}
|
||||
else if (memberExpression.Type == PubConst.BoolType && isLogicOperator)
|
||||
{
|
||||
Append(parameter, nodeType);
|
||||
}
|
||||
else
|
||||
{
|
||||
Result(parameter, nodeType);
|
||||
}
|
||||
}
|
||||
|
||||
private void Result(ExpressionParameter parameter, ExpressionType nodeType)
|
||||
{
|
||||
BaseParameter.ChildExpression = base.Expression;
|
||||
|
||||
@@ -17,5 +17,5 @@ using System.Runtime.InteropServices;
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")]
|
||||
[assembly: AssemblyVersion("4.2.0.1")]
|
||||
[assembly: AssemblyFileVersion("4.2.0.1")]
|
||||
[assembly: AssemblyVersion("4.2.0.3")]
|
||||
[assembly: AssemblyFileVersion("4.2.0.3")]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -28,7 +29,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Common Methods
|
||||
|
||||
public override bool IsComplexModel(string sql)
|
||||
{
|
||||
return Regex.IsMatch(sql, @"AS \`\w+\.\w+\`");
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
sql = new StringBuilder();
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace SqlSugar
|
||||
|
||||
}, (cm, key) =>
|
||||
{
|
||||
string sql = "PRAGMA table_info("+tableName+")";
|
||||
string sql = "select * from " + tableName + " limit 0,1";
|
||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
using (DbDataReader reader = (SqliteDataReader)this.Context.Ado.GetDataReader(sql))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -28,7 +29,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Common Methods
|
||||
|
||||
public override bool IsComplexModel(string sql)
|
||||
{
|
||||
return Regex.IsMatch(sql, @"AS \`\w+\.\w+\`");
|
||||
}
|
||||
public override string ToSqlString()
|
||||
{
|
||||
sql = new StringBuilder();
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace SqlSugar
|
||||
{
|
||||
if (base._DbConnection == null)
|
||||
{
|
||||
var SQLiteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
base._DbConnection = new SqliteConnection(SQLiteConnectionString);
|
||||
var SqliteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString;
|
||||
base._DbConnection = new SqliteConnection(SqliteConnectionString);
|
||||
}
|
||||
return base._DbConnection;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>4.2.0.1</version>
|
||||
<version>4.2.0.3</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
||||
Reference in New Issue
Block a user