Ejemplo n.º 1
0
 protected override object PrepareConstraintValue(object value)
 {
     if (value is bool)
     {
         return(OracleDbTypeHelper.ToDbBoolean((bool)value));
     }
     return(base.PrepareConstraintValue(value));
 }
Ejemplo n.º 2
0
        private void CreateTable()
        {
            //不再使用 Date 类型,因为 Oracle 和 SQLServer 里面的数据的精度不一样。改为使用 LONG
            //Oracle 中的 DateTime 类型为 Date
            var timeType = DbSetting.IsOracleProvider(this.DbSetting) ?
                           OracleDbTypeHelper.ConvertToOracleTypeString(DbType.Int64) :
                           SqlDbTypeHelper.ConvertToSQLTypeString(DbType.Int64);

            this.DBA.RawAccesser.ExecuteText(string.Format(@"CREATE TABLE {1}(ID INT NOT NULL,Value {0} NOT NULL,PRIMARY KEY (ID))", timeType, TableName));
            this.DBA.ExecuteText("INSERT INTO " + TableName + " (ID,VALUE) VALUES (1, {0})", DefaultMinTime.Ticks);
        }
Ejemplo n.º 3
0
        private static IDbDataParameter ReadIntoBatchParameter(IList <Entity> entities, RdbColumn column, IRawDbAccesser dba)
        {
            var parameter = dba.ParameterFactory.CreateParameter();

            parameter.ParameterName = column.Name;

            #region 对于 CLOB 类型,需要特殊处理。

            var dbType = column.Info.ColumnMeta.DataType ?? OracleDbTypeHelper.ConvertFromCLRType(column.Info.DataType);

            /*********************** 代码块解释 *********************************
             * 不再需要对 CLOB 类型特殊处理
             *
             * 这是因为:某个字段使用 CLOB 类型后,如果再使用 BatchInsert 的功能,如果数据条数较多时(1000条未再现,10000条时出现),
             * oracle.exe 会一直占用 100% CPU,而且一直运行,不再返回(目前还不知道什么原因)。
             *
             * 另外,如果不使用 OracleDbType.Clob 来标记 OracleParameter,而只是使用 DbType.String,也可以正确的运行。
             **********************************************************************/
            //bool setOracleDbTypeEx = false;
            //if (dbType == DbType.String || dbType == DbType.AnsiString)
            //{
            //    //对于 CLOB 类型,需要特殊处理。
            //    var length = column.Info.ColumnMeta.DataTypeLength;
            //    if (OracleDbTypeHelper.CLOBTypeName.EqualsIgnoreCase(length) || "MAX".EqualsIgnoreCase(length))
            //    {
            //        (parameter as OracleParameter).OracleDbTypeEx = OracleDbType.Clob;
            //        setOracleDbTypeEx = true;
            //    }
            //}
            //else if (dbType == DbType.Binary)
            //{
            //    (parameter as OracleParameter).OracleDbTypeEx = OracleDbType.Blob;
            //    setOracleDbTypeEx = true;
            //}
            //if (!setOracleDbTypeEx)
            //{
            parameter.DbType = dbType;
            //}

            #endregion

            int rowsCount  = entities.Count;
            var valueArray = new object[rowsCount] as IList;
            for (int j = 0; j < rowsCount; j++)
            {
                var entity = entities[j];
                var value  = column.ReadParameterValue(entity);
                valueArray[j] = value;
            }

            parameter.Value = valueArray;
            return(parameter);
        }
Ejemplo n.º 4
0
        public override object ReadParameterValue(Entity entity)
        {
            var value = base.ReadParameterValue(entity);

            if (this.Info.IsBooleanType)
            {
                value = OracleDbTypeHelper.ToDbBoolean((bool)value);
            }
            else if (this.Info.DataType.IsEnum)
            {
                value = TypeHelper.CoerceValue(typeof(int), value);
            }
            return(value);
        }
Ejemplo n.º 5
0
        internal override void Write(Entity entity, object value)
        {
            var info = this.Info;

            if (info.IsBooleanType)
            {
                value = OracleDbTypeHelper.ToCLRBoolean(value);
            }
            else if (value == null && info.IsStringType)//null 转换为空字符串
            {
                value = string.Empty;
            }

            base.Write(entity, value);
        }
Ejemplo n.º 6
0
        internal static object PrepareConstraintValueInternal(object value)
        {
            if (value != DBNull.Value)
            {
                if (value is bool)
                {
                    value = OracleDbTypeHelper.ToDbBoolean((bool)value);
                }
                else if (value.GetType().IsEnum)
                {
                    value = TypeHelper.CoerceValue(typeof(int), value);
                }
            }

            return(value);
        }
Ejemplo n.º 7
0
        private static IDbDataParameter ReadIntoBatchParameter(IList <Entity> entities, RdbColumn column, IRawDbAccesser dba)
        {
            var parameter = dba.ParameterFactory.CreateParameter();

            parameter.ParameterName = column.Name;
            parameter.DbType        = OracleDbTypeHelper.ConvertFromCLRType(column.Info.DataType);

            int rowsCount  = entities.Count;
            var valueArray = new object[rowsCount] as IList;

            for (int j = 0; j < rowsCount; j++)
            {
                var entity = entities[j];
                var value  = column.ReadParameterValue(entity);
                valueArray[j] = value;
            }

            parameter.Value = valueArray;
            return(parameter);
        }