예제 #1
0
        // 获取 String 类型的 SQL 片断
        protected override string GetSqlValueByString(object value, object dbType, int?size = null)
        {
            bool   unicode = OracleDbTypeInfo.IsUnicode2(dbType);
            string result  = this.EscapeQuote(value.ToString(), unicode, true);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 获取 DatetTime 类型的 SQL 片断
        /// </summary>
        protected override string GetSqlValueByDateTime(object value, object dbType, int?precision)
        {
            // 默认精度6
            string           format      = "yyyy-MM-dd HH:mm:ss";
            OracleDbTypeInfo dbTypeInfo  = OracleDbTypeInfo.Create(dbType);
            bool             isTimestamp = false;

            if (dbTypeInfo != null && (dbTypeInfo.IsDateTime || dbTypeInfo.IsDateTime2))
            {
                format      = "yyyy-MM-dd HH:mm:ss.ffffff";
                isTimestamp = true;
                string pad = string.Empty;
                if (precision != null && precision.Value > 0)
                {
                    pad = "f".PadLeft(precision.Value > 7 ? 7 : precision.Value, 'f');
                }
                if (!string.IsNullOrEmpty(pad))
                {
                    format = string.Format("yyyy-MM-dd HH:mm:ss.{0}", pad);
                }
            }

            string result = this.EscapeQuote(((DateTime)value).ToString(format), false, false);

            result = isTimestamp
                ? string.Format("TO_TIMESTAMP({0},'yyyy-mm-dd hh24:mi:ss.ff')", result)
                : string.Format("TO_DATE({0},'yyyy-mm-dd hh24:mi:ss')", result);
            return(result);
        }
예제 #3
0
        /// <summary>
        /// 检查是否Unicode数据类型
        /// </summary>
        public static bool IsUnicode2(object dbType)
        {
            if (dbType == null)
            {
                return(true);
            }
            OracleDbTypeInfo dbTypeInfo = OracleDbTypeInfo.Create(dbType);

            return(dbTypeInfo != null ? dbTypeInfo.IsUnicode : true);
        }
예제 #4
0
        protected override IDbDataParameter AddParameter(object value, object dbType, int?size = null, int?precision = null, int?scale = null, ParameterDirection?direction = null)
        {
            if (value is bool)
            {
                value = ((bool)value) ? 1 : 0;
            }
            else if (value is Guid)
            {
                value  = ((Guid)value).ToByteArray();
                dbType = OracleDbType.Raw;
            }
            //else if (value is DateTimeOffset)
            //{
            //    value = new Oracle.ManagedDataAccess.Types.OracleTimeStampTZ(((DateTimeOffset)value).LocalDateTime, TimeZone.CurrentTimeZone.StandardName);
            //}

            OracleParameter parameter = (OracleParameter)base.AddParameter(value, dbType, size, precision, scale, direction);

            // 补充 DbType
            OracleDbTypeInfo dbTypeInfo = OracleDbTypeInfo.Create(dbType);

            if (dbTypeInfo != null && dbTypeInfo.DbType != null)
            {
                parameter.DbType = dbTypeInfo.DbType.Value;
            }
            else if (dbTypeInfo != null && dbTypeInfo.SqlDbType != null)
            {
                parameter.OracleDbType = dbTypeInfo.SqlDbType.Value;
            }

            if (size != null && (size.Value > 0 || size.Value == -1))
            {
                parameter.Size = size.Value;
            }
            if (precision != null && precision.Value > 0)
            {
                parameter.Precision = (byte)precision.Value;
            }
            if (scale != null && scale.Value > 0)
            {
                parameter.Scale = (byte)scale.Value;
            }

            return(parameter);
        }