Update Core

This commit is contained in:
sunkaixuna
2021-12-07 11:30:01 +08:00
parent 71fd340f69
commit dc2f09549b
9 changed files with 76 additions and 80 deletions

View File

@@ -1500,54 +1500,5 @@ namespace SqlSugar
return result; return result;
} }
#endregion #endregion
#region Obsolete
[Obsolete]
public virtual dynamic SqlQueryDynamic(string sql, object parameters = null)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
[Obsolete]
public virtual dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
[Obsolete]
public dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters)
{
var dt = this.GetDataTable(sql, parameters);
return dt == null ? null : this.Context.Utilities.DataTableToDynamic(dt);
}
[Obsolete]
public void UseStoredProcedure(Action action)
{
var oldCommandType = this.CommandType;
this.CommandType = CommandType.StoredProcedure;
this.IsClearParameters = false;
if (action != null)
{
action();
}
this.CommandType = oldCommandType;
this.IsClearParameters = true;
}
[Obsolete]
public T UseStoredProcedure<T>(Func<T> action)
{
T result = default(T);
var oldCommandType = this.CommandType;
this.CommandType = CommandType.StoredProcedure;
this.IsClearParameters = false;
if (action != null)
{
result = action();
}
this.CommandType = oldCommandType;
this.IsClearParameters = true;
return result;
}
#endregion
} }
} }

View File

@@ -314,7 +314,7 @@ namespace SqlSugar
{ {
get get
{ {
return new List<string>() { "int32", "datetime", "decimal", "double", "byte", "guid" }; return new List<string>() { "int32", "datetime", "decimal", "double", "byte" };
} }
} }
#endregion #endregion

View File

@@ -140,17 +140,33 @@ namespace SqlSugar
var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField); var entityPropertyName = this.Context.EntityMaintenance.GetPropertyName<T>(primaryField);
var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName); var columnInfo = EntityInfo.Columns.Single(it => it.PropertyName == entityPropertyName);
var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null); var entityValue = columnInfo.PropertyInfo.GetValue(deleteObj, null);
var tempequals = DeleteBuilder.WhereInEqualTemplate;
if (this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DisableNvarchar == true)
{
tempequals = "\"{0}\"='{1}' ";
}
if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle) if (this.Context.CurrentConnectionConfig.DbType == DbType.Oracle)
{ {
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField.ToUpper(), entityValue); if (entityValue != null && UtilMethods.GetUnderType(entityValue.GetType()) == UtilConstants.DateType)
{
andString.AppendFormat("\"{0}\"={1} ", primaryField.ToUpper(), "to_date('" + entityValue.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') ");
}
else
{
andString.AppendFormat(tempequals, primaryField.ToUpper(), entityValue);
}
} }
else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL&& (this.Context.CurrentConnectionConfig.MoreSettings==null||this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower==true)) else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL && (this.Context.CurrentConnectionConfig.MoreSettings == null || this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower == true))
{ {
andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue)); andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue));
} }
else if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer && entityValue != null && UtilMethods.GetUnderType(entityValue.GetType()) == UtilConstants.DateType)
{
andString.AppendFormat("\"{0}\"={1} ", primaryField,$"'{entityValue.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff")}'");
}
else else
{ {
andString.AppendFormat(DeleteBuilder.WhereInEqualTemplate, primaryField, entityValue); andString.AppendFormat(tempequals, primaryField, entityValue);
} }
++i; ++i;
} }

View File

@@ -65,7 +65,10 @@ namespace SqlSugar.DistributedSystem.Snowflake
// def get_timestamp() = System.currentTimeMillis // def get_timestamp() = System.currentTimeMillis
readonly object _lock = new Object(); readonly object _lock = new Object();
public long getID()
{
return NextId();
}
public virtual long NextId() public virtual long NextId()
{ {
lock(_lock) lock(_lock)

View File

@@ -8,22 +8,38 @@ namespace SqlSugar
{ {
public sealed class SnowFlakeSingle public sealed class SnowFlakeSingle
{ {
public static readonly SnowFlakeSingle instance = new SnowFlakeSingle(); private static object LockObject = new object();
private static DistributedSystem.Snowflake.IdWorker worker;
public static int WorkId = 1; public static int WorkId = 1;
public static int DatacenterId = 1; public static int DatacenterId = 1;
private SnowFlakeSingle() private SnowFlakeSingle()
{ {
worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
} }
static SnowFlakeSingle() { } static SnowFlakeSingle() { }
public static SnowFlakeSingle Instance public static DistributedSystem.Snowflake.IdWorker Instance
{ {
get { return instance; } get
{
if (worker == null)
{
lock (LockObject)
{
if (worker == null)
{
worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
}
}
}
return worker;
}
} }
private DistributedSystem.Snowflake.IdWorker worker; public static DistributedSystem.Snowflake.IdWorker instance
public long getID() {
{ get
return worker.NextId(); {
return Instance;
}
} }
} }
} }

View File

@@ -878,6 +878,30 @@ namespace SqlSugar
public string GeDateFormat(string formatString, string value) public string GeDateFormat(string formatString, string value)
{ {
if (IsOracle())
{
return $"to_char({value},'{formatString}') ";
}
else if (IsMySql()&& formatString == "yyyy-MM-dd")
{
return $"DATE_FORMAT({value}, '%Y-%m-%d')";
}
else if (formatString == "yyyy-MM-dd" && IsSqlServer())
{
return $"CONVERT(varchar(100),convert(datetime,{value}), 23)";
}
else if (formatString == "yyyy-MM-dd HH:mm:ss" && IsSqlServer())
{
return $"CONVERT(varchar(100),convert(datetime,{value}), 120)";
}
else if (formatString == "yyyy-MM-dd hh:mm:ss" && IsSqlServer())
{
return $"CONVERT(varchar(100),convert(datetime,{value}), 120)";
}
else if (formatString == "yyyy-MM-dd hh:mm:ss.ms" && IsSqlServer())
{
return $"CONVERT(varchar(100),convert(datetime,{value}), 121)";
}
var parameter = new MethodCallExpressionArgs() { IsMember = true, MemberValue = DateType.Year }; var parameter = new MethodCallExpressionArgs() { IsMember = true, MemberValue = DateType.Year };
var parameter2 = new MethodCallExpressionArgs() { IsMember = true, MemberName = value }; var parameter2 = new MethodCallExpressionArgs() { IsMember = true, MemberName = value };
var parameters = new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() { parameter2, parameter } }; var parameters = new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() { parameter2, parameter } };

View File

@@ -177,20 +177,6 @@ namespace SqlSugar
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null); Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);
Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null); Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null);
IAdo UseStoredProcedure(); IAdo UseStoredProcedure();
#region Obsolete
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
void UseStoredProcedure(Action action);
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
T UseStoredProcedure<T>(Func<T> action);
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, object whereObj = null);
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters);
[Obsolete("Use SqlQuery<dynamic>(sql)")]
dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters);
#endregion
} }
} }

View File

@@ -18,6 +18,8 @@ namespace SqlSugar
csharpTypeName = "long"; csharpTypeName = "long";
if (csharpTypeName.ToLower().IsIn("boolean", "bool")) if (csharpTypeName.ToLower().IsIn("boolean", "bool"))
csharpTypeName = "bool"; csharpTypeName = "bool";
if (csharpTypeName == "Guid")
csharpTypeName = "string";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
return mappings.HasValue() ? mappings.First().Key : "varchar"; return mappings.HasValue() ? mappings.First().Key : "varchar";
} }

View File

@@ -327,8 +327,6 @@ namespace SqlSugar
return await this.Context.Deleteable<T>().In(ids).ExecuteCommandAsync() > 0; return await this.Context.Deleteable<T>().In(ids).ExecuteCommandAsync() > 0;
} }
#endregion #endregion
[Obsolete("Use AsSugarClient()")]
public ISqlSugarClient FullClient { get { return this.Context; } }
} }
} }