diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index fe68d7502..e5f06d829 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -73,6 +73,20 @@ namespace SqlSugar #endregion #region Connection + public virtual bool IsValidConnection() + { + try + { + using (OpenAlways()) + { + return true; + } + } + catch (Exception) + { + return false; + } + } public virtual void Open() { CheckConnection(); diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs index ad2ae3193..eecc87dba 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs @@ -164,6 +164,7 @@ namespace SqlSugar void Close(); void Open(); SugarConnection OpenAlways(); + bool IsValidConnection(); void CheckConnection(); void BeginTran(); diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs index fbd74e066..65f0db8e0 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlInsertBuilder.cs @@ -27,7 +27,8 @@ namespace SqlSugar } } } - public override object FormatValue(object value) + int i = 0; + public object FormatValue(object value,string name) { var n = "N"; if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) @@ -72,7 +73,10 @@ namespace SqlSugar } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { - return n+"'" + GetString(value).ToSqlFilter() + "'"; + ++i; + var parameterName = this.Builder.SqlParameterKeyWord + name + i; + this.Parameters.Add(new SugarParameter(parameterName, value)); + return parameterName; } else { @@ -115,7 +119,7 @@ namespace SqlSugar foreach (var item in groupList) { batchInsetrSql.Append("("); - insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value))); + insertColumns = string.Join(",", item.Select(it => FormatValue(it.Value,it.PropertyName))); batchInsetrSql.Append(insertColumns); if (groupList.Last() == item) { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs index 7ac30596c..1d702316b 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs @@ -59,7 +59,7 @@ namespace SqlSugar { updateTable.Append(SqlTemplateBatchUnion); } - updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value),this.Builder.GetTranslationColumnName(it.DbColumnName))))); + updateTable.Append("\r\n SELECT " + string.Join(",", columns.Select(it => string.Format(SqlTemplateBatchSelect, FormatValue(it.Value,it.PropertyName),this.Builder.GetTranslationColumnName(it.DbColumnName))))); ++i; } pageIndex++; @@ -89,7 +89,8 @@ namespace SqlSugar } return batchUpdateSql.ToString(); } - public override object FormatValue(object value) + int i = 0; + public object FormatValue(object value,string name) { var n = "N"; if (this.Context.CurrentConnectionConfig.MoreSettings != null&&this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar) @@ -142,7 +143,10 @@ namespace SqlSugar } else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) { - return n+"'" + GetString(value).ToSqlFilter() + "'"; + ++i; + var parameterName = this.Builder.SqlParameterKeyWord + name + i; + this.Parameters.Add(new SugarParameter(parameterName, value)); + return parameterName; } else { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs index 28e899978..23f6996e1 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/SqlBuilder/OracleExpressionContext.cs @@ -57,6 +57,11 @@ namespace SqlSugar } public partial class OracleMethod : DefaultDbMethod, IDbMethods { + public override string HasValue(MethodCallExpressionModel model) + { + var parameter = model.Args[0]; + return string.Format("( {0} IS NOT NULL ) ", parameter.MemberName); + } public override string DateDiff(MethodCallExpressionModel model) {