mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 增加 FreeSql.Provider.OracleOledb 解决US7ASCII 中文乱码问题;
This commit is contained in:
		@@ -1,6 +1,10 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
#if oledb
 | 
			
		||||
using System.Data.OleDb;
 | 
			
		||||
#else
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#endif
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
@@ -194,7 +198,7 @@ namespace FreeSql.Oracle.Curd
 | 
			
		||||
                return 0;
 | 
			
		||||
            }
 | 
			
		||||
            var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
 | 
			
		||||
            var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0) as OracleParameter;
 | 
			
		||||
            var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0);
 | 
			
		||||
            identParam.Direction = ParameterDirection.Output;
 | 
			
		||||
            sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
 | 
			
		||||
            var dbParms = _params.Concat(new[] { identParam }).ToArray();
 | 
			
		||||
@@ -263,7 +267,7 @@ namespace FreeSql.Oracle.Curd
 | 
			
		||||
                return 0;
 | 
			
		||||
            }
 | 
			
		||||
            var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name);
 | 
			
		||||
            var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0) as OracleParameter;
 | 
			
		||||
            var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0);
 | 
			
		||||
            identParam.Direction = ParameterDirection.Output;
 | 
			
		||||
            sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}";
 | 
			
		||||
            var dbParms = _params.Concat(new[] { identParam }).ToArray();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,9 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
using FreeSql.Internal.ObjectPool;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Data.Common;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.Oracle
 | 
			
		||||
@@ -63,8 +61,13 @@ namespace FreeSql.Oracle
 | 
			
		||||
 | 
			
		||||
        public override DbCommand CreateCommand()
 | 
			
		||||
        {
 | 
			
		||||
            var cmd = new OracleCommand();
 | 
			
		||||
            var cmd =
 | 
			
		||||
#if oledb
 | 
			
		||||
                new System.Data.OleDb.OleDbCommand();
 | 
			
		||||
#else
 | 
			
		||||
                new Oracle.ManagedDataAccess.Client.OracleCommand();
 | 
			
		||||
            cmd.BindByName = true;
 | 
			
		||||
#endif
 | 
			
		||||
            return cmd;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,15 @@
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#if oledb
 | 
			
		||||
using System.Data.OleDb;
 | 
			
		||||
using OracleException = System.Data.OleDb.OleDbException;
 | 
			
		||||
using OracleConnection = System.Data.OleDb.OleDbConnection;
 | 
			
		||||
#else
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#endif
 | 
			
		||||
using FreeSql.Internal.ObjectPool;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Data.Common;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
@@ -121,7 +125,10 @@ namespace FreeSql.Oracle
 | 
			
		||||
        public void OnDestroy(DbConnection obj)
 | 
			
		||||
        {
 | 
			
		||||
            try { if (obj.State != ConnectionState.Closed) obj.Close(); } catch { }
 | 
			
		||||
#if oledb
 | 
			
		||||
#else
 | 
			
		||||
            try { OracleConnection.ClearPool(obj as OracleConnection); } catch { }
 | 
			
		||||
#endif
 | 
			
		||||
            obj.Dispose();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,11 @@
 | 
			
		||||
using FreeSql.DatabaseModel;
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
#if oledb
 | 
			
		||||
using System.Data.OleDb;
 | 
			
		||||
#else
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#endif
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
@@ -21,37 +25,67 @@ namespace FreeSql.Oracle
 | 
			
		||||
        public OracleCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { }
 | 
			
		||||
 | 
			
		||||
        static object _dicCsToDbLock = new object();
 | 
			
		||||
        static Dictionary<string, CsToDb<OracleDbType>> _dicCsToDb = new Dictionary<string, CsToDb<OracleDbType>>() {
 | 
			
		||||
                { typeof(bool).FullName, CsToDb.New(OracleDbType.Boolean, "number","number(1) NOT NULL", null, false, false) },{ typeof(bool?).FullName, CsToDb.New(OracleDbType.Boolean, "number","number(1) NULL", null, true, null) },
 | 
			
		||||
#if oledb
 | 
			
		||||
        static Dictionary<Type, CsToDb<OleDbType>> _dicCsToDb = new Dictionary<Type, CsToDb<OleDbType>>() {
 | 
			
		||||
                { typeof(bool), CsToDb.New(OleDbType.Boolean, "number","number(1) NOT NULL", null, false, false) },{ typeof(bool?), CsToDb.New(OleDbType.Boolean, "number","number(1) NULL", null, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(sbyte).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(4) NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(4) NULL", false, true, null) },
 | 
			
		||||
                { typeof(short).FullName, CsToDb.New(OracleDbType.Int16, "number","number(6) NOT NULL", false, false, 0) },{ typeof(short?).FullName, CsToDb.New(OracleDbType.Int16, "number", "number(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(int).FullName, CsToDb.New(OracleDbType.Int32, "number", "number(11) NOT NULL", false, false, 0) },{ typeof(int?).FullName, CsToDb.New(OracleDbType.Int32, "number", "number(11) NULL", false, true, null) },
 | 
			
		||||
                { typeof(long).FullName, CsToDb.New(OracleDbType.Int64, "number","number(21) NOT NULL", false, false, 0) },{ typeof(long?).FullName, CsToDb.New(OracleDbType.Int64, "number","number(21) NULL", false, true, null) },
 | 
			
		||||
                { typeof(sbyte), CsToDb.New(OleDbType.TinyInt, "number", "number(4) NOT NULL", false, false, 0) },{ typeof(sbyte?), CsToDb.New(OleDbType.TinyInt, "number", "number(4) NULL", false, true, null) },
 | 
			
		||||
                { typeof(short), CsToDb.New(OleDbType.SmallInt, "number","number(6) NOT NULL", false, false, 0) },{ typeof(short?), CsToDb.New(OleDbType.SmallInt, "number", "number(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(int), CsToDb.New(OleDbType.Integer, "number", "number(11) NOT NULL", false, false, 0) },{ typeof(int?), CsToDb.New(OleDbType.Integer, "number", "number(11) NULL", false, true, null) },
 | 
			
		||||
                { typeof(long), CsToDb.New(OleDbType.BigInt, "number","number(21) NOT NULL", false, false, 0) },{ typeof(long?), CsToDb.New(OleDbType.BigInt, "number","number(21) NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(byte).FullName, CsToDb.New(OracleDbType.Byte, "number","number(3) NOT NULL", true, false, 0) },{ typeof(byte?).FullName, CsToDb.New(OracleDbType.Byte, "number","number(3) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ushort).FullName, CsToDb.New(OracleDbType.Decimal, "number","number(5) NOT NULL", true, false, 0) },{ typeof(ushort?).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(5) NULL", true, true, null) },
 | 
			
		||||
                { typeof(uint).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(10) NOT NULL", true, false, 0) },{ typeof(uint?).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(10) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ulong).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(20) NOT NULL", true, false, 0) },{ typeof(ulong?).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(20) NULL", true, true, null) },
 | 
			
		||||
                { typeof(byte), CsToDb.New(OleDbType.UnsignedTinyInt, "number","number(3) NOT NULL", true, false, 0) },{ typeof(byte?), CsToDb.New(OleDbType.UnsignedTinyInt, "number","number(3) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ushort), CsToDb.New(OleDbType.UnsignedSmallInt, "number","number(5) NOT NULL", true, false, 0) },{ typeof(ushort?), CsToDb.New(OleDbType.UnsignedSmallInt, "number", "number(5) NULL", true, true, null) },
 | 
			
		||||
                { typeof(uint), CsToDb.New(OleDbType.UnsignedInt, "number", "number(10) NOT NULL", true, false, 0) },{ typeof(uint?), CsToDb.New(OleDbType.UnsignedInt, "number", "number(10) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ulong), CsToDb.New(OleDbType.UnsignedBigInt, "number", "number(20) NOT NULL", true, false, 0) },{ typeof(ulong?), CsToDb.New(OleDbType.UnsignedBigInt, "number", "number(20) NULL", true, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(double).FullName, CsToDb.New(OracleDbType.Double, "float", "float(126) NOT NULL", false, false, 0) },{ typeof(double?).FullName, CsToDb.New(OracleDbType.Double, "float", "float(126) NULL", false, true, null) },
 | 
			
		||||
                { typeof(float).FullName, CsToDb.New(OracleDbType.Single, "float","float(63) NOT NULL", false, false, 0) },{ typeof(float?).FullName, CsToDb.New(OracleDbType.Single, "float","float(63) NULL", false, true, null) },
 | 
			
		||||
                { typeof(decimal).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, CsToDb.New(OracleDbType.Decimal, "number", "number(10,2) NULL", false, true, null) },
 | 
			
		||||
                { typeof(double), CsToDb.New(OleDbType.Double, "float", "float(126) NOT NULL", false, false, 0) },{ typeof(double?), CsToDb.New(OleDbType.Double, "float", "float(126) NULL", false, true, null) },
 | 
			
		||||
                { typeof(float), CsToDb.New(OleDbType.Single, "float","float(63) NOT NULL", false, false, 0) },{ typeof(float?), CsToDb.New(OleDbType.Single, "float","float(63) NULL", false, true, null) },
 | 
			
		||||
                { typeof(decimal), CsToDb.New(OleDbType.Decimal, "number", "number(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?), CsToDb.New(OleDbType.Decimal, "number", "number(10,2) NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(TimeSpan).FullName, CsToDb.New(OracleDbType.IntervalDS, "interval day to second","interval day(2) to second(6) NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, CsToDb.New(OracleDbType.IntervalDS, "interval day to second", "interval day(2) to second(6) NULL",false, true, null) },
 | 
			
		||||
                { typeof(DateTime).FullName, CsToDb.New(OracleDbType.TimeStamp, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, CsToDb.New(OracleDbType.TimeStamp, "timestamp", "timestamp(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(DateTimeOffset).FullName, CsToDb.New(OracleDbType.TimeStampLTZ, "timestamp with local time zone", "timestamp(6) with local time zone NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTimeOffset?).FullName, CsToDb.New(OracleDbType.TimeStampLTZ, "timestamp with local time zone", "timestamp(6) with local time zone NULL", false, true, null) },
 | 
			
		||||
                { typeof(TimeSpan), CsToDb.New(OleDbType.DBTime, "interval day to second","interval day(2) to second(6) NOT NULL", false, false, 0) },{ typeof(TimeSpan?), CsToDb.New(OleDbType.DBTime, "interval day to second", "interval day(2) to second(6) NULL",false, true, null) },
 | 
			
		||||
                { typeof(DateTime), CsToDb.New(OleDbType.DBTime, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?), CsToDb.New(OleDbType.DBTime, "timestamp", "timestamp(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(DateTimeOffset), CsToDb.New(OleDbType.DBTimeStamp, "timestamp with local time zone", "timestamp(6) with local time zone NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTimeOffset?), CsToDb.New(OleDbType.DBTimeStamp, "timestamp with local time zone", "timestamp(6) with local time zone NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(byte[]).FullName, CsToDb.New(OracleDbType.Blob, "blob", "blob NULL", false, null, new byte[0]) },
 | 
			
		||||
                { typeof(string).FullName, CsToDb.New(OracleDbType.NVarchar2, "nvarchar2", "nvarchar2(255) NULL", false, null, "") },
 | 
			
		||||
                { typeof(char).FullName, CsToDb.New(OracleDbType.Char, "char", "char(1 CHAR) NULL", false, null, '\0') },
 | 
			
		||||
                { typeof(byte[]), CsToDb.New(OleDbType.VarBinary, "blob", "blob NULL", false, null, new byte[0]) },
 | 
			
		||||
                { typeof(string), CsToDb.New(OleDbType.VarChar, "nvarchar2", "nvarchar2(255) NULL", false, null, "") },
 | 
			
		||||
                { typeof(char), CsToDb.New(OleDbType.Char, "char", "char(1 CHAR) NULL", false, null, '\0') },
 | 
			
		||||
 | 
			
		||||
                { typeof(Guid).FullName, CsToDb.New(OracleDbType.Char, "char", "char(36 CHAR) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, CsToDb.New(OracleDbType.Char, "char", "char(36 CHAR) NULL", false, true, null) },
 | 
			
		||||
                { typeof(Guid), CsToDb.New(OleDbType.Char, "char", "char(36 CHAR) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?), CsToDb.New(OleDbType.Char, "char", "char(36 CHAR) NULL", false, true, null) },
 | 
			
		||||
            };
 | 
			
		||||
#else
 | 
			
		||||
        static Dictionary<Type, CsToDb<OracleDbType>> _dicCsToDb = new Dictionary<Type, CsToDb<OracleDbType>>() {
 | 
			
		||||
                { typeof(bool), CsToDb.New(OracleDbType.Boolean, "number","number(1) NOT NULL", null, false, false) },{ typeof(bool?), CsToDb.New(OracleDbType.Boolean, "number","number(1) NULL", null, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(sbyte), CsToDb.New(OracleDbType.Decimal, "number", "number(4) NOT NULL", false, false, 0) },{ typeof(sbyte?), CsToDb.New(OracleDbType.Decimal, "number", "number(4) NULL", false, true, null) },
 | 
			
		||||
                { typeof(short), CsToDb.New(OracleDbType.Int16, "number","number(6) NOT NULL", false, false, 0) },{ typeof(short?), CsToDb.New(OracleDbType.Int16, "number", "number(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(int), CsToDb.New(OracleDbType.Int32, "number", "number(11) NOT NULL", false, false, 0) },{ typeof(int?), CsToDb.New(OracleDbType.Int32, "number", "number(11) NULL", false, true, null) },
 | 
			
		||||
                { typeof(long), CsToDb.New(OracleDbType.Int64, "number","number(21) NOT NULL", false, false, 0) },{ typeof(long?), CsToDb.New(OracleDbType.Int64, "number","number(21) NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(byte), CsToDb.New(OracleDbType.Byte, "number","number(3) NOT NULL", true, false, 0) },{ typeof(byte?), CsToDb.New(OracleDbType.Byte, "number","number(3) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ushort), CsToDb.New(OracleDbType.Decimal, "number","number(5) NOT NULL", true, false, 0) },{ typeof(ushort?), CsToDb.New(OracleDbType.Decimal, "number", "number(5) NULL", true, true, null) },
 | 
			
		||||
                { typeof(uint), CsToDb.New(OracleDbType.Decimal, "number", "number(10) NOT NULL", true, false, 0) },{ typeof(uint?), CsToDb.New(OracleDbType.Decimal, "number", "number(10) NULL", true, true, null) },
 | 
			
		||||
                { typeof(ulong), CsToDb.New(OracleDbType.Decimal, "number", "number(20) NOT NULL", true, false, 0) },{ typeof(ulong?), CsToDb.New(OracleDbType.Decimal, "number", "number(20) NULL", true, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(double), CsToDb.New(OracleDbType.Double, "float", "float(126) NOT NULL", false, false, 0) },{ typeof(double?), CsToDb.New(OracleDbType.Double, "float", "float(126) NULL", false, true, null) },
 | 
			
		||||
                { typeof(float), CsToDb.New(OracleDbType.Single, "float","float(63) NOT NULL", false, false, 0) },{ typeof(float?), CsToDb.New(OracleDbType.Single, "float","float(63) NULL", false, true, null) },
 | 
			
		||||
                { typeof(decimal), CsToDb.New(OracleDbType.Decimal, "number", "number(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?), CsToDb.New(OracleDbType.Decimal, "number", "number(10,2) NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(TimeSpan), CsToDb.New(OracleDbType.IntervalDS, "interval day to second","interval day(2) to second(6) NOT NULL", false, false, 0) },{ typeof(TimeSpan?), CsToDb.New(OracleDbType.IntervalDS, "interval day to second", "interval day(2) to second(6) NULL",false, true, null) },
 | 
			
		||||
                { typeof(DateTime), CsToDb.New(OracleDbType.TimeStamp, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?), CsToDb.New(OracleDbType.TimeStamp, "timestamp", "timestamp(6) NULL", false, true, null) },
 | 
			
		||||
                { typeof(DateTimeOffset), CsToDb.New(OracleDbType.TimeStampLTZ, "timestamp with local time zone", "timestamp(6) with local time zone NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTimeOffset?), CsToDb.New(OracleDbType.TimeStampLTZ, "timestamp with local time zone", "timestamp(6) with local time zone NULL", false, true, null) },
 | 
			
		||||
 | 
			
		||||
                { typeof(byte[]), CsToDb.New(OracleDbType.Blob, "blob", "blob NULL", false, null, new byte[0]) },
 | 
			
		||||
                { typeof(string), CsToDb.New(OracleDbType.NVarchar2, "nvarchar2", "nvarchar2(255) NULL", false, null, "") },
 | 
			
		||||
                { typeof(char), CsToDb.New(OracleDbType.Char, "char", "char(1 CHAR) NULL", false, null, '\0') },
 | 
			
		||||
 | 
			
		||||
                { typeof(Guid), CsToDb.New(OracleDbType.Char, "char", "char(36 CHAR) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?), CsToDb.New(OracleDbType.Char, "char", "char(36 CHAR) NULL", false, true, null) },
 | 
			
		||||
            };
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        public override DbInfoResult GetDbInfo(Type type)
 | 
			
		||||
        {
 | 
			
		||||
            if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new DbInfoResult((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue);
 | 
			
		||||
            if (_dicCsToDb.TryGetValue(type, out var trydc)) return new DbInfoResult((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue);
 | 
			
		||||
            if (type.IsArray) return null;
 | 
			
		||||
            var enumType = type.IsEnum ? type : null;
 | 
			
		||||
            if (enumType == null && type.IsNullableType())
 | 
			
		||||
@@ -62,14 +96,14 @@ namespace FreeSql.Oracle
 | 
			
		||||
            if (enumType != null)
 | 
			
		||||
            {
 | 
			
		||||
                var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ?
 | 
			
		||||
                    CsToDb.New(OracleDbType.Int32, "number", $"number(16){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()) :
 | 
			
		||||
                    CsToDb.New(OracleDbType.Int64, "number", $"number(32){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue());
 | 
			
		||||
                if (_dicCsToDb.ContainsKey(type.FullName) == false)
 | 
			
		||||
                    CsToDb.New(_dicCsToDb[typeof(int)].type, "number", $"number(16){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()) :
 | 
			
		||||
                    CsToDb.New(_dicCsToDb[typeof(long)].type, "number", $"number(32){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue());
 | 
			
		||||
                if (_dicCsToDb.ContainsKey(type) == false)
 | 
			
		||||
                {
 | 
			
		||||
                    lock (_dicCsToDbLock)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (_dicCsToDb.ContainsKey(type.FullName) == false)
 | 
			
		||||
                            _dicCsToDb.Add(type.FullName, newItem);
 | 
			
		||||
                        if (_dicCsToDb.ContainsKey(type) == false)
 | 
			
		||||
                            _dicCsToDb.Add(type, newItem);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                return new DbInfoResult((int)newItem.type, newItem.dbtype, newItem.dbtypeFull, newItem.isnullable, newItem.defaultValue);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,11 @@
 | 
			
		||||
using FreeSql.DatabaseModel;
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
#if oledb
 | 
			
		||||
using System.Data.OleDb;
 | 
			
		||||
#else
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#endif
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
@@ -25,6 +29,98 @@ namespace FreeSql.Oracle
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int GetDbType(DbColumnInfo column) => (int)GetSqlDbType(column);
 | 
			
		||||
#if oledb
 | 
			
		||||
        OleDbType GetSqlDbType(DbColumnInfo column)
 | 
			
		||||
        {
 | 
			
		||||
            var dbfull = column.DbTypeTextFull?.ToLower();
 | 
			
		||||
            switch (dbfull)
 | 
			
		||||
            {
 | 
			
		||||
                case "number(1)": return OleDbType.Boolean;
 | 
			
		||||
 | 
			
		||||
                case "number(4)": return OleDbType.TinyInt;
 | 
			
		||||
                case "number(6)": return OleDbType.SmallInt;
 | 
			
		||||
                case "number(11)": return OleDbType.Integer;
 | 
			
		||||
                case "number(21)": return OleDbType.BigInt;
 | 
			
		||||
 | 
			
		||||
                case "number(3)": return OleDbType.UnsignedTinyInt;
 | 
			
		||||
                case "number(5)": return OleDbType.UnsignedSmallInt;
 | 
			
		||||
                case "number(10)": return OleDbType.UnsignedInt;
 | 
			
		||||
                case "number(20)": return OleDbType.UnsignedBigInt;
 | 
			
		||||
 | 
			
		||||
                case "float(126)": return OleDbType.Double;
 | 
			
		||||
                case "float(63)": return OleDbType.Single;
 | 
			
		||||
                case "number(10,2)": return OleDbType.Decimal;
 | 
			
		||||
 | 
			
		||||
                case "interval day(2) to second(6)": return OleDbType.DBTime;
 | 
			
		||||
                case "timestamp(6)": return OleDbType.DBTime;
 | 
			
		||||
                case "timestamp(6) with local time zone": return OleDbType.DBTimeStamp;
 | 
			
		||||
 | 
			
		||||
                case "blob": return OleDbType.VarBinary;
 | 
			
		||||
                case "nvarchar2(255)": return OleDbType.VarChar;
 | 
			
		||||
 | 
			
		||||
                case "char(36 char)": return OleDbType.Char;
 | 
			
		||||
            }
 | 
			
		||||
            switch (column.DbTypeText?.ToLower())
 | 
			
		||||
            {
 | 
			
		||||
                case "number":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(10,2)"]);
 | 
			
		||||
                    return OleDbType.Decimal;
 | 
			
		||||
                case "float":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(126)"]);
 | 
			
		||||
                    return OleDbType.Double;
 | 
			
		||||
                case "interval day to second":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["interval day(2) to second(6)"]);
 | 
			
		||||
                    return OleDbType.DBTime;
 | 
			
		||||
                case "date":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["date"]);
 | 
			
		||||
                    return OleDbType.DBTime;
 | 
			
		||||
                case "timestamp":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6)"]);
 | 
			
		||||
                    return OleDbType.DBTime;
 | 
			
		||||
                case "timestamp with local time zone":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6) with local time zone"]);
 | 
			
		||||
                    return OleDbType.DBTimeStamp;
 | 
			
		||||
                case "blob":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
 | 
			
		||||
                    return OleDbType.VarBinary;
 | 
			
		||||
                case "nvarchar2":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.VarChar;
 | 
			
		||||
                case "varchar2":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.VarChar;
 | 
			
		||||
                case "char":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.Char;
 | 
			
		||||
                case "nchar":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.Char;
 | 
			
		||||
                case "clob":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.VarChar;
 | 
			
		||||
                case "nclob":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.VarChar;
 | 
			
		||||
                case "raw":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
 | 
			
		||||
                    return OleDbType.VarBinary;
 | 
			
		||||
                case "long raw":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]);
 | 
			
		||||
                    return OleDbType.VarBinary;
 | 
			
		||||
                case "binary_float":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(63)"]);
 | 
			
		||||
                    return OleDbType.Single;
 | 
			
		||||
                case "binary_double":
 | 
			
		||||
                    _dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(126)"]);
 | 
			
		||||
                    return OleDbType.Double;
 | 
			
		||||
                case "rowid":
 | 
			
		||||
                default:
 | 
			
		||||
                    if (dbfull != null) _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]);
 | 
			
		||||
                    return OleDbType.VarChar;
 | 
			
		||||
            }
 | 
			
		||||
            throw new NotImplementedException(CoreStrings.S_TypeMappingNotImplemented(column.DbTypeTextFull));
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
        OracleDbType GetSqlDbType(DbColumnInfo column)
 | 
			
		||||
        {
 | 
			
		||||
            var dbfull = column.DbTypeTextFull?.ToLower();
 | 
			
		||||
@@ -115,6 +211,7 @@ namespace FreeSql.Oracle
 | 
			
		||||
            }
 | 
			
		||||
            throw new NotImplementedException(CoreStrings.S_TypeMappingNotImplemented(column.DbTypeTextFull));
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        static ConcurrentDictionary<string, DbToCs> _dicDbToCs = new ConcurrentDictionary<string, DbToCs>(StringComparer.CurrentCultureIgnoreCase);
 | 
			
		||||
        static OracleDbFirst()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,9 @@
 | 
			
		||||
using FreeSql;
 | 
			
		||||
#if oledb
 | 
			
		||||
using System.Data.OleDb;
 | 
			
		||||
#else
 | 
			
		||||
using Oracle.ManagedDataAccess.Client;
 | 
			
		||||
#endif
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
public static partial class FreeSqlOracleGlobalExtensions
 | 
			
		||||
@@ -14,6 +18,8 @@ public static partial class FreeSqlOracleGlobalExtensions
 | 
			
		||||
    public static string FormatOracle(this string that, params object[] args) => _oracleAdo.Addslashes(that, args);
 | 
			
		||||
    static FreeSql.Oracle.OracleAdo _oracleAdo = new FreeSql.Oracle.OracleAdo();
 | 
			
		||||
 | 
			
		||||
#if oledb
 | 
			
		||||
#else
 | 
			
		||||
    #region ExecuteOracleBulkCopy
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Oracle CopyBulk 批量插入功能<para></para>
 | 
			
		||||
@@ -106,4 +112,5 @@ public static partial class FreeSqlOracleGlobalExtensions
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    #endregion
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user