Beispiel #1
0
        private SqlTypeBase MakeSpecificSqlType(string dt, int len, int prec, int scale)
        {
            switch (dt)
            {
            case "binary":
            {
                SqlTypeBinary res = new SqlTypeBinary();
                res.Length = len;
                return(res);
            }

            case "image":
                return(new SqlTypeImage());

            case "timestamp":
                return(new SqlTypeTimestamp());

            case "varbinary":
            {
                SqlTypeVarBinary res = new SqlTypeVarBinary();
                res.Length = len;
                return(res);
            }

            case "bit":
                return(new SqlTypeBit());

            case "tinyint":
                return(new SqlTypeTinyInt());

            case "datetime":
                return(new SqlTypeDatetime());

            case "datetime2":
                return(new SqlTypeDatetime2());

            case "datetimeoffset":
                return(new SqlTypeDatetimeOffset());

            case "date":
                return(new SqlTypeDate());

            case "time":
                return(new SqlTypeTime());

            case "smalldatetime":
                return(new SqlTypeSmallDatetime());

            case "decimal":
            {
                SqlTypeDecimal res = new SqlTypeDecimal();
                res.Precision = prec;
                res.Scale     = scale;
                return(res);
            }

            case "numeric":
            {
                SqlTypeNumeric res = new SqlTypeNumeric();
                res.Precision = prec;
                res.Scale     = scale;
                return(res);
            }

            case "float":
                return(new SqlTypeFloat());

            case "uniqueidentifier":
                return(new SqlTypeUniqueIdentifier());

            case "smallint":
                return(new SqlTypeSmallInt());

            case "int":
                return(new SqlTypeInt());

            case "bigint":
                return(new SqlTypeBigInt());

            case "real":
                return(new SqlTypeReal());

            case "char":
            {
                SqlTypeChar res = new SqlTypeChar();
                res.Length = len;
                return(res);
            }

            case "nchar":
            {
                SqlTypeNChar res = new SqlTypeNChar();
                res.Length = len;
                return(res);
            }

            case "varchar":
            {
                SqlTypeVarChar res = new SqlTypeVarChar();
                res.Length = len;
                return(res);
            }

            case "nvarchar":
            {
                SqlTypeNVarChar res = new SqlTypeNVarChar();
                res.Length = len;
                return(res);
            }

            case "text":
                return(new SqlTypeText());

            case "ntext":
                return(new SqlTypeNText());

            case "xml":
                return(new SqlTypeXml());

            case "money":
                return(new SqlTypeMoney());

            case "smallmoney":
                return(new SqlTypeSmallMoney());

            case "sql_variant":
                return(new SqlTypeVariant());
            }
            ReportUnknownType(dt);
            return(new SqlTypeGeneric {
                Sql = dt
            });
        }
Beispiel #2
0
        public override ISpecificType GenericTypeToSpecific(DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            switch (type.Code)
            {
            case DbTypeCode.Int:
                return(GetSqlTypeInt((DbTypeInt)type));

            case DbTypeCode.String:
                return(GetSqlTypeString((DbTypeString)type));

            case DbTypeCode.Logical:
                return(new SqlTypeBit());

            case DbTypeCode.Datetime:
            {
                string attr  = type.GetSpecificAttribute("mssql", "subtype");
                var    dtype = type as DbTypeDatetime;
                if (attr == "timestamp")
                {
                    return(new SqlTypeTimestamp());
                }
                if (attr == "datetime")
                {
                    return(new SqlTypeDatetime());
                }
                if (attr == "smalldatetime")
                {
                    return(new SqlTypeSmallDatetime());
                }
                if (m_version.Is_2008())
                {
                    if (dtype.HasTimeZone)
                    {
                        return(new SqlTypeDatetimeOffset());
                    }
                    if (dtype.SubType == DbDatetimeSubType.Date)
                    {
                        return(new SqlTypeDate());
                    }
                    if (dtype.SubType == DbDatetimeSubType.Time)
                    {
                        return(new SqlTypeTime());
                    }
                    if (attr == "datetime2")
                    {
                        return(new SqlTypeDatetime2());
                    }
                    // on 2008 server prefer datetime2 type
                    // NO: return new SqlTypeDatetime2();
                }
                return(new SqlTypeDatetime());
            }

            case DbTypeCode.Numeric:
            {
                SqlTypeNumericBase res;
                if (type.GetSpecificAttribute("mssql", "subtype") == "decimal")
                {
                    res = new SqlTypeDecimal();
                }
                else
                {
                    res = new SqlTypeNumeric();
                }
                res.Precision  = ((DbTypeNumeric)type).Precision;
                res.Scale      = ((DbTypeNumeric)type).Scale;
                res.IsIdentity = ((DbTypeNumeric)type).Autoincrement;

                int increment;
                if (Int32.TryParse(type.GetSpecificAttribute("mssql", "identity_increment"), out increment))
                {
                    res.IdentityIncrement = increment;
                    res.IdentitySeed      = Int32.Parse(type.GetSpecificAttribute("mssql", "identity_seed"));
                }
                return(res);
            }

            //return String.Format("decimal({0},{1})", ((DbTypeNumeric)type).Precision, ((DbTypeNumeric)type).Scale);
            case DbTypeCode.Blob:
                if (type.GetSpecificAttribute("mssql", "subtype") == "variant")
                {
                    return(new SqlTypeVariant());
                }
                return(new SqlTypeImage());

            case DbTypeCode.Text:
                if (((DbTypeText)type).IsUnicode)
                {
                    return(new SqlTypeNText());
                }
                else
                {
                    return(new SqlTypeText());
                }

            case DbTypeCode.Array:
                return(new SqlTypeText());

            case DbTypeCode.Float:
            {
                DbTypeFloat tp = (DbTypeFloat)type;
                if (tp.IsMoney)
                {
                    if (tp.Bytes == 8)
                    {
                        return(new SqlTypeSmallMoney());
                    }
                    return(new SqlTypeMoney());
                }
                if (tp.Bytes == 4)
                {
                    return(new SqlTypeReal());
                }
                else
                {
                    return(new SqlTypeFloat());
                }
            }

            case DbTypeCode.Xml:
                if (m_version.Is_2005())
                {
                    return(new SqlTypeXml());
                }
                return(new SqlTypeText());

            case DbTypeCode.Generic:
                return(new SqlTypeGeneric {
                    Sql = ((DbTypeGeneric)type).Sql
                });
            }
            throw new InternalError("DAE-00332 unknown type");
        }