Browse Source

Update core

pull/12/MERGE
610262374@qq.com 6 years ago
parent
commit
6a08eea471
  1. 2
      Src/Asp.Net/SqlSugar/SqlSugar.nuspec
  2. 57
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs
  3. 3
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  4. 10
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  5. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  6. 7
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/MethodCallExpressionModel.cs
  7. 38
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  8. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  9. 16
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  10. 25
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  11. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs
  12. 8
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs

2
Src/Asp.Net/SqlSugar/SqlSugar.nuspec

@ -2,7 +2,7 @@
<package >
<metadata>
<id>sqlSugar</id>
<version>5.0.0.6</version>
<version>5.0.0.7</version>
<title>SqlSugar 5.0+ .Net Framework 4.5+ , SqlSugar 4.0+ .Net Framework 4.0+</title>
<authors>sun kaixuan</authors>
<owners>landa</owners>

57
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/AdoProvider/AdoProvider.cs

@ -777,45 +777,39 @@ namespace SqlSugar
result = GetData<T>(typeof(T), dataReader);
}
List<T2> result2 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T2>();
NextResult(dataReader);
result2 = GetData<T2>(typeof(T2), dataReader);
}
List<T3> result3 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T3>();
NextResult(dataReader);
result3 = GetData<T3>(typeof(T3), dataReader);
}
List<T4> result4 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T4>();
NextResult(dataReader);
result4 = GetData<T4>(typeof(T4), dataReader);
}
List<T5> result5 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T5>();
NextResult(dataReader);
result5 = GetData<T5>(typeof(T5), dataReader);
}
List<T6> result6 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T6>();
NextResult(dataReader);
result6 = GetData<T6>(typeof(T6), dataReader);
}
List<T7> result7 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T7>();
NextResult(dataReader);
result7 = GetData<T7>(typeof(T7), dataReader);
}
builder.SqlQueryBuilder.Clear();
@ -834,7 +828,6 @@ namespace SqlSugar
return Tuple.Create<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>(result, result2, result3, result4, result5, result6, result7);
}
}
public virtual Task<List<T>> SqlQueryAsync<T>(string sql, object parameters = null)
{
var sugarParameters = this.GetParameters(parameters);
@ -898,45 +891,39 @@ namespace SqlSugar
result =await GetDataAsync<T>(typeof(T), dataReader);
}
List<T2> result2 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T2>();
NextResult(dataReader);
result2 = await GetDataAsync<T2>(typeof(T2), dataReader);
}
List<T3> result3 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T3>();
NextResult(dataReader);
result3 = await GetDataAsync<T3>(typeof(T3), dataReader);
}
List<T4> result4 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T4>();
NextResult(dataReader);
result4 = await GetDataAsync<T4>(typeof(T4), dataReader);
}
List<T5> result5 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T5>();
NextResult(dataReader);
result5 = await GetDataAsync<T5>(typeof(T5), dataReader);
}
List<T6> result6 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T6>();
NextResult(dataReader);
result6 = await GetDataAsync<T6>(typeof(T6), dataReader);
}
List<T7> result7 = null;
if (DbReader.HasRows)
if (NextResult(dataReader))
{
this.Context.InitMappingInfo<T7>();
NextResult(dataReader);
result7 = await GetDataAsync<T7>(typeof(T7), dataReader);
}
builder.SqlQueryBuilder.Clear();
@ -1165,17 +1152,29 @@ namespace SqlSugar
#endregion
#region Helper
private static void NextResult(IDataReader dataReader)
//private static void NextResult(IDataReader dataReader)
//{
// try
// {
// NextResult(dataReader);
// }
// catch
// {
// // Check.Exception(true, ErrorMessage.GetThrowMessage("Please reduce the number of T. Save Queue Changes queries don't have so many results", "请减少T的数量,SaveQueueChanges 查询没有这么多结果"));
// }
//}
private static bool NextResult(IDataReader dataReader)
{
try
{
dataReader.NextResult();
return dataReader.NextResult();
}
catch
catch
{
// Check.Exception(true, ErrorMessage.GetThrowMessage("Please reduce the number of T. Save Queue Changes queries don't have so many results", "请减少T的数量,SaveQueueChanges 查询没有这么多结果"));
return false;
}
}
private void ExecuteProcessingSQL(ref string sql, SugarParameter[] parameters)
{
var result = this.ProcessingEventStartingSQL(sql, parameters);

3
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -73,6 +73,9 @@ namespace SqlSugar
{
var queryable = this.Context.Queryable<T>().WithCacheIF(IsCache, CacheTime);
CopyQueryBuilder(queryable.QueryBuilder);
((QueryableProvider<T>)queryable).MapperAction = this.MapperAction;
((QueryableProvider<T>)queryable).MapperActionWithCache = this.MapperActionWithCache;
((QueryableProvider<T>)queryable).Mappers = this.Mappers;
return queryable;
}
public virtual ISugarQueryable<T> AS<T2>(string tableName)

10
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs

@ -31,6 +31,7 @@ namespace SqlSugar
public bool IsNoUpdateDefaultValue { get; set; }
public List<string> PrimaryKeys { get; set; }
public bool IsOffIdentity { get; set; }
public bool IsWhereColumns { get; set; }
public virtual string SqlTemplate
{
@ -253,6 +254,15 @@ namespace SqlSugar
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
}
}
if (PrimaryKeys.HasValue()&&IsWhereColumns)
{
foreach (var item in PrimaryKeys)
{
var isFirst = whereString == null;
whereString += (isFirst ? " WHERE " : " AND ");
whereString += Builder.GetTranslationColumnName(item) + "=" + this.Context.Ado.SqlParameterKeyWord + item;
}
}
return string.Format(SqlTemplate, GetTableNameString, columnsString, whereString);
}

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -167,6 +167,7 @@ namespace SqlSugar
public IUpdateable<T> WhereColumns(Expression<Func<T, object>> columns)
{
this.IsWhereColumns = true;
UpdateBuilder.IsWhereColumns = true;
Check.Exception(UpdateParameterIsNull == true, "Updateable<T>().Updateable is error,Use Updateable(obj).WhereColumns");
var whereColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
if (this.WhereColumnList == null) this.WhereColumnList = new List<string>();

7
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/Common/MethodCallExpressionModel.cs

@ -8,8 +8,9 @@ namespace SqlSugar
{
public class MethodCallExpressionModel
{
public List<MethodCallExpressionArgs> Args { get; set; }
public string Name { get; internal set; }
public List<MethodCallExpressionArgs> Args { get; set; }
public string Name { get; set; }
public dynamic Data { get; set; }
}
public class MethodCallExpressionArgs
@ -17,6 +18,6 @@ namespace SqlSugar
public bool IsMember { get; set; }
public object MemberName { get; set; }
public object MemberValue { get; set; }
public Type Type { get; set; }
public Type Type { get; set; }
}
}

38
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -93,6 +93,44 @@ namespace SqlSugar
}
}
public virtual string ContainsArrayUseSqlParameters(MethodCallExpressionModel model)
{
var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue;
List<object> inValues = new List<object>();
if (inValueIEnumerable != null)
{
foreach (var item in inValueIEnumerable)
{
if (item != null && item.GetType().IsEnum())
{
inValues.Add(Convert.ToInt64(item));
}
else
{
inValues.Add(item);
}
}
}
var value = model.Args[1].MemberName;
string inValueString = null;
if (inValues != null && inValues.Count > 0)
{
for (int i = 0; i < inValues.Count; i++)
{
inValueString += model.Data + "_" + i+",";
}
}
if (inValueString.IsNullOrEmpty())
{
return " (1=2) ";
}
else
{
inValueString=inValueString.TrimEnd(',');
return string.Format(" ({0} IN ({1})) ", value, inValueString);
}
}
public virtual string Equals(MethodCallExpressionModel model)
{
var parameter = model.Args[0];

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -20,6 +20,7 @@ namespace SqlSugar
string Trim(MethodCallExpressionModel model);
string Contains(MethodCallExpressionModel model);
string ContainsArray(MethodCallExpressionModel model);
string ContainsArrayUseSqlParameters(MethodCallExpressionModel model);
string Equals(MethodCallExpressionModel model);
string DateIsSameDay(MethodCallExpressionModel model);
string DateIsSameByType(MethodCallExpressionModel model);

16
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -37,9 +37,21 @@ namespace SqlSugar
{
return thisValue.Contains(parameterValue);
}
public static bool ContainsArray<T>(T[] thisValue, object parameterValue)
public static bool ContainsArray<T>(T[] thisValue, object InField)
{
return thisValue.Contains((T)parameterValue);
return thisValue.Contains((T)InField);
}
public static bool ContainsArray<T>(List<T> thisValue, object InField)
{
return thisValue.Contains((T)InField);
}
public static bool ContainsArrayUseSqlParameters<T>(List<T> thisValue, object InField)
{
return thisValue.Contains((T)InField);
}
public static bool ContainsArrayUseSqlParameters<T>(T[] thisValue, object InField)
{
return thisValue.Contains((T)InField);
}
public static bool StartsWith(string thisValue, string parameterValue)
{

25
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -1,5 +1,6 @@
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@ -539,6 +540,30 @@ namespace SqlSugar
var caResult = this.Context.DbMehtods.ContainsArray(model);
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return caResult;
case "ContainsArrayUseSqlParameters":
if (model.Args[0].MemberValue == null)
{
var first = this.Context.Parameters.FirstOrDefault(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
if (first.HasValue())
{
model.Args[0].MemberValue = first.Value;
}
}
model.Data =this.Context.SqlParameterKeyWord+"INP_"+this.Context.ParameterIndex;
this.Context.ParameterIndex++;
if (model.Args[0].MemberValue.HasValue())
{
var inValueIEnumerable = (IEnumerable)model.Args[0].MemberValue;
int i = 0;
foreach (var item in inValueIEnumerable)
{
this.Context.Parameters.Add(new SugarParameter(model.Data+"_"+i,item));
i++;
}
}
var caResult2 = this.Context.DbMehtods.ContainsArrayUseSqlParameters(model);
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[0].MemberName.ObjToString());
return caResult2;
case "Equals":
return this.Context.DbMehtods.Equals(model);
case "DateIsSame":

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/DbMaintenance/PostgreSQLDbMaintenance.cs

@ -356,7 +356,7 @@ namespace SqlSugar
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
{
return base.GetColumnInfosByTableName(tableName.ToLower(), isCache);
return base.GetColumnInfosByTableName(tableName.TrimEnd('"').TrimStart('"').ToLower(), isCache);
}
#endregion
}

8
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/PostgreSQL/Insertable/PostgreSQLInserttable.cs

@ -13,7 +13,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetPrimaryKeys().FirstOrDefault());
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetIdentityKeys().FirstOrDefault());
RestoreMapping();
var result = Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()).ObjToInt();
return result;
@ -22,7 +22,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetPrimaryKeys().FirstOrDefault());
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetIdentityKeys().FirstOrDefault());
RestoreMapping();
var obj = await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
var result = obj.ObjToInt();
@ -38,7 +38,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetPrimaryKeys().FirstOrDefault());
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetIdentityKeys().FirstOrDefault());
RestoreMapping();
var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()) ?? "0");
return result;
@ -47,7 +47,7 @@ namespace SqlSugar
{
InsertBuilder.IsReturnIdentity = true;
PreToSql();
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetPrimaryKeys().FirstOrDefault());
string sql = InsertBuilder.ToSqlString().Replace("$PrimaryKey", GetIdentityKeys().FirstOrDefault());
RestoreMapping();
var result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()) ?? "0");
return result;

Loading…
Cancel
Save