mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 增加 KingBaseES 支持数组等类型(参考 PostgreSQL);
This commit is contained in:
		@@ -3,10 +3,13 @@ using FreeSql.Internal.CommonProvider;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using FreeSql.Internal.ObjectPool;
 | 
			
		||||
using Kdbndp;
 | 
			
		||||
using Newtonsoft.Json.Linq;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data.Common;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.KingbaseES
 | 
			
		||||
@@ -43,9 +46,10 @@ namespace FreeSql.KingbaseES
 | 
			
		||||
        public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
 | 
			
		||||
        {
 | 
			
		||||
            if (param == null) return "NULL";
 | 
			
		||||
            if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
 | 
			
		||||
            if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || param is JToken || param is JObject || param is JArray))
 | 
			
		||||
                param = Utils.GetDataReaderValue(mapType, param);
 | 
			
		||||
 | 
			
		||||
            bool isdic;
 | 
			
		||||
            if (param is bool || param is bool?)
 | 
			
		||||
                return (bool)param ? "'t'" : "'f'";
 | 
			
		||||
            else if (param is string)
 | 
			
		||||
@@ -62,6 +66,16 @@ namespace FreeSql.KingbaseES
 | 
			
		||||
            else if (param is DateTime?)
 | 
			
		||||
                return AddslashesTypeHandler(typeof(DateTime?), param) ?? string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'");
 | 
			
		||||
 | 
			
		||||
#if net60
 | 
			
		||||
            else if (param is DateOnly || param is DateOnly?)
 | 
			
		||||
                return AddslashesTypeHandler(typeof(DateOnly), param) ?? string.Concat("'", ((DateOnly)param).ToString("yyyy-MM-dd"), "'");
 | 
			
		||||
            else if (param is TimeOnly || param is TimeOnly?)
 | 
			
		||||
            {
 | 
			
		||||
                var ts = (TimeOnly)param;
 | 
			
		||||
                return $"'{ts.Hour}:{ts.Minute}:{ts.Second}.{ts.Millisecond}'";
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            else if (param is TimeSpan || param is TimeSpan?)
 | 
			
		||||
            {
 | 
			
		||||
                var ts = (TimeSpan)param;
 | 
			
		||||
@@ -69,6 +83,31 @@ namespace FreeSql.KingbaseES
 | 
			
		||||
            }
 | 
			
		||||
            else if (param is byte[])
 | 
			
		||||
                return $"'\\x{CommonUtils.BytesSqlRaw(param as byte[])}'";
 | 
			
		||||
            else if (param is JToken || param is JObject || param is JArray)
 | 
			
		||||
                return string.Concat("'", param.ToString().Replace("'", "''"), "'::jsonb");
 | 
			
		||||
            else if ((isdic = param is Dictionary<string, string>) ||
 | 
			
		||||
                param is IEnumerable<KeyValuePair<string, string>>)
 | 
			
		||||
            {
 | 
			
		||||
                var pgdics = isdic ? param as Dictionary<string, string> :
 | 
			
		||||
                    param as IEnumerable<KeyValuePair<string, string>>;
 | 
			
		||||
 | 
			
		||||
                var pghstore = new StringBuilder("'");
 | 
			
		||||
                var pairs = pgdics.ToArray();
 | 
			
		||||
 | 
			
		||||
                for (var i = 0; i < pairs.Length; i++)
 | 
			
		||||
                {
 | 
			
		||||
                    if (i != 0) pghstore.Append(",");
 | 
			
		||||
 | 
			
		||||
                    pghstore.AppendFormat("\"{0}\"=>", pairs[i].Key.Replace("'", "''"));
 | 
			
		||||
 | 
			
		||||
                    if (pairs[i].Value == null)
 | 
			
		||||
                        pghstore.Append("NULL");
 | 
			
		||||
                    else
 | 
			
		||||
                        pghstore.AppendFormat("\"{0}\"", pairs[i].Value.Replace("'", "''"));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return pghstore.Append("'::hstore");
 | 
			
		||||
            }
 | 
			
		||||
            else if (param is IEnumerable)
 | 
			
		||||
                return AddslashesIEnumerable(param, mapType, mapColumn);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user