Пример #1
0
        public static int GetDefaultSize(this DataTypeConstants dataType, int length)
        {
            var size = length;

            switch (dataType)
            {
            case DataTypeConstants.Decimal:
            case DataTypeConstants.Real:
                size = 18;
                break;

            case DataTypeConstants.Binary:
            case DataTypeConstants.NVarChar:
            case DataTypeConstants.VarBinary:
            case DataTypeConstants.VarChar:
                size = 50;
                break;

            case DataTypeConstants.Char:
            case DataTypeConstants.NChar:
                size = 10;
                break;

            case DataTypeConstants.DateTime2:
                size = 2;
                break;
            }
            return(size);
        }
Пример #2
0
 public static bool SupportsIdentity(this DataTypeConstants dataType)
 {
     return(dataType == DataTypeConstants.BigInt ||
            dataType == DataTypeConstants.Int ||
            dataType == DataTypeConstants.SmallInt ||
            dataType == DataTypeConstants.UniqueIdentifier);
 }
Пример #3
0
        /// <summary>
        /// Verifies that length does not exceed the maximum length value for the specified variable length data type
        /// Predefined length like integers are not processed
        /// </summary>
        /// <param name="type"></param>
        /// <param name="length"></param>
        /// <returns>The lesser of the values maximum length and the specified length</returns>
        public static int ValidateDataTypeMax(this DataTypeConstants type, int length)
        {
            switch (type)
            {
            case DataTypeConstants.Char:
                return((length > 8000) ? 8000 : length);

            case DataTypeConstants.VarChar:
                return((length > 8000) ? 8000 : length);

            case DataTypeConstants.NChar:
                return((length > 4000) ? 4000 : length);

            case DataTypeConstants.NVarChar:
                return((length > 4000) ? 4000 : length);

            case DataTypeConstants.Decimal:
                return((length > 38) ? 38 : length);

            case DataTypeConstants.DateTime2:
                return((length > 7) ? 7 : length);

            case DataTypeConstants.Binary:
            case DataTypeConstants.VarBinary:
                return((length > 8000) ? 8000 : length);
            }
            return(length);
        }
Пример #4
0
 /// <summary>
 /// Given a datatype and length, it will return a display string for this datatype
 /// </summary>
 /// <param name="dataType"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public static string GetLengthString(this DataTypeConstants dataType, int length)
 {
     if (dataType.SupportsMax() && length == 0)
     {
         return("max");
     }
     else
     {
         return(length.ToString());
     }
 }
Пример #5
0
 public static bool IsDecimalType(this DataTypeConstants dataType)
 {
     switch (dataType)
     {
     case DataTypeConstants.Decimal:
     case DataTypeConstants.Float:
     case DataTypeConstants.Real:
         return(true);
     }
     return(false);
 }
Пример #6
0
        /// <summary>
        /// Gets the scale of the data type (decimals only)
        /// </summary>
        public static int GetPredefinedScale(this DataTypeConstants type)
        {
            //Returns -1 if variable
            switch (type)
            {
            case DataTypeConstants.Decimal:
                return(-1);

            default:
                return(0);
            }
        }
Пример #7
0
            protected override void OnValueChanged(FieldBase element, DataTypeConstants oldValue, DataTypeConstants newValue)
            {
                base.OnValueChanged(element, oldValue, newValue);

                if (element.Entity != null && element.Entity.nHydrateModel != null)
                {
                    if (!element.Entity.nHydrateModel.IsLoading)
                    {
                        element.Length = newValue.GetDefaultSize(element.Length);
                    }
                }
            }
Пример #8
0
 public static bool IsIntegerType(this DataTypeConstants dataType)
 {
     switch (dataType)
     {
     case DataTypeConstants.BigInt:
     case DataTypeConstants.Int:
     case DataTypeConstants.TinyInt:
     case DataTypeConstants.SmallInt:
         return(true);
     }
     return(false);
 }
Пример #9
0
        /// <summary>
        /// Determines if this type supports the MAX syntax in SQL 2008
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool SupportsMax(this DataTypeConstants type)
        {
            switch (type)
            {
            case DataTypeConstants.VarChar:
            case DataTypeConstants.NVarChar:
            case DataTypeConstants.VarBinary:
                return(true);

            default:
                return(false);
            }
        }
Пример #10
0
        private static bool IsBinaryType(this DataTypeConstants dataType)
        {
            switch (dataType)
            {
            case DataTypeConstants.Binary:
            case DataTypeConstants.Image:
            case DataTypeConstants.VarBinary:
                return(true);

            default:
                return(false);
            }
        }
Пример #11
0
        /// <summary>
        /// Gets the SQL Server type mapping for this data type
        /// </summary>
        /// <param name="isRaw">Determines if the square brackets '[]' are around the type</param>
        /// <returns>The SQL ready datatype like '[Int]' or '[Varchar] (100)'</returns>
        public static string GetSQLDefaultType(this DataTypeConstants dataType, bool isRaw, int length, int scale)
        {
            var retval = string.Empty;

            if (!isRaw)
            {
                retval += "[";
            }
            retval += dataType.ToString();
            if (!isRaw)
            {
                retval += "]";
            }

            if (dataType == DataTypeConstants.Variant)
            {
                retval = string.Empty;
                if (!isRaw)
                {
                    retval += "[";
                }
                retval += "sql_variant";
                if (!isRaw)
                {
                    retval += "]";
                }
            }
            else if (dataType == DataTypeConstants.Binary ||
                     dataType == DataTypeConstants.Char ||
                     dataType == DataTypeConstants.Decimal ||
                     dataType == DataTypeConstants.NChar ||
                     dataType == DataTypeConstants.NVarChar ||
                     dataType == DataTypeConstants.VarBinary ||
                     dataType == DataTypeConstants.VarChar)
            {
                if (dataType == DataTypeConstants.Decimal)
                {
                    retval += " (" + length + ", " + scale + ")";
                }
                else if (dataType == DataTypeConstants.DateTime2)
                {
                    retval += " (" + length + ")";
                }
                else
                {
                    retval += " (" + dataType.GetLengthString(length) + ")";
                }
            }
            return(retval);
        }
Пример #12
0
 /// <summary>
 /// OracleProcParam ctor to setup for the add of any kind of array
 /// </summary>
 /// <param name="pDir"></param>
 /// <param name="pDName"></param>
 /// <param name="pName"></param>
 /// <param name="pArrSize"></param>
 public OracleProcParam(
     ParameterDirection pDir,
     DataTypeConstants.PawnDataType pDName,
     string pName,
     int pArrSize)
 {
     this.Direction = pDir;
     this.paramIsClob = false;
     this.dataTypeName = pDName;
     this.Name = pName;
     this.parameterValues = new List<object>(1);
     this.arraySize = pArrSize;
     this.ComputeDataType();
 }
Пример #13
0
        public static bool IsTextType(this DataTypeConstants dataType)
        {
            switch (dataType)
            {
            case DataTypeConstants.Char:
            case DataTypeConstants.NChar:
            case DataTypeConstants.NText:
            case DataTypeConstants.NVarChar:
            case DataTypeConstants.Text:
            case DataTypeConstants.VarChar:
            case DataTypeConstants.Xml:
                return(true);

            default:
                return(false);
            }
        }
Пример #14
0
        public static bool IsSupportedType(this DataTypeConstants type)
        {
            switch (type)
            {
            //case DataTypeConstants.Xml:
            case DataTypeConstants.Udt:
            case DataTypeConstants.Structured:
            case DataTypeConstants.Variant:
                //case DataTypeConstants.DateTimeOffset:
                //case DataTypeConstants.DateTime2:
                //case DataTypeConstants.Time:
                //case DataTypeConstants.Date:
                return(false);

            default:
                return(true);
            }
        }
Пример #15
0
        public static bool IsSupportedType(DataTypeConstants type, DatabaseTypeConstants sqlVersion)
        {
            if (sqlVersion == DatabaseTypeConstants.SQL2005)
            {
                switch (type)
                {
                //case DataTypeConstants.Xml:
                case DataTypeConstants.Udt:
                case DataTypeConstants.Structured:
                case DataTypeConstants.Variant:
                case DataTypeConstants.DateTimeOffset:
                case DataTypeConstants.DateTime2:
                case DataTypeConstants.Time:
                case DataTypeConstants.Date:
                    return(false);

                default:
                    return(true);
                }
            }
            else if ((sqlVersion == DatabaseTypeConstants.SQL2008) || (sqlVersion == DatabaseTypeConstants.SQLAzure))
            {
                switch (type)
                {
                //case DataTypeConstants.Xml:
                case DataTypeConstants.Udt:
                case DataTypeConstants.Structured:
                case DataTypeConstants.Variant:
                    //case DataTypeConstants.DateTimeOffset:
                    //case DataTypeConstants.DateTime2:
                    //case DataTypeConstants.Time:
                    //case DataTypeConstants.Date:
                    return(false);

                default:
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #16
0
 // ReSharper restore UnusedMember.Global
 /// <summary>
 /// Overriding type constructor for any direction parameters
 /// </summary>
 /// <param name="pName"></param>
 /// <param name="pDt"></param>
 /// <param name="val"></param>
 /// <param name="pDir"></param>
 /// <param name="sZ"></param>
 /// <param name="preserveType"></param>
 // ReSharper disable UnusedMember.Global
 public OracleProcParam(string pName, DataTypeConstants.PawnDataType pDt, object val, ParameterDirection pDir, int sZ, bool preserveType)
 {
     if (pDt == DataTypeConstants.PawnDataType.CLOB)
     {
         this.paramIsClob = true;
     }
     this.Direction = pDir;
     this.dataTypeName = pDt;
     this.Name = pName;
     this.parameterValues = new List<object>(1);
     this.ComputeDataType();
     if (this.Direction == ParameterDirection.Input && val != null)
     {
         if (preserveType)
         {
             this.AddValue(val);
         }
         else
         {
             this.AddValue(val.ToString());
         }
     }
     else if (val != null)
     {
         this.AddValue(DBNull.Value);
     }
     this.arraySize = sZ;
 }
Пример #17
0
 /// <summary>
 /// Gets the SQL Server type mapping for this data type
 /// </summary>
 public static string GetSQLDefaultType(this DataTypeConstants dataType, int length, int scale)
 {
     return(dataType.GetSQLDefaultType(false, length, scale));
 }
Пример #18
0
 public static bool IsNumericType(this DataTypeConstants dataType)
 {
     return(dataType.IsDecimalType() || dataType.IsIntegerType());
 }
Пример #19
0
        /// <summary>
        /// Gets the size of the data type
        /// </summary>
        /// <returns></returns>
        /// <remarks>Returns -1 for variable types and 1 for blob fields</remarks>
        public static int GetPredefinedSize(this DataTypeConstants type)
        {
            //Returns -1 if variable
            switch (type)
            {
            case DataTypeConstants.BigInt:
                return(8);

            case DataTypeConstants.Bit:
                return(1);

            case DataTypeConstants.DateTime:
                return(8);

            case DataTypeConstants.Date:
                return(3);

            case DataTypeConstants.Time:
                return(5);

            case DataTypeConstants.DateTimeOffset:
                return(10);

            case DataTypeConstants.Float:
                return(8);

            case DataTypeConstants.Int:
                return(4);

            case DataTypeConstants.Money:
                return(8);

            case DataTypeConstants.Real:
                return(4);

            case DataTypeConstants.SmallDateTime:
                return(4);

            case DataTypeConstants.SmallInt:
                return(2);

            case DataTypeConstants.SmallMoney:
                return(4);

            case DataTypeConstants.Timestamp:
                return(8);

            case DataTypeConstants.TinyInt:
                return(1);

            case DataTypeConstants.UniqueIdentifier:
                return(16);

            case DataTypeConstants.Image:
                return(1);

            case DataTypeConstants.Text:
            case DataTypeConstants.NText:
                return(1);

            case DataTypeConstants.Xml:
                return(1);

            default:
                return(-1);
            }
        }
Пример #20
0
            protected override void OnValueChanged(FieldBase element, DataTypeConstants oldValue, DataTypeConstants newValue)
            {
                try
                {
                    base.OnValueChanged(element, oldValue, newValue);

                    if (element.Entity != null && element.Entity.nHydrateModel != null)
                    {
                        if (!element.Entity.nHydrateModel.IsLoading)
                        {
                            element.Length = newValue.GetDefaultSize(element.Length);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
Пример #21
0
        public static bool IsSupportedType(DataTypeConstants type, DatabaseTypeConstants sqlVersion)
        {
            if (sqlVersion == DatabaseTypeConstants.SQL2005)
            {
                switch (type)
                {
                    //case DataTypeConstants.Xml:
                    case DataTypeConstants.Udt:
                    case DataTypeConstants.Structured:
                    case DataTypeConstants.Variant:
                    case DataTypeConstants.DateTimeOffset:
                    case DataTypeConstants.DateTime2:
                    case DataTypeConstants.Time:
                    case DataTypeConstants.Date:
                        return false;
                    default:
                        return true;
                }
            }
            else if ((sqlVersion == DatabaseTypeConstants.SQL2008) || (sqlVersion == DatabaseTypeConstants.SQLAzure))
            {
                switch (type)
                {
                    //case DataTypeConstants.Xml:
                    case DataTypeConstants.Udt:
                    case DataTypeConstants.Structured:
                    case DataTypeConstants.Variant:
                        //case DataTypeConstants.DateTimeOffset:
                        //case DataTypeConstants.DateTime2:
                        //case DataTypeConstants.Time:
                        //case DataTypeConstants.Date:
                        return false;
                    default:
                        return true;
                }
            }
            else
            {
                return false;
            }

        }
 public static bool MySQLSupportedDatatype(DataTypeConstants type)
 {
     switch (type)
     {
         case DataTypeConstants.Variant:
         case DataTypeConstants.DateTimeOffset:
         case DataTypeConstants.Udt:
             return false;
         default:
             return true;
     }
 }