Browse Source

Update Core

pull/10/MERGE
sunkaixuna 3 years ago
parent
commit
b5886c50cc
  1. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs
  2. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs
  4. 21
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs
  5. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  6. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  7. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs
  8. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs
  9. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs
  10. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs
  11. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs
  12. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs
  13. 9
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs
  14. 5
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs
  15. 2
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs
  16. 10
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs

@ -28,6 +28,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 == "DateTimeOffset")
csharpTypeName = "DateTime";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)).ToList(); var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)).ToList();
if (mappings!=null&&mappings.Count>0) if (mappings!=null&&mappings.Count>0)
return mappings.First().Key; return mappings.First().Key;

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

@ -2597,6 +2597,7 @@ namespace SqlSugar
asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop; asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop;
asyncQueryableBuilder.Offset = this.QueryBuilder.Offset; asyncQueryableBuilder.Offset = this.QueryBuilder.Offset;
asyncQueryableBuilder.IsSqlQuery = this.QueryBuilder.IsSqlQuery; asyncQueryableBuilder.IsSqlQuery = this.QueryBuilder.IsSqlQuery;
asyncQueryableBuilder.OldSql = this.QueryBuilder.OldSql;
} }
protected int SetCacheTime(int cacheDurationInSeconds) protected int SetCacheTime(int cacheDurationInSeconds)
{ {

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/InsertBuilder.cs

@ -206,6 +206,11 @@ namespace SqlSugar
{ {
return "N'" + value.ToString().ToSqlFilter() + "'"; return "N'" + value.ToString().ToSqlFilter() + "'";
} }
else if (type == UtilConstants.DateTimeOffsetType)
{
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value);
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
}
else if (type == UtilConstants.FloatType) else if (type == UtilConstants.FloatType)
{ {
return "N'" +Convert.ToDouble(value).ToString() + "'"; return "N'" +Convert.ToDouble(value).ToString() + "'";

21
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

@ -45,7 +45,7 @@ namespace SqlSugar
public object SelectValue { get; set; } public object SelectValue { get; set; }
public string SelectCacheKey { get; set; } public string SelectCacheKey { get; set; }
public string EntityName { get; set; } public string EntityName { get; set; }
public string OldSql { get; set; }
public Type EntityType { get; set; } public Type EntityType { get; set; }
public Type ResultType { get; set; } public Type ResultType { get; set; }
@ -491,21 +491,14 @@ namespace SqlSugar
} }
public string GetSqlQuerySql(string result) public string GetSqlQuerySql(string result)
{ {
if (this.IsSqlQuery && (Skip == null && Take == null)&&(this.WhereInfos==null||this.WhereInfos.Count==0)) if (this.IsSqlQuery&&this.OldSql.HasValue() && (Skip == null && Take == null) && (this.WhereInfos == null || this.WhereInfos.Count == 0))
{ {
var old = result; return this.OldSql;
var regex = @"^SELECT .* FROM \(((.|\n|\r)*)\) t $"; }
if (this.Context.CurrentConnectionConfig.DbType .IsIn( DbType.MySql,DbType.PostgreSQL,DbType.Sqlite)) else
{ {
result = result.Substring(0,result.Length-1); return result;
}
result = System.Text.RegularExpressions.Regex.Match(result,regex).Groups[1].Value;
if (string.IsNullOrEmpty(result))
{
result = old;
}
} }
return result;
} }
#endregion #endregion

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

@ -310,6 +310,11 @@ namespace SqlSugar
{ {
return value.ObjToBool() ? "1" : "0"; return value.ObjToBool() ? "1" : "0";
} }
else if (type == UtilConstants.DateTimeOffsetType)
{
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value);
return "'" + date.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
}
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{ {
return "N'" + value.ToString().ToSqlFilter() + "'"; return "N'" + value.ToString().ToSqlFilter() + "'";

1
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -588,6 +588,7 @@ namespace SqlSugar
var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); var sqlBuilder = InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig);
var result= this.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select(sqlBuilder.GetDefaultShortName() + ".*"); var result= this.Context.Queryable<T>().AS(sqlBuilder.GetPackTable(sql, sqlBuilder.GetDefaultShortName())).With(SqlWith.Null).Select(sqlBuilder.GetDefaultShortName() + ".*");
result.QueryBuilder.IsSqlQuery = true; result.QueryBuilder.IsSqlQuery = true;
result.QueryBuilder.OldSql = sql;
return result; return result;
} }
#endregion #endregion

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

@ -878,7 +878,7 @@ namespace SqlSugar
public string GeDateFormat(string formatString, string value) public string GeDateFormat(string formatString, string value)
{ {
if (IsOracle()) if (IsOracle()||IsPg())
{ {
return $"to_char({value},'{formatString}') "; return $"to_char({value},'{formatString}') ";
} }

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs

@ -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 == "DateTimeOffset")
csharpTypeName = "DateTime";
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";
} }

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/DbBind/MySqlDbBind.cs

@ -22,6 +22,8 @@ namespace SqlSugar
csharpTypeName = "bool"; csharpTypeName = "bool";
if (csharpTypeName == "SByte") if (csharpTypeName == "SByte")
csharpTypeName = "Byte"; csharpTypeName = "Byte";
if (csharpTypeName == "DateTimeOffset")
csharpTypeName = "DateTime";
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";
} }

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/MySql/MySqlProvider.cs

@ -117,6 +117,11 @@ namespace SqlSugar
{ {
sqlParameter.DbType = System.Data.DbType.AnsiString; sqlParameter.DbType = System.Data.DbType.AnsiString;
} }
else if (parameter.DbType== System.Data.DbType.DateTimeOffset)
{
sqlParameter.Value = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)sqlParameter.Value);
sqlParameter.DbType = System.Data.DbType.DateTime;
}
++index; ++index;
} }
return result; return result;

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/DbBind/OracleDbBind.cs

@ -20,6 +20,8 @@ namespace SqlSugar
csharpTypeName = "bool"; csharpTypeName = "bool";
if (csharpTypeName == "Guid") if (csharpTypeName == "Guid")
csharpTypeName = "string"; csharpTypeName = "string";
if (csharpTypeName == "DateTimeOffset")
csharpTypeName = "DateTime";
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";
} }

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/OracleProvider.cs

@ -143,6 +143,11 @@ namespace SqlSugar
sqlParameter.DbType = System.Data.DbType.String; sqlParameter.DbType = System.Data.DbType.String;
sqlParameter.Value = sqlParameter.Value.ObjToString(); sqlParameter.Value = sqlParameter.Value.ObjToString();
} }
else if (parameter.DbType == System.Data.DbType.DateTimeOffset)
{
sqlParameter.Value = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)parameter.Value);
sqlParameter.DbType = System.Data.DbType.DateTime;
}
else if (parameter.DbType == System.Data.DbType.Boolean) else if (parameter.DbType == System.Data.DbType.Boolean)
{ {
sqlParameter.DbType = System.Data.DbType.Int16; sqlParameter.DbType = System.Data.DbType.Int16;

9
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs

@ -134,14 +134,19 @@ namespace SqlSugar
else if (type == UtilConstants.BoolType) else if (type == UtilConstants.BoolType)
{ {
return value.ObjToBool() ? "1" : "0"; return value.ObjToBool() ? "1" : "0";
}
else if (type==UtilConstants.DateTimeOffsetType)
{
var date= UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value);
return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') ";
} }
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{ {
return N+"'" + value.ToString().ToSqlFilter() + "'"; return N + "'" + value.ToString().ToSqlFilter() + "'";
} }
else else
{ {
return N+"'" + value.ToString() + "'"; return N + "'" + value.ToString() + "'";
} }
} }
} }

5
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Oracle/SqlBuilder/OracleUpdateBuilder.cs

@ -76,6 +76,11 @@ namespace SqlSugar
{ {
return value.ObjToBool() ? "1" : "0"; return value.ObjToBool() ? "1" : "0";
} }
else if (type == UtilConstants.DateTimeOffsetType)
{
var date = UtilMethods.ConvertFromDateTimeOffset((DateTimeOffset)value);
return "to_date('" + date.ToString("yyyy-MM-dd HH:mm:ss") + "', 'YYYY-MM-DD HH24:MI:SS') ";
}
else if (type == UtilConstants.StringType || type == UtilConstants.ObjType) else if (type == UtilConstants.StringType || type == UtilConstants.ObjType)
{ {
return N + "'" + value.ToString().ToSqlFilter() + "'"; return N + "'" + value.ToString().ToSqlFilter() + "'";

2
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/Sqlite/DbBind/SqliteDbBind.cs

@ -20,6 +20,8 @@ namespace SqlSugar
csharpTypeName = "long"; csharpTypeName = "long";
if (csharpTypeName == "Boolean") if (csharpTypeName == "Boolean")
csharpTypeName = "bool"; csharpTypeName = "bool";
if (csharpTypeName == "DateTimeOffset")
csharpTypeName = "DateTime";
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";
} }

10
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs

@ -17,6 +17,16 @@ namespace SqlSugar
public class UtilMethods public class UtilMethods
{ {
internal static DateTime ConvertFromDateTimeOffset(DateTimeOffset dateTime)
{
if (dateTime.Offset.Equals(TimeSpan.Zero))
return dateTime.UtcDateTime;
else if (dateTime.Offset.Equals(TimeZoneInfo.Local.GetUtcOffset(dateTime.DateTime)))
return DateTime.SpecifyKind(dateTime.DateTime, DateTimeKind.Local);
else
return dateTime.DateTime;
}
internal static object To(object value, Type destinationType) internal static object To(object value, Type destinationType)
{ {
return To(value, destinationType, CultureInfo.InvariantCulture); return To(value, destinationType, CultureInfo.InvariantCulture);

Loading…
Cancel
Save