Пример #1
0
 /// <summary>
 /// 设置命令参数对象的 DbType属性
 /// </summary>
 /// <param name="parameter">命令参数对象</param>
 /// <param name="dbType">DbType属性</param>
 public static void SetDbType(this NpgsqlParameter parameter, object dbType)
 {
     if (dbType != null)
     {
         if (dbType is DbType)
         {
             parameter.DbType = (DbType)dbType;
         }
         else if (dbType is NpgsqlDbType)
         {
             parameter.NpgsqlDbType = (NpgsqlDbType)dbType;
         }
         else
         {
             DbTypeUtils.ThrowException(dbType);
         }
     }
 }
Пример #2
0
 /// <summary>
 /// 是否日期+时间类型
 /// </summary>
 public static bool IsDateTime(object dbType)
 {
     if (dbType == null)
     {
         return(false);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.DateTime);
     }
     else if (dbType is NpgsqlDbType)
     {
         return(((NpgsqlDbType)dbType) == NpgsqlDbType.Timestamp);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #3
0
 /// <summary>
 /// 是否日期类型
 /// </summary>
 public static bool IsDate(object dbType)
 {
     if (dbType == null)
     {
         return(false);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.Date);
     }
     else if (dbType is SqlDbType)
     {
         return(((SqlDbType)dbType) == SqlDbType.Date);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #4
0
 /// <summary>
 /// 是否日期+时间+精度类型
 /// </summary>
 public static bool IsDateTime2(object dbType)
 {
     if (dbType == null)
     {
         return(false);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.DateTime2);
     }
     else if (dbType is OracleDbType)
     {
         return(((OracleDbType)dbType) == OracleDbType.TimeStamp);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #5
0
 /// <summary>
 /// 检查是否Unicode数据类型
 /// </summary>
 public static bool IsUnicode(object dbType)
 {
     if (dbType == null)
     {
         return(true);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.String || ((DbType)dbType) == DbType.StringFixedLength);
     }
     else if (dbType is OracleDbType)
     {
         return(((OracleDbType)dbType) == OracleDbType.NVarchar2 || ((OracleDbType)dbType) == OracleDbType.NChar || ((OracleDbType)dbType) == OracleDbType.NClob);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #6
0
 /// <summary>
 /// 是否时间类型
 /// </summary>
 public static bool IsTime(object dbType)
 {
     if (dbType == null)
     {
         return(false);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.Time);
     }
     else if (dbType is MySqlDbType)
     {
         return(((MySqlDbType)dbType) == MySqlDbType.Time);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #7
0
 /// <summary>
 /// 检查是否Unicode数据类型
 /// </summary>
 public static bool IsUnicode(object dbType)
 {
     // 默认加 N
     if (dbType == null)
     {
         return(true);
     }
     else if (dbType is DbType)
     {
         return(((DbType)dbType) == DbType.String || ((DbType)dbType) == DbType.StringFixedLength);
     }
     else if (dbType is SqlDbType)
     {
         return(((SqlDbType)dbType) == SqlDbType.NVarChar || ((SqlDbType)dbType) == SqlDbType.NChar || ((SqlDbType)dbType) == SqlDbType.NText);
     }
     else
     {
         return(DbTypeUtils.ThrowException(dbType));
     }
 }
Пример #8
0
        /// <summary>
        /// 是否日期+时间+精度+时区类型
        /// </summary>
        public static bool IsDateTimeOffset(object dbType)
        {
#if netcore
            if (dbType == null)
            {
                return(false);
            }
            else if (dbType is DbType)
            {
                return(((DbType)dbType) == DbType.DateTimeOffset);
            }
            else if (dbType is NpgsqlDbType)
            {
                return(((NpgsqlDbType)dbType) == NpgsqlDbType.TimestampTz);
            }
            else
            {
                return(DbTypeUtils.ThrowException(dbType));
            }
#endif
#if !netcore
            if (dbType == null)
            {
                return(false);
            }
            else if (dbType is DbType)
            {
                return(((DbType)dbType) == DbType.DateTimeOffset);
            }
            else if (dbType is NpgsqlDbType)
            {
                return(((NpgsqlDbType)dbType) == NpgsqlDbType.TimestampTZ);
            }
            else
            {
                return(DbTypeUtils.ThrowException(dbType));
            }
#endif
        }
Пример #9
0
        /// <summary>
        /// 是否时间类型
        /// </summary>
        public static bool IsTime(object dbType)
        {
#if netcore
            if (dbType == null)
            {
                return(false);
            }
            else if (dbType is DbType)
            {
                return(((DbType)dbType) == DbType.Time);
            }
            else if (dbType is NpgsqlDbType)
            {
                return(((NpgsqlDbType)dbType) == NpgsqlDbType.Time);
            }
            else
            {
                return(DbTypeUtils.ThrowException(dbType));
            }
#endif
#if !netcore
            throw new NotSupportedException("Npgsql does not support Time DbType.");
#endif
        }