Exemplo n.º 1
0
        // 获取 Time 类型的 SQL 片断
        protected override string GetSqlValueByTime(object value, object dbType, int?precision)
        {
#if netcore
            // 默认精度6
            string        format     = @"hh\:mm\:ss\.ffffff";
            NpgDbTypeInfo dbTypeInfo = NpgDbTypeInfo.Create(dbType);

            if (dbTypeInfo != null && dbTypeInfo.IsTime)
            {
                string pad = string.Empty;
                if (precision != null && precision.Value > 0)
                {
                    pad = "f".PadLeft(precision.Value > 6 ? 6 : precision.Value, 'f');
                }
                if (!string.IsNullOrEmpty(pad))
                {
                    format = string.Format(@"hh\:mm\:ss\.{0}", pad);
                }
            }

            string result = this.EscapeQuote(((TimeSpan)value).ToString(format), false, false);
            return(result);
#endif

#if !netcore
            throw new NotSupportedException("Oracle does not support Time type.");
#endif
        }
Exemplo n.º 2
0
        // 获取 DateTimeOffset 类型的 SQL 片断
        protected override string GetSqlValueByDateTimeOffset(object value, object dbType, int?precision)
        {
            // 默认精度6
            string        format     = "yyyy-MM-dd HH:mm:ss.ffffff";
            NpgDbTypeInfo dbTypeInfo = NpgDbTypeInfo.Create(dbType);

            if (dbTypeInfo != null && dbTypeInfo.IsDateTimeOffset)
            {
                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 date = ((DateTimeOffset)value).DateTime.ToString(format);
            string span = ((DateTimeOffset)value).Offset.ToString(@"hh");

            span = string.Format("{0}{1}", ((DateTimeOffset)value).Offset.Hours >= 0 ? '+' : '-', span);

            string result = string.Format("(TIMESTAMPTZ '{0}{1}')", date, span);

            return(result);

            // Npgsql 的显示都是以本地时区显示的?###
        }
Exemplo n.º 3
0
        protected override IDbDataParameter AddParameter(object value, object dbType, int?size = null, int?precision = null, int?scale = null, ParameterDirection?direction = null)
        {
            NpgsqlParameter parameter = (NpgsqlParameter)base.AddParameter(value, dbType, size, precision, scale, direction);

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

            if (dbTypeInfo != null && dbTypeInfo.DbType != null)
            {
                parameter.DbType = dbTypeInfo.DbType.Value;
            }
            else if (dbTypeInfo != null && dbTypeInfo.SqlDbType != null)
            {
                parameter.NpgsqlDbType = 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);
        }
Exemplo n.º 4
0
        // 获取 DatetTime 类型的 SQL 片断
        protected override string GetSqlValueByDateTime(object value, object dbType, int?precision)
        {
            // 默认精度6
            string        format     = "yyyy-MM-dd HH:mm:ss.ffffff";
            NpgDbTypeInfo dbTypeInfo = NpgDbTypeInfo.Create(dbType);

            if (dbTypeInfo != null && dbTypeInfo.IsDate)
            {
                format = "yyyy-MM-dd";
            }
            else if (dbTypeInfo != null && (dbTypeInfo.IsDateTime || dbTypeInfo.IsDateTime2))
            {
                string pad = string.Empty;
                if (precision != null && precision.Value > 0)
                {
                    pad = "f".PadLeft(precision.Value > 6 ? 6 : 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);

            return(result);
        }