PGSQLl Support Array

This commit is contained in:
skx 2020-10-13 17:44:25 +08:00
parent 5ee5ee636f
commit 92ee57967e
9 changed files with 67 additions and 1 deletions

View File

@ -1343,7 +1343,7 @@ namespace SqlSugar
if (item.Value != null)
{
var type = item.Value.GetType();
if ((type != UtilConstants.ByteArrayType && type.IsArray) || type.FullName.IsCollectionsList())
if ((type != UtilConstants.ByteArrayType && type.IsArray&&item.IsArray==false) || type.FullName.IsCollectionsList())
{
var newValues = new List<string>();
foreach (var inValute in item.Value as IEnumerable)

View File

@ -194,6 +194,7 @@ namespace SqlSugar
column.DefaultValue = sugarColumn.DefaultValue;
column.IndexGroupNameList = sugarColumn.IndexGroupNameList;
column.IsOnlyIgnoreUpdate = sugarColumn.IsOnlyIgnoreUpdate;
column.IsArray = sugarColumn.IsArray;
}
else
{

View File

@ -343,6 +343,10 @@ namespace SqlSugar
{
paramters.IsJson = true;
}
if (item.IsArray)
{
paramters.IsArray = true;
}
this.InsertBuilder.Parameters.Add(paramters);
}
}
@ -407,6 +411,10 @@ namespace SqlSugar
{
columnInfo.IsJson = true;
}
if (column.IsArray)
{
columnInfo.IsArray = true;
}
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);

View File

@ -491,6 +491,10 @@ namespace SqlSugar
columnInfo.IsJson = true;
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
}
if (column.IsArray)
{
columnInfo.IsArray = true;
}
var tranColumn = EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
if (tranColumn != null && columnInfo.Value.HasValue())
{
@ -536,6 +540,10 @@ namespace SqlSugar
{
parameter.IsJson = true;
}
if (item.IsArray)
{
parameter.IsArray = true;
}
this.UpdateBuilder.Parameters.Add(parameter);
}
}

View File

@ -21,6 +21,7 @@ namespace SqlSugar
public object Value { get; set; }
public int DecimalDigits { get; set; }
public int Scale { get; set; }
public bool IsArray { get; set; }
internal bool IsJson { get; set; }
}
}

View File

@ -33,5 +33,6 @@ namespace SqlSugar
public bool IsJson { get; set; }
public bool NoSerialize { get; set; }
public string[] IndexGroupNameList { get; set; }
public bool IsArray { get; set; }
}
}

View File

@ -171,6 +171,13 @@ namespace SqlSugar
set { _IndexGroupNameList = value; }
}
private bool _IsArray;
public bool IsArray
{
get { return _IsArray; }
set { _IsArray = value; }
}
}
}

View File

@ -234,5 +234,6 @@ namespace SqlSugar
public string TypeName { get; set; }
public bool IsJson { get; set; }
public bool IsArray { get; set; }
}
}

View File

@ -99,6 +99,19 @@ namespace SqlSugar
{
sqlParameter.NpgsqlDbType = NpgsqlDbType.Json;
}
if (parameter.IsArray)
{
// sqlParameter.Value = this.Context.Utilities.SerializeObject(sqlParameter.Value);
var type = sqlParameter.Value.GetType();
if (ArrayMapping.ContainsKey(type))
{
sqlParameter.NpgsqlDbType = ArrayMapping[type] | NpgsqlDbType.Array;
}
else
{
Check.Exception(true, sqlParameter.Value.GetType().Name + " No Support");
}
}
if (sqlParameter.Direction == 0)
{
sqlParameter.Direction = ParameterDirection.Input;
@ -114,5 +127,31 @@ namespace SqlSugar
}
return result;
}
static readonly Dictionary<Type, NpgsqlDbType> ArrayMapping = new Dictionary<Type, NpgsqlDbType>()
{
{ typeof(int[]),NpgsqlDbType.Integer},
{ typeof(short[]),NpgsqlDbType.Smallint},
{ typeof(long[]),NpgsqlDbType.Bigint},
{ typeof(decimal[]),NpgsqlDbType.Numeric},
{ typeof(char[]),NpgsqlDbType.Text},
{ typeof(byte[]),NpgsqlDbType.Bytea},
{ typeof(bool[]),NpgsqlDbType.Boolean},
{typeof(DateTime[]),NpgsqlDbType.Date},
{ typeof(int?[]),NpgsqlDbType.Integer},
{ typeof(short?[]),NpgsqlDbType.Smallint},
{ typeof(long?[]),NpgsqlDbType.Bigint},
{ typeof(decimal?[]),NpgsqlDbType.Numeric},
{ typeof(char?[]),NpgsqlDbType.Text},
{ typeof(byte?[]),NpgsqlDbType.Bytea},
{ typeof(bool?[]),NpgsqlDbType.Boolean},
{typeof(DateTime?[]),NpgsqlDbType.Date},
{ typeof(string[]), NpgsqlDbType.Text},
};
}
}