Browse Source

Support pgsql dictionary null

pull/23/MERGE
sunkaixuan 2 years ago
parent
commit
bb23883a7d
  1. 11
      Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs
  2. 10
      Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs
  3. 9
      Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs
  4. 1
      Src/Asp.Net/SqlSugar/Interface/IDbBind.cs
  5. 6
      Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLBuilder.cs
  6. 97
      Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

11
Src/Asp.Net/SqlSugar/Abstract/DbBindProvider/DbBindProvider.cs

@ -41,6 +41,17 @@ namespace SqlSugar
var mappings = this.MappingTypes.Where(it => it.Key == dbTypeName);
return mappings.HasValue() ? mappings.First().Key : "string";
}
public string GetCsharpTypeNameByDbTypeName(string dbTypeName)
{
var mappings = this.MappingTypes.Where(it => it.Key == dbTypeName);
if (mappings == null || mappings.Count() == 0)
{
return "string";
}
var result = mappings.First().Value.ObjToString();
return result;
}
public virtual string GetConvertString(string dbTypeName)
{
string result = string.Empty;

10
Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableHelper.cs

@ -103,6 +103,7 @@ namespace SqlSugar
#endregion
if (this.IsSingle)
{
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
foreach (var item in this.InsertBuilder.DbColumnInfoList)
{
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
@ -119,6 +120,15 @@ namespace SqlSugar
{
paramters.IsArray = true;
}
if (item.Value == null && isDic)
{
var type = this.SqlBuilder.GetNullType(this.InsertBuilder.GetTableNameString, item.DbColumnName);
if (type != null)
{
paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, type);
}
}
this.InsertBuilder.Parameters.Add(paramters);
}
}

9
Src/Asp.Net/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs

@ -268,6 +268,7 @@ namespace SqlSugar
#endregion
if (this.IsSingle)
{
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
{
if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List<SugarParameter>();
@ -284,6 +285,14 @@ namespace SqlSugar
{
parameter.IsArray = true;
}
if (item.Value == null && isDic)
{
var type = this.SqlBuilder.GetNullType(this.UpdateBuilder.GetTableNameString, item.DbColumnName);
if (type != null)
{
parameter = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, type);
}
}
this.UpdateBuilder.Parameters.Add(parameter);
}
}

1
Src/Asp.Net/SqlSugar/Interface/IDbBind.cs

@ -21,6 +21,7 @@ namespace SqlSugar
string GetConvertString(string dbTypeName);
string GetDbTypeName(string csharpTypeName);
string GetCsharpTypeName(string dbTypeName);
string GetCsharpTypeNameByDbTypeName(string dbTypeName);
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
List<T> DataReaderToList<T>(Type type, IDataReader reader);
Task<List<T>> DataReaderToListAsync<T>(Type entityType, IDataReader dataReader);

6
Src/Asp.Net/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLBuilder.cs

@ -108,12 +108,12 @@ namespace SqlSugar
var columnInfo=this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).FirstOrDefault(z => z.DbColumnName.EqualCase(columnName));
if (columnInfo != null)
{
var cTypeName=this.Context.Ado.DbBind.GetCsharpTypeName(UtilConstants.StringType.Name);
var value=UtilMethods.ConvertDataByTypeName(cTypeName, "");
var cTypeName=this.Context.Ado.DbBind.GetCsharpTypeNameByDbTypeName(columnInfo.DataType);
var value=UtilMethods.GetTypeByTypeName(cTypeName);
if (value != null)
{
var key = "GetNullType_" + tableName + columnName;
return new ReflectionInoCacheService().GetOrCreate(key, () => value.GetType());
return new ReflectionInoCacheService().GetOrCreate(key, () => value);
}
}
return null;

97
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

@ -636,6 +636,103 @@ namespace SqlSugar
}
return dic;
}
public static Type GetTypeByTypeName(string ctypename)
{
if (ctypename.EqualCase(UtilConstants.DecType.Name))
{
return UtilConstants.DecType;
}
else if (ctypename.EqualCase(UtilConstants.DobType.Name))
{
return UtilConstants.DobType;
}
else if (ctypename.EqualCase(UtilConstants.DateType.Name))
{
return UtilConstants.DateType;
}
else if (ctypename.EqualCase(UtilConstants.IntType.Name))
{
return UtilConstants.IntType;
}
else if (ctypename.EqualCase(UtilConstants.BoolType.Name))
{
return UtilConstants.BoolType;
}
else if (ctypename.EqualCase(UtilConstants.LongType.Name))
{
return UtilConstants.LongType;
}
else if (ctypename.EqualCase(UtilConstants.ShortType.Name))
{
return UtilConstants.ShortType;
}
else if (ctypename.EqualCase(UtilConstants.DateTimeOffsetType.Name))
{
return UtilConstants.DateTimeOffsetType;
}
else if (ctypename.EqualCase(UtilConstants.GuidType.Name))
{
return UtilConstants.GuidType;
}
else if (ctypename.EqualCase("int"))
{
return UtilConstants.IntType;
}
else if (ctypename.EqualCase("long"))
{
return UtilConstants.LongType;
}
else if (ctypename.EqualCase("short"))
{
return UtilConstants.ShortType;
}
else if (ctypename.EqualCase("byte"))
{
return UtilConstants.ByteType;
}
else if (ctypename.EqualCase("uint"))
{
return UtilConstants.UIntType;
}
else if (ctypename.EqualCase("ulong"))
{
return UtilConstants.ULongType;
}
else if (ctypename.EqualCase("ushort"))
{
return UtilConstants.UShortType;
}
else if (ctypename.EqualCase("uint32"))
{
return UtilConstants.UIntType;
}
else if (ctypename.EqualCase("uint64"))
{
return UtilConstants.ULongType;
}
else if (ctypename.EqualCase("bool"))
{
return UtilConstants.BoolType;
}
else if (ctypename.EqualCase("ToBoolean"))
{
return UtilConstants.BoolType;
}
else if (ctypename.EqualCase("uint16"))
{
return UtilConstants.UShortType;
}
else if (ctypename.EqualCase(UtilConstants.ByteArrayType.Name))
{
return UtilConstants.ByteArrayType;
}
else
{
return UtilConstants.StringType;
}
}
public static object ConvertDataByTypeName(string ctypename,string value)
{
var item = new ConditionalModel() {

Loading…
Cancel
Save