Update Core

This commit is contained in:
sunkaixuan
2018-01-15 12:56:56 +08:00
parent 15241cd4db
commit e4d1b358f3
25 changed files with 160 additions and 38 deletions

View File

@@ -266,7 +266,6 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd(sql);
return count;
}
catch (Exception ex)
@@ -278,6 +277,7 @@ namespace SqlSugar
finally
{
if (this.IsAutoClose()) this.Close();
SetConnectionEnd(sql);
}
}
public virtual IDataReader GetDataReader(string sql, params SugarParameter[] parameters)
@@ -326,7 +326,6 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd(sql);
return ds;
}
catch (Exception ex)
@@ -338,6 +337,7 @@ namespace SqlSugar
finally
{
if (this.IsAutoClose()) this.Close();
SetConnectionEnd(sql);
}
}
public virtual object GetScalar(string sql, params SugarParameter[] parameters)
@@ -356,7 +356,6 @@ namespace SqlSugar
if (this.IsClearParameters)
sqlCommand.Parameters.Clear();
ExecuteAfter(sql, parameters);
SetConnectionEnd(sql);
return scalar;
}
catch (Exception ex)
@@ -368,6 +367,7 @@ namespace SqlSugar
finally
{
if (this.IsAutoClose()) this.Close();
SetConnectionEnd(sql);
}
}
#endregion

View File

@@ -109,7 +109,7 @@ namespace SqlSugar
{
if (!ReaderKeys.Contains(mappInfo.DbColumnName))
{
fileName = ReaderKeys.FirstOrDefault(it => it.Equals(mappInfo.DbColumnName, StringComparison.CurrentCultureIgnoreCase)|| it.Equals(mappInfo.PropertyName, StringComparison.CurrentCultureIgnoreCase));
fileName = ReaderKeys.First(it => it.Equals(mappInfo.DbColumnName, StringComparison.CurrentCultureIgnoreCase)|| it.Equals(mappInfo.PropertyName, StringComparison.CurrentCultureIgnoreCase));
}
else
{

View File

@@ -141,7 +141,7 @@ namespace SqlSugar
this.Context.Ado.ExecuteCommand(sql);
return true;
}
public virtual bool CreateTable(string tableName, List<DbColumnInfo> columns)
public virtual bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
{
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
string sql = GetCreateTableSql(tableName, columns);

View File

@@ -386,16 +386,20 @@ namespace SqlSugar
{
QueryBuilder.OrderByValue = QueryBuilder.DefaultOrderByTemplate;
}
QueryBuilder.Skip = 0;
QueryBuilder.Take = 1;
var reval = this.ToList();
if (reval.HasValue())
if (QueryBuilder.Skip.HasValue)
{
return reval.FirstOrDefault();
QueryBuilder.Take = 1;
return this.ToList().FirstOrDefault();
}
else
{
return default(T);
QueryBuilder.Skip = 0;
QueryBuilder.Take = 1;
var reval = this.ToList();
if (reval.HasValue())
return reval.FirstOrDefault();
else
return default(T);
}
}
public virtual T First(Expression<Func<T, bool>> expression)
@@ -1072,8 +1076,9 @@ namespace SqlSugar
private void ToSqlBefore()
{
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
if (moreSetts != null && moreSetts.IsWithNoLockQuery&&string.IsNullOrEmpty(QueryBuilder.TableWithString)) {
this.With(SqlWith.NoLock);
if (moreSetts != null && moreSetts.IsWithNoLockQuery && string.IsNullOrEmpty(QueryBuilder.TableWithString))
{
this.With(SqlWith.NoLock);
}
}

View File

@@ -210,6 +210,9 @@ namespace SqlSugar
public virtual ExpressionResult GetExpressionValue(Expression expression, ResolveExpressType resolveType)
{
ILambdaExpressions resolveExpress = this.LambdaExpressions;
if (resolveType.IsIn(ResolveExpressType.FieldSingle,ResolveExpressType.FieldMultiple,ResolveExpressType.SelectSingle, ResolveExpressType.SelectMultiple) &&(expression is LambdaExpression)&& (expression as LambdaExpression).Body is BinaryExpression) {
resolveType = resolveType.IsIn(ResolveExpressType.SelectSingle, ResolveExpressType.FieldSingle) ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
}
this.LambdaExpressions.Clear();
resolveExpress.JoinQueryInfos = Builder.QueryBuilder.JoinQueryInfos;
resolveExpress.IsSingle = IsSingle();

View File

@@ -89,5 +89,6 @@ namespace SqlSugar
}
public List<SqlFuncExternal> SqlFuncServices { get; set; }
public List<KeyValuePair<string, CSharpDataType>> AppendDataReaderTypeMappings { get; set; }
}
}

View File

@@ -10,6 +10,7 @@ namespace SqlSugar
MySql ,
SqlServer,
Sqlite,
Oracle
Oracle,
PostgreSQL
}
}

View File

@@ -264,6 +264,10 @@ namespace SqlSugar
{
this.Context.Parameters.AddRange(newContext.Parameters);
}
if (newContext.SingleTableNameSubqueryShortName.HasValue())
{
this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
}
var methodCallExpressionArgs = new MethodCallExpressionArgs()
{
IsMember = true,

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace SqlSugar
{
public class SubGroupBy : ISubOperation
{
public string Name
{
get { return "GroupBy"; }
}
public Expression Expression
{
get; set;
}
public int Sort
{
get
{
return 479;
}
}
public ExpressionContext Context
{
get; set;
}
public string GetValue(Expression expression)
{
var exp = expression as MethodCallExpression;
var argExp = exp.Arguments[0];
var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
result = result.Replace(selfParameterName, string.Empty);
return result;
}
}
}

View File

@@ -22,14 +22,31 @@ namespace SqlSugar
this.context = context;
var currentExpression = expression;
allMethods.Add(currentExpression);
if (context.IsSingle && oppsiteExpression != null&& oppsiteExpression is MemberExpression)
if (context.IsSingle && oppsiteExpression != null && oppsiteExpression is MemberExpression)
{
var childExpression = (oppsiteExpression as MemberExpression).Expression;
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
}
else if (context.IsSingle)
{
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
if (context.Expression is LambdaExpression)
{
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
}
else if (context.Expression is MethodCallExpression)
{
var meExp = ((context.Expression as MethodCallExpression).Object as MethodCallExpression).Arguments[0] as LambdaExpression;
var selfParameterName = meExp.Parameters.First().Name;
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Left as MemberExpression).Expression as ParameterExpression).Name;
if (context.SingleTableNameSubqueryShortName == selfParameterName)
{
context.SingleTableNameSubqueryShortName = (((meExp.Body as BinaryExpression).Right as MemberExpression).Expression as ParameterExpression).Name;
}
}
else
{
Check.Exception(true, "I'm sorry I can't parse the current expression");
}
}
while (currentExpression != null)
{
@@ -69,7 +86,7 @@ namespace SqlSugar
isubList.Insert(0, new SubBegin());
if (isubList.Any(it => it is SubSelect))
{
isubList.Add(new SubTop() { Context=this.context });
isubList.Add(new SubTop() { Context = this.context });
}
if (isubList.Any(it => it is SubAny || it is SubNotAny))
{

View File

@@ -26,7 +26,8 @@ namespace SqlSugar
new SubSum(){ Context=Context },
new SubAvg(){ Context=Context },
new SubOrderBy(){ Context=Context },
new SubOrderByDesc(){ Context=Context }
new SubOrderByDesc(){ Context=Context },
new SubGroupBy(){ Context=Context}
};
}

View File

@@ -17,6 +17,10 @@ namespace SqlSugar
{
return this;
}
public Subqueryable<T> GroupBy(Func<T, object> expression)
{
return this;
}
public Subqueryable<T> OrderByDesc(Func<T, object> expression)
{
return this;

View File

@@ -160,6 +160,12 @@ namespace SqlSugar
{
Dictionary<string, object> result = new Dictionary<string, object>();
var type = item.PropertyType;
if (UtilConstants.SugarType == type) {
return result;
}
if (type.FullName.IsCollectionsList()) {
return null;
}
var classProperties = type.GetProperties().ToList();
foreach (var prop in classProperties)
{

View File

@@ -64,7 +64,7 @@ namespace SqlSugar
{
var message = ErrorMessage.GetThrowMessage(
"You need to refer to Oracle.ManagedDataAccess.dll",
"需要引用ManagedDataAccess.dll请在Nuget安装最新稳定版本,如果有版本兼容问题请先删除原有引用");
"Oracle .NET Core官方驱动还没发布暂不支持Oracle");
throw new Exception(message);
}
}

View File

@@ -28,7 +28,7 @@ namespace SqlSugar
#region DDL
bool DropTable(string tableName);
bool TruncateTable(string tableName);
bool CreateTable(string tableName, List<DbColumnInfo> columns);
bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true);
bool AddColumn(string tableName, DbColumnInfo column);
bool UpdateColumn(string tableName, DbColumnInfo column);
bool AddPrimaryKey(string tableName,string columnName);

View File

@@ -27,8 +27,18 @@ namespace SqlSugar
{
get
{
return new List<KeyValuePair<string, CSharpDataType>>()
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
{
return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
}
else
{
return MappingTypesConst;
}
}
}
public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>(){
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("mediumint",CSharpDataType.@int),
@@ -71,13 +81,11 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
};
}
}
public override List<string> StringThrow
{
get
{
return new List<string>() { "int32", "datetime", "decimal", "double", "byte"};
return new List<string>() { "int32", "datetime", "decimal", "double", "byte" };
}
}
}

View File

@@ -179,7 +179,7 @@ namespace SqlSugar
#endregion
#region Methods
public override bool CreateTable(string tableName, List<DbColumnInfo> columns)
public override bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true)
{
if (columns.HasValue())
{

View File

@@ -10,7 +10,18 @@ namespace SqlSugar
{
get
{
return new List<KeyValuePair<string, CSharpDataType>>()
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (extService != null&& extService.AppendDataReaderTypeMappings.HasValue())
{
return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
}
else
{
return MappingTypesConst;
}
}
}
public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
@@ -26,7 +37,7 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("smalldatetime",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("datetime2",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
@@ -45,7 +56,6 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("varbinary",CSharpDataType.byteArray),
new KeyValuePair<string, CSharpDataType>("datetimeoffset", CSharpDataType.DateTimeOffset),
new KeyValuePair<string, CSharpDataType>("datetimeoffset", CSharpDataType.DateTime)};
}
}
}
};
}

View File

@@ -22,12 +22,23 @@ namespace SqlSugar
csharpTypeName = "bool";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
return mappings.HasValue() ? mappings.First().Key : "varchar";
}
}
public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
{
get
{
return new List<KeyValuePair<string, CSharpDataType>>()
var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
{
return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
}
else
{
return MappingTypesConst;
}
}
}
public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>()
{
new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
@@ -87,9 +98,7 @@ namespace SqlSugar
new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
new KeyValuePair<string, CSharpDataType>("guid",CSharpDataType.Guid)
};
}
}
};
public override List<string> StringThrow
{
get

View File

@@ -206,7 +206,7 @@ namespace SqlSugar
});
}
public override bool CreateTable(string tableName, List<DbColumnInfo> columns)
public override bool CreateTable(string tableName, List<DbColumnInfo> columns,bool isCreatePrimaryKey=true)
{
if (columns.HasValue())
{

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.6.3.1</Version>
<Version>4.6.4.1</Version>
<Copyright>sun_kai_xuan</Copyright>
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
@@ -20,4 +20,9 @@
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Realization\PostgreSQL\DbMaintenance\" />
<Folder Include="Realization\PostgreSQL\SqlBuilder\" />
</ItemGroup>
</Project>

View File

@@ -37,6 +37,8 @@ namespace SqlSugar
case DbType.Oracle:
DependencyManagement.TryOracle();
break;
case DbType.PostgreSQL:
throw new Exception("Development 50%");
default:
throw new Exception("ConnectionConfig.DbType is null");
}

View File

@@ -2,7 +2,7 @@
<package >
<metadata>
<id>sqlSugarCore</id>
<version>4.6.3.1</version>
<version>4.6.4.1</version>
<authors>sunkaixuan</authors>
<owners>Landa</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>

View File

@@ -37,5 +37,7 @@ namespace SqlSugar
internal static Type DicSo = typeof(KeyValuePair<string, object>);
internal static Type DicArraySS = typeof(Dictionary<string, string>);
internal static Type DicArraySO = typeof(Dictionary<string, object>);
public static Type SugarType = typeof(SqlSugarClient);
}
}