From 27a94a1ed8c71503aadf715f11fe6aa2cc88f657 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 1 Sep 2017 13:22:52 +0800 Subject: [PATCH] Update Core --- .../Abstract/AdoProvider/AdoProvider.cs | 22 +++++-- .../CodeFirstProvider/CodeFirstProvider.cs | 2 +- .../Abstract/EntityProvider/EntityProvider.cs | 2 +- .../InsertableProvider/InsertableProvider.cs | 30 ++++++++-- .../SqlBuilderProvider/QueryBuilder.cs | 6 +- .../UpdateProvider/UpdateableProvider.cs | 1 + .../SqlSugar/Entities/DbResult.cs | 4 +- .../ExpressionsToSql/Common/ErrorMessage.cs | 10 +++- .../Common/ExpressionConst.cs | 17 +++--- .../ExpressionsToSql/ExpressionContext.cs | 59 ++++++++++--------- .../ResolveItems/BaseResolve.cs | 34 +++++------ .../ResolveItems/BinaryExpressionResolve.cs | 20 +++---- .../ResolveItems/MemberExpressionResolve.cs | 6 +- .../MethodCallExpressionResolve.cs | 1 + .../Infrastructure/RewritableMethods.cs | 2 +- .../SqlSeverTest/SqlSugar/Interface/IAdo.cs | 1 + .../SqlSugar/Interface/Insertable.cs | 2 + .../Realization/MySql/MySqlProvider.cs | 15 +++-- .../SqlBuilder/SqlServerQueryBuilder.cs | 2 +- .../SqlServer/SqlServerProvider.cs | 9 ++- .../Realization/Sqlite/DbBind/SqliteDbBind.cs | 15 ++++- .../Realization/Sqlite/SqliteProvider.cs | 13 +++- .../SqlSeverTest/SqlSugar/SqlSugarClient.cs | 12 ++-- .../SqlSugar/Utilities/UtilConstants.cs | 25 ++++---- 24 files changed, 194 insertions(+), 116 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 6b6896682..045ab9ac8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -90,7 +90,14 @@ namespace SqlSugar { if (this.Connection.State != ConnectionState.Open) { - this.Connection.Open(); + try + { + this.Connection.Open(); + } + catch (Exception ex) + { + Check.Exception(true,ErrorMessage.ConnnectionOpen, ex.Message); + } } } @@ -151,8 +158,8 @@ namespace SqlSugar } catch (Exception ex) { - result.Exception = ex; - result.Messaage = ex.Message; + result.ErrorException = ex; + result.ErrorMessage = ex.Message; result.IsSuccess = false; this.RollbackTran(); } @@ -171,8 +178,8 @@ namespace SqlSugar } catch (Exception ex) { - result.Exception = ex; - result.Messaage = ex.Message; + result.ErrorException = ex; + result.ErrorMessage = ex.Message; result.IsSuccess = false; this.RollbackTran(); } @@ -204,6 +211,11 @@ namespace SqlSugar this.IsClearParameters = true; return result; } + public IAdo UseStoredProcedure() + { + this.CommandType = CommandType.StoredProcedure; + return this; + } #endregion #region Core diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 9fff707ec..6fc162f12 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -34,7 +34,7 @@ namespace SqlSugar { Execute(entityType); }); - Check.Exception(!executeResult.IsSuccess, executeResult.Messaage); + Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage); } public virtual void InitTables(Type[] entityTypes) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityProvider/EntityProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityProvider/EntityProvider.cs index 7efb7f819..f051010e6 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityProvider/EntityProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/EntityProvider/EntityProvider.cs @@ -97,7 +97,7 @@ namespace SqlSugar else { var mappingInfo = this.Context.MappingColumns.SingleOrDefault(it => it.EntityName == typeName && it.DbColumnName == dbColumnName); - return mappingInfo == null ? dbColumnName : mappingInfo.DbColumnName; + return mappingInfo == null ? dbColumnName : mappingInfo.PropertyName; } } public PropertyInfo GetProperty(string dbColumnName) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index 246a57c19..c86a9ee1e 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -53,16 +53,34 @@ namespace SqlSugar RestoreMapping(); return Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); } + public long ExecuteReturnBigIdentity() + { + InsertBuilder.IsReturnIdentity = true; + PreToSql(); + string sql = InsertBuilder.ToSqlString(); + RestoreMapping(); + return Convert.ToInt64( Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); + } public T ExecuteReturnEntity() + { + ExecuteCommandIdentityIntoEntity(); + return InsertObjs.First(); + } + public bool ExecuteCommandIdentityIntoEntity() { var result = InsertObjs.First(); - var identityKeys=GetIdentityKeys(); - if (identityKeys.Count == 0) return result; - var idValue = ExecuteReturnIdentity(); - Check.Exception(identityKeys.Count > 1, "ExecuteReutrnEntity does not support multiple identity keys"); + var identityKeys = GetIdentityKeys(); + if (identityKeys.Count == 0) { return this.ExecuteCommand() > 0; } + var idValue = ExecuteReturnBigIdentity(); + Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); - this.Context.EntityProvider.GetProperty(identityKey).SetValue(result,idValue,null); - return result; + object setValue= 0; + if (idValue > int.MaxValue) + setValue = idValue; + else + setValue = Convert.ToInt32(idValue); + this.Context.EntityProvider.GetProperty(identityKey).SetValue(result,setValue, null); + return idValue>0; } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs index 85f6b8840..4111a0ce9 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs @@ -236,10 +236,10 @@ namespace SqlSugar var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString); string groupByValue = GetGroupByString + HavingInfos; string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null; - if (this.IsCount) { orderByValue = null; this.OrderByValue = oldOrderBy; } + if (this.IsCount) { orderByValue = null; } sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue); - sql.Replace(UtilConstants.OrderReplace, isRowNumber ? (this.IsCount ? null : rowNumberString) : null); - if (this.IsCount) { return sql.ToString(); } + sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (this.IsCount ? null : rowNumberString) : null); + if (this.IsCount) { this.OrderByValue = oldOrderBy; return sql.ToString(); } var result = ToPageSql(sql.ToString(), this.Take, this.Skip); if (ExternalPageIndex > 0) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index 61630343b..1f953b691 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -30,6 +30,7 @@ namespace SqlSugar PreToSql(); string sql = UpdateBuilder.ToSqlString(); RestoreMapping(); + Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions"); return this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray()); } public IUpdateable AS(string tableName) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DbResult.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DbResult.cs index a2b90991d..fd6aa90e5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DbResult.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/DbResult.cs @@ -8,8 +8,8 @@ namespace SqlSugar public class DbResult { public bool IsSuccess { get; set; } - public Exception Exception { get; set; } - public string Messaage { get; set; } + public Exception ErrorException { get; set; } + public string ErrorMessage { get; set; } public T Data { get; set; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs index b8314cb20..b64176e27 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ErrorMessage.cs @@ -18,7 +18,7 @@ namespace SqlSugar { get { - return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达示格式错误,正确格式: it=>it.fieldName"); + return ErrorMessage.GetThrowMessage("Expression format error, correct format: it=>it.fieldName","表达式格式错误,正确格式: it=>it.fieldName"); } } @@ -29,5 +29,13 @@ namespace SqlSugar return ErrorMessage.GetThrowMessage("Expression parsing does not support the current function {0}. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)", "拉姆达解析不支持当前函数{0},SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)"); } } + + public static string ConnnectionOpen + { + get + { + return ErrorMessage.GetThrowMessage("Connection open error . {0}", " 连接字符串出错了,实在找不到原因请先Google错误{0}."); + } + } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs index 6420df23e..bbc5f9402 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/ExpressionConst.cs @@ -7,16 +7,13 @@ namespace SqlSugar { internal class ExpressionConst { - public const string BinaryFormatString = " ( {0} {1} {2} ) "; - public const string Format0 = "{0}"; - public const string Format1 = "$__$"; - public const string Format2 = "o__o"; - public const string Format3 = "("; - public const string Format4 = ")"; - public const string SqlFuncFullName = "SqlSugar.SqlFunc"; - public const string MethodConst = "MethodConst"; public const string Const = "Const"; - public readonly static Type MemberExpressionType = typeof(MemberExpression); - public readonly static Type ConstantExpressionType = typeof(ConstantExpression); + public const string FormatSymbol = "{0}"; + public const string RightParenthesis = ")"; + public const string LeftParenthesis = "("; + public const string MethodConst = "MethodConst"; + public const string SqlFuncFullName = "SqlSugar.SqlFunc"; + public const string BinaryFormatString = " ( {0} {1} {2} ) "; + public const string ExpressionReplace = "46450BDC-77B7-4025-B2A6-3F048CA85AD0"; } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ExpressionContext.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ExpressionContext.cs index d93a217d4..12cdb20d8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ExpressionContext.cs @@ -19,7 +19,7 @@ namespace SqlSugar private IDbMethods _DbMehtods { get; set; } #endregion - #region properties + #region Properties public IDbMethods DbMehtods { get @@ -100,22 +100,44 @@ namespace SqlSugar public virtual string SqlTranslationRight { get { return "]"; } } #endregion - #region public functions + #region Core methods + public void Resolve(Expression expression, ResolveExpressType resolveType) + { + this.ResolveType = resolveType; + this.Expression = expression; + BaseResolve resolve = new BaseResolve(new ExpressionParameter() { CurrentExpression = this.Expression, Context = this }); + resolve.Start(); + } + public void Clear() + { + base._Result = null; + base._Parameters = new List(); + } + public ExpressionContext GetCopyContext() + { + ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true); + copyContext.Index = this.Index; + copyContext.ParameterIndex = this.ParameterIndex; + return copyContext; + } + #endregion + + #region Override methods public virtual string GetTranslationTableName(string entityName, bool isMapping = true) { Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name")); if (IsTranslationText(entityName)) return entityName; isMapping = isMapping && this.MappingTables.IsValuable(); - var isComplex = entityName.Contains("."); + var isComplex = entityName.Contains(UtilConstants.Dot); if (isMapping && isComplex) { - var columnInfo = entityName.Split('.'); + var columnInfo = entityName.Split(UtilConstants.DotChar); var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase)); if (mappingInfo != null) { columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName; } - return string.Join(".", columnInfo.Select(it => GetTranslationText(it))); + return string.Join(UtilConstants.Dot, columnInfo.Select(it => GetTranslationText(it))); } else if (isMapping) { @@ -124,7 +146,7 @@ namespace SqlSugar } else if (isComplex) { - return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it))); + return string.Join(UtilConstants.Dot, entityName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it))); } else { @@ -133,15 +155,15 @@ namespace SqlSugar } public virtual string GetTranslationColumnName(string columnName) { - Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "column Name")); + Check.ArgumentNullException(columnName, string.Format(ErrorMessage.ObjNotExist, "Column Name")); if (columnName.Substring(0, 1) == this.SqlParameterKeyWord) { return columnName; } if (IsTranslationText(columnName)) return columnName; - if (columnName.Contains(".")) + if (columnName.Contains(UtilConstants.Dot)) { - return string.Join(".", columnName.Split('.').Select(it => GetTranslationText(it))); + return string.Join(UtilConstants.Dot, columnName.Split(UtilConstants.DotChar).Select(it => GetTranslationText(it))); } else { @@ -168,13 +190,6 @@ namespace SqlSugar { return SqlTranslationLeft + name + SqlTranslationRight; } - public virtual void Resolve(Expression expression, ResolveExpressType resolveType) - { - this.ResolveType = resolveType; - this.Expression = expression; - BaseResolve resolve = new BaseResolve(new ExpressionParameter() { CurrentExpression = this.Expression, Context = this }); - resolve.Start(); - } public virtual string GetAsString(string asName, string fieldValue) { if (fieldValue.Contains(".*") || fieldValue == "*") return fieldValue; @@ -191,18 +206,6 @@ namespace SqlSugar if (fieldValue.Contains(".*") || fieldValue == "*") return fieldValue; return string.Format(" {0} {1} {2} ", GetTranslationColumnName(fieldShortName + "." + fieldValue), "AS", GetTranslationColumnName(asName)); } - public virtual void Clear() - { - base._Result = null; - base._Parameters = new List(); - } - public ExpressionContext GetCopyContext() - { - ExpressionContext copyContext = (ExpressionContext)Activator.CreateInstance(this.GetType(), true); - copyContext.Index = this.Index; - copyContext.ParameterIndex = this.ParameterIndex; - return copyContext; - } #endregion } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index 10a6ba6b1..0133e1026 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -113,11 +113,11 @@ namespace SqlSugar Context.ParameterIndex++; if (isLeft == true) { - appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index; + appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index; } - if (this.Context.Result.Contains(ExpressionConst.Format0)) + if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString()); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString()); } else { @@ -132,9 +132,9 @@ namespace SqlSugar if (parameter.CurrentExpression is MethodCallExpression) { var appendValue = value; - if (this.Context.Result.Contains(ExpressionConst.Format0)) + if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - this.Context.Result.Replace(ExpressionConst.Format0, appendValue.ObjToString()); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString()); } else { @@ -159,11 +159,11 @@ namespace SqlSugar appendValue = string.Format(" {0} ", appendValue); if (isLeft == true) { - appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index; + appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index; } - if (this.Context.Result.Contains(ExpressionConst.Format0)) + if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - this.Context.Result.Replace(ExpressionConst.Format0, appendValue); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue); } else { @@ -186,11 +186,11 @@ namespace SqlSugar appendValue = string.Format(" {0} ", appendValue); if (isLeft == true) { - appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index; + appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index; } - if (this.Context.Result.Contains(ExpressionConst.Format0)) + if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - this.Context.Result.Replace(ExpressionConst.Format0, appendValue); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue); } else { @@ -209,11 +209,11 @@ namespace SqlSugar appendValue = string.Format(" {0} ", appendValue); if (isLeft == true) { - appendValue += ExpressionConst.Format1 + parameter.BaseParameter.Index; + appendValue += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index; } - if (this.Context.Result.Contains(ExpressionConst.Format0)) + if (this.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - this.Context.Result.Replace(ExpressionConst.Format0, appendValue); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue); } else { @@ -226,7 +226,7 @@ namespace SqlSugar { if (isLeft == true) { - this.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index); + this.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index); } } protected string AppendParameter(object paramterValue) @@ -238,14 +238,14 @@ namespace SqlSugar } protected void AppendNot(object Value) { - var isAppend = !this.Context.Result.Contains(ExpressionConst.Format0); + var isAppend = !this.Context.Result.Contains(ExpressionConst.FormatSymbol); if (isAppend) { this.Context.Result.Append("NOT"); } else { - this.Context.Result.Replace(ExpressionConst.Format0, "NOT"); + this.Context.Result.Replace(ExpressionConst.FormatSymbol, "NOT"); } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs index 40ade6076..d3c422165 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs @@ -22,15 +22,15 @@ namespace SqlSugar var lsrb = !leftIsBinary && rightBinary; var lbrb = rightBinary && leftIsBinary; var lsbs = !leftIsBinary && !rightBinary; - var isAppend = !base.Context.Result.Contains(ExpressionConst.Format0); + var isAppend = !base.Context.Result.Contains(ExpressionConst.FormatSymbol); if (isAppend) { - base.Context.Result.Append(ExpressionConst.Format3); - base.Context.Result.Append(ExpressionConst.Format0); + base.Context.Result.Append(ExpressionConst.LeftParenthesis); + base.Context.Result.Append(ExpressionConst.FormatSymbol); } else { - base.Context.Result.Replace(ExpressionConst.Format0, ExpressionConst.Format3 + ExpressionConst.Format0); + base.Context.Result.Replace(ExpressionConst.FormatSymbol, ExpressionConst.LeftParenthesis + ExpressionConst.FormatSymbol); } parameter.LeftExpression = leftExpression; parameter.RightExpression = rightExpression; @@ -43,18 +43,18 @@ namespace SqlSugar base.IsLeft = null; if (lsbs && parameter.ValueIsNull) { - base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, isEqual ? "IS" : "IS NOT"); - base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index+1), isEqual ? "IS" : "IS NOT"); + base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, isEqual ? "IS" : "IS NOT"); + base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index+1), isEqual ? "IS" : "IS NOT"); } else { - base.Context.Result.Replace(ExpressionConst.Format1 + parameter.Index, operatorValue); - base.Context.Result.Replace(ExpressionConst.Format1 + (parameter.Index + 1), operatorValue); + base.Context.Result.Replace(ExpressionConst.ExpressionReplace + parameter.Index, operatorValue); + base.Context.Result.Replace(ExpressionConst.ExpressionReplace + (parameter.Index + 1), operatorValue); } - base.Context.Result.Append(ExpressionConst.Format4); + base.Context.Result.Append(ExpressionConst.RightParenthesis); if (parameter.BaseExpression is BinaryExpression && parameter.IsLeft == true) { - base.Context.Result.Append(" " + ExpressionConst.Format1 + parameter.BaseParameter.Index + " "); + base.Context.Result.Append(" " + ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index + " "); } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs index 40e6ee4eb..ba824bee8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs @@ -176,11 +176,11 @@ namespace SqlSugar fieldName = string.Format(" {0} ", fieldName); if (isLeft == true) { - fieldName += ExpressionConst.Format1 + parameter.BaseParameter.Index; + fieldName += ExpressionConst.ExpressionReplace + parameter.BaseParameter.Index; } - if (base.Context.Result.Contains(ExpressionConst.Format0)) + if (base.Context.Result.Contains(ExpressionConst.FormatSymbol)) { - base.Context.Result.Replace(ExpressionConst.Format0, fieldName); + base.Context.Result.Replace(ExpressionConst.FormatSymbol, fieldName); } else { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index f6db014f2..08ec4abac 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -351,6 +351,7 @@ namespace SqlSugar case "ToTime": return this.Context.DbMehtods.ToTime(model); case "ToString": + Check.Exception(model.Args.Count > 1, "ToString (Format) is not supported, Use ToString().If time formatting can be used it.Date.Year+\"-\"+it.Data.Month+\"-\"+it.Date.Day "); return this.Context.DbMehtods.ToString(model); case "ToDecimal": return this.Context.DbMehtods.ToDecimal(model); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/RewritableMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/RewritableMethods.cs index 90ee952f8..36b171ca4 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/RewritableMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Infrastructure/RewritableMethods.cs @@ -202,7 +202,7 @@ namespace SqlSugar public T DeserializeObject(string value) { var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - return JsonConvert.DeserializeObject(value,jSetting); + return JsonConvert.DeserializeObject(value, jSetting); } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IAdo.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IAdo.cs index 44ea41fce..4506bbdc5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IAdo.cs @@ -86,5 +86,6 @@ namespace SqlSugar DbResult UseTran(Func action); void UseStoredProcedure(Action action); T UseStoredProcedure(Func action); + IAdo UseStoredProcedure(); } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs index 277a8d3ec..a722476b8 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/Insertable.cs @@ -12,6 +12,8 @@ namespace SqlSugar int ExecuteCommand(); int ExecuteReturnIdentity(); T ExecuteReturnEntity(); + bool ExecuteCommandIdentityIntoEntity(); + long ExecuteReturnBigIdentity(); IInsertable AS(string tableName); IInsertable With(string lockString); IInsertable InsertColumns(Expression> columns); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs index 978cd4190..31c86e5bb 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs @@ -17,12 +17,19 @@ namespace SqlSugar { if (base._DbConnection == null) { - var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString; - if (!mySqlConnectionString.ToLower().Contains("charset")) + try { - mySqlConnectionString=mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;"; + var mySqlConnectionString = base.Context.CurrentConnectionConfig.ConnectionString; + if (!mySqlConnectionString.ToLower().Contains("charset")) + { + mySqlConnectionString = mySqlConnectionString.Trim().TrimEnd(';') + ";charset=utf8;"; + } + base._DbConnection = new MySqlConnection(mySqlConnectionString); + } + catch (Exception ex) + { + Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message); } - base._DbConnection = new MySqlConnection(mySqlConnectionString); } return base._DbConnection; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs index d226d9ca3..d463d7ebd 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerQueryBuilder.cs @@ -12,7 +12,7 @@ namespace SqlSugar { get { - return "SELECT {0}{"+UtilConstants.OrderReplace+"} FROM {1}{2}{3}{4}"; + return "SELECT {0}{"+UtilConstants.ReplaceKey+"} FROM {1}{2}{3}{4}"; } } } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs index ace42ab1d..972af9be1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlServerProvider.cs @@ -16,7 +16,14 @@ namespace SqlSugar { if (base._DbConnection == null) { - base._DbConnection = new SqlConnection(base.Context.CurrentConnectionConfig.ConnectionString); + try + { + base._DbConnection = new SqlConnection(base.Context.CurrentConnectionConfig.ConnectionString); + } + catch (Exception ex) + { + Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message); + } } return base._DbConnection; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs index 97d7a46e6..b26114af1 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs @@ -41,11 +41,18 @@ namespace SqlSugar new KeyValuePair("nvarchar",CSharpDataType.@string), new KeyValuePair("nvarchar2",CSharpDataType.@string), new KeyValuePair("text",CSharpDataType.@string), + new KeyValuePair("ntext",CSharpDataType.@string), + new KeyValuePair("blob_text",CSharpDataType.@string), new KeyValuePair("char",CSharpDataType.@string), + new KeyValuePair("nchar",CSharpDataType.@string), new KeyValuePair("num",CSharpDataType.@string), + new KeyValuePair("currency",CSharpDataType.@string), + new KeyValuePair("datetext",CSharpDataType.@string), + new KeyValuePair("word",CSharpDataType.@string), + new KeyValuePair("graphic",CSharpDataType.@string), new KeyValuePair("tinyint",CSharpDataType.@byte), - new KeyValuePair("UNSIGNEDINTEGER8",CSharpDataType.@byte), + new KeyValuePair("unsignedinteger8",CSharpDataType.@byte), new KeyValuePair("smallint",CSharpDataType.@short), new KeyValuePair("int16",CSharpDataType.@short), new KeyValuePair("bigint",CSharpDataType.@long), @@ -58,7 +65,10 @@ namespace SqlSugar new KeyValuePair("double",CSharpDataType.@double), new KeyValuePair("float",CSharpDataType.@float), new KeyValuePair("decimal",CSharpDataType.@decimal), + new KeyValuePair("dec",CSharpDataType.@decimal), new KeyValuePair("numeric",CSharpDataType.@decimal), + new KeyValuePair("money",CSharpDataType.@decimal), + new KeyValuePair("smallmoney",CSharpDataType.@decimal), new KeyValuePair("datetime",CSharpDataType.DateTime), new KeyValuePair("timestamp",CSharpDataType.DateTime), @@ -66,9 +76,12 @@ namespace SqlSugar new KeyValuePair("time",CSharpDataType.DateTime), new KeyValuePair("blob",CSharpDataType.byteArray), + new KeyValuePair("clob",CSharpDataType.byteArray), new KeyValuePair("raw",CSharpDataType.byteArray), new KeyValuePair("oleobject",CSharpDataType.byteArray), new KeyValuePair("binary",CSharpDataType.byteArray), + new KeyValuePair("photo",CSharpDataType.byteArray), + new KeyValuePair("picture",CSharpDataType.byteArray), new KeyValuePair("varchar",CSharpDataType.Guid), new KeyValuePair("guid",CSharpDataType.Guid) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs index cd18df849..4e98f9165 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/SqliteProvider.cs @@ -16,10 +16,17 @@ namespace SqlSugar { get { - if (base._DbConnection == null) + try { - var SqliteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString; - base._DbConnection = new SqliteConnection(SqliteConnectionString); + if (base._DbConnection == null) + { + var SqliteConnectionString = base.Context.CurrentConnectionConfig.ConnectionString; + base._DbConnection = new SqliteConnection(SqliteConnectionString); + } + } + catch (Exception ex) + { + Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message); } return base._DbConnection; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs index 3202e7376..52ae2e438 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/SqlSugarClient.cs @@ -152,7 +152,7 @@ namespace SqlSugar } public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); @@ -160,7 +160,7 @@ namespace SqlSugar } public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); @@ -169,7 +169,7 @@ namespace SqlSugar #region 9-12 public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); @@ -177,7 +177,7 @@ namespace SqlSugar } public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); @@ -185,7 +185,7 @@ namespace SqlSugar } public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); @@ -193,7 +193,7 @@ namespace SqlSugar } public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { - InitMppingInfo(); + InitMppingInfo(); var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12) }; var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryJoin(joinExpression, types, queryable); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs index 23cd164d5..f89b173d9 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilConstants.cs @@ -6,31 +6,32 @@ namespace SqlSugar { internal static class UtilConstants { - + public const string Dot = "."; + public const char DotChar = '.'; internal const string Space = " "; internal const string AssemblyName = "SqlSugar"; - internal const string OrderReplace = "{$:OrderByString:$}"; + internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}"; - internal static Type StringType = typeof(string); - internal static Type ShortType = typeof(short); internal static Type IntType = typeof(int); internal static Type LongType = typeof(long); - internal static Type DecType = typeof(decimal); internal static Type GuidType = typeof(Guid); - internal static Type DateType = typeof(DateTime); - internal static Type ByteType = typeof(Byte); - internal static Type ByteArrayType = typeof(byte[]); internal static Type BoolType = typeof(bool); + internal static Type ByteType = typeof(Byte); internal static Type ObjType = typeof(object); internal static Type DobType = typeof(double); - internal static Type FloatType=typeof(float); + internal static Type FloatType = typeof(float); + internal static Type ShortType = typeof(short); + internal static Type DecType = typeof(decimal); + internal static Type StringType = typeof(string); + internal static Type DateType = typeof(DateTime); + internal static Type ByteArrayType = typeof(byte[]); internal static Type ModelType= typeof(ModelContext); - internal static Type DicSS = typeof(KeyValuePair); - internal static Type DicSi = typeof(KeyValuePair); internal static Type Dicii = typeof(KeyValuePair); + internal static Type DicIS = typeof(KeyValuePair); + internal static Type DicSi = typeof(KeyValuePair); + internal static Type DicSS = typeof(KeyValuePair); internal static Type DicOO = typeof(KeyValuePair); internal static Type DicSo = typeof(KeyValuePair); - internal static Type DicIS = typeof(KeyValuePair); internal static Type DicArraySS = typeof(Dictionary); internal static Type DicArraySO = typeof(Dictionary); }