Beispiel #1
0
        //public override object AdaptValueToType(object value, DbTypeBase type)
        //{
        //    DateTime mintimestamp = new DateTime(1970, 1, 1, 0, 0, 1);
        //    DateTime maxtimestamp = new DateTime(2038, 1, 9, 3, 14, 7);
        //    if (type is DbTypeDatetime && type.GetSpecificAttribute("mysql", "subtype") == "timestamp" && value is DateTime)
        //    {
        //        DateTime dt = (DateTime)value;
        //        if (dt < mintimestamp) dt = mintimestamp;
        //        if (dt > maxtimestamp) dt = maxtimestamp;
        //    }
        //    return base.AdaptValueToType(value, type);
        //}

        public override string GetSpecificExpression(SqlSpecialConstant specConst, DbTypeBase type, IProgressInfo progress)
        {
            if (type is DbTypeDatetime && type.GetSpecificAttribute("mysql", "subtype") == "timestamp")
            {
                switch (specConst)
                {
                case SqlSpecialConstant.Current_Timestamp:
                case SqlSpecialConstant.Utc_Timestamp:
                    return("CURRENT_TIMESTAMP");
                }
            }
            if (type is DbTypeDatetime && type.GetSpecificAttribute("mysql", "subtype") == "datetime")
            {
                switch (specConst)
                {
                case SqlSpecialConstant.Current_Timestamp:
                case SqlSpecialConstant.Current_Time:
                case SqlSpecialConstant.Current_Date:
                case SqlSpecialConstant.Utc_Timestamp:
                    return("CURRENT_DATETIME");
                    //case SqlSpecialConstant.Current_Time: return "CURRENT_TIME";
                    //case SqlSpecialConstant.Current_Date: return "CURRENT_DATE";
                    //case SqlSpecialConstant.Utc_Timestamp: return "UTC_TIMESTAMP";
                }
            }
            return(null);
        }
Beispiel #2
0
        protected override void ApplyTypeRestrictions(BedValueHolder holder, DbTypeBase type, ILogger logger)
        {
            var htype = holder.GetFieldType();
            var dtype = type as DbTypeDatetime;

            if (dtype != null && type.GetSpecificAttribute("mysql", "subtype") == "timestamp" && htype.IsDateRelated())
            {
                var val = holder.GetDateTimeValue();
                val.MakeRestriction(m_mintimestamp, m_maxtimestamp);
                val.MakeValidDate();
                holder.SetDateTimeEx(val);
            }

            base.ApplyTypeRestrictions(holder, type, logger);
        }
Beispiel #3
0
        public override ISpecificType GenericTypeToSpecific(DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            switch (type.Code)
            {
            case DbTypeCode.Int:
                return(new SqliteTypeInt {
                    IsAutoIncrement = ((DbTypeInt)type).Autoincrement
                });

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

            case DbTypeCode.Float:
                return(new SqliteTypeReal());

            case DbTypeCode.Blob:
                return(new SqliteTypeBlob());

            case DbTypeCode.String:
            case DbTypeCode.Xml:
            case DbTypeCode.Array:
                return(new SqliteTypeText());

            case DbTypeCode.Datetime:
                return(new SqliteTypeDateTime());

            case DbTypeCode.Numeric:
                return(new SqliteTypeNumeric());

            case DbTypeCode.Text:
            {
                string subtype = type.GetSpecificAttribute("sqlite", "subtype");
                return(new SqliteTypeText {
                        SpecificCode = subtype
                    });
            }
            break;
            }
            return(new SqliteTypeText());
        }
Beispiel #4
0
        //public override bool IsSystemTable(string schema, string table)
        //{
        //    return table.Contains("$") || table == "HELP";
        //}

        public override ISpecificType GenericTypeToSpecific(DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            switch (type.Code)
            {
            case DbTypeCode.Array:
                return(new OracleTypeClob());

            case DbTypeCode.Blob:
                if (type.GetSpecificAttribute("oracle", "subtype") == "longraw")
                {
                    return(new OracleTypeLongRaw());
                }
                return(new OracleTypeBlob());

            case DbTypeCode.Datetime:
            {
                var    dtype   = (DbTypeDatetime)type;
                string subtype = type.GetSpecificAttribute("oracle", "subtype");
                if (subtype == "timestamp")
                {
                    var res = new OracleTypeTimestamp();
                    try { res.TimeZone = (TimeZoneType)Enum.Parse(typeof(TimeZoneType), type.GetSpecificAttribute("oracle", "timezone"), true); }
                    catch { res.TimeZone = TimeZoneType.None; }
                    string fprec = type.GetSpecificAttribute("oracle", "fractionalprecision");
                    if (fprec != null)
                    {
                        res.FractionalPrecision = Int32.Parse(fprec);
                    }
                    return(res);
                }
                if (subtype == "yeartomonth")
                {
                    var    res   = new OracleTypeIntervalYearToMonth();
                    string yprec = type.GetSpecificAttribute("oracle", "yearprecision");
                    if (yprec != null)
                    {
                        res.YearPrecision = Int32.Parse(yprec);
                    }
                    return(res);
                }
                if (subtype == "daytosecond")
                {
                    var    res   = new OracleTypeIntervalDayToSecond();
                    string dprec = type.GetSpecificAttribute("oracle", "dayprecision");
                    string fprec = type.GetSpecificAttribute("oracle", "fractionalprecision");
                    if (dprec != null)
                    {
                        res.DayPrecision = Int32.Parse(dprec);
                    }
                    if (fprec != null)
                    {
                        res.FractionalPrecision = Int32.Parse(fprec);
                    }
                    return(res);
                }
                if (dtype.SubType == DbDatetimeSubType.Interval)
                {
                    return(new OracleTypeIntervalDayToSecond());
                }
                return(new OracleTypeDate());
            }

            case DbTypeCode.Float:
                if (type.GetSpecificAttribute("oracle", "subtype") == "number")
                {
                    return(new OracleTypeNumber());
                }
                if (((DbTypeFloat)type).Bytes == 4)
                {
                    return(new OracleTypeBinaryFloat());
                }
                return(new OracleTypeBinaryDouble());

            case DbTypeCode.Generic:
                return(new OracleTypeGeneric {
                    Sql = ((DbTypeGeneric)type).Sql
                });

            case DbTypeCode.Int:
            {
                string ilen = type.GetSpecificAttribute("oracle", "length");
                if (ilen != null)
                {
                    return new OracleTypeNumber
                           {
                               Precision = Int32.Parse(ilen)
                           }
                }
                ;
            }
                return(new OracleTypeInteger());

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

            case DbTypeCode.Numeric:
            {
                var ntype = (DbTypeNumeric)type;
                if (type.GetSpecificAttribute("oracle", "noprec") == "1")
                {
                    return new OracleTypeNumber
                           {
                               Scale = ntype.Scale
                           }
                }
                ;
                return(new OracleTypeNumber
                    {
                        Precision = ntype.Precision,
                        Scale = ntype.Scale
                    });
            }

            case DbTypeCode.String:
            {
                string subtype = type.GetSpecificAttribute("oracle", "subtype");
                if (subtype != null)
                {
                    switch (subtype)
                    {
                    case "rowid": return(new OracleTypeRowId());

                    case "urowid": return(new OracleTypeURowId());

                    case "mlslabel": return(new OracleTypeMlsLabel());

                    case "bfile": return(new OracleTypeBFile());
                    }
                }
                var stype = (DbTypeString)type;
                if (stype.IsBinary)
                {
                    return new OracleTypeRaw {
                               Length = stype.Length
                    }
                }
                ;
                if (stype.IsVarLength)
                {
                    if (stype.IsUnicode)
                    {
                        return new OracleTypeNVarChar2 {
                                   Length = stype.Length
                        }
                    }
                    ;
                    else
                    {
                        return new OracleTypeVarChar2 {
                                   Length = stype.Length
                        }
                    };
                }
                else
                {
                    if (stype.IsUnicode)
                    {
                        return new OracleTypeNChar {
                                   Length = stype.Length
                        }
                    }
                    ;
                    else
                    {
                        return new OracleTypeChar {
                                   Length = stype.Length
                        }
                    };
                }
            }

            case DbTypeCode.Text:
                if (type.GetSpecificAttribute("oracle", "subtype") == "long")
                {
                    return(new OracleTypeLong());
                }
                if (((DbTypeText)type).IsUnicode)
                {
                    return(new OracleTypeNClob());
                }
                else
                {
                    return(new OracleTypeClob());
                }

            case DbTypeCode.Xml:
                return(new OracleTypeXml());
            }
            throw new Exception("DAE-00342 unknown type");
        }
Beispiel #5
0
        public override ISpecificType GenericTypeToSpecific(DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            switch (type.Code)
            {
            case DbTypeCode.Int:
                return(GetEfzTypeInt((DbTypeInt)type));

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

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

            case DbTypeCode.Datetime:
            {
                string attr  = type.GetSpecificAttribute("effiproz", "subtype");
                var    dtype = type as DbTypeDatetime;
                if (attr == "timestamp")
                {
                    var res = new EfzTypeTimestamp();
                    res.Precision = Int32.Parse(type.GetSpecificAttribute("effiproz", "precision"));
                    return(res);
                }
                if (attr == "yeartomonth")
                {
                    var res = new EfzTypeIntervalYearToMonth();
                    //res.Precision = Int32.Parse(type.GetSpecificAttribute("effiproz", "precision"));
                    return(res);
                }
                if (attr == "daytosecond")
                {
                    var res = new EfzTypeIntervalDayToSecond();
                    //res.Precision = Int32.Parse(type.GetSpecificAttribute("effiproz", "precision"));
                    return(res);
                }
                if (attr == "date")
                {
                    var res = new EfzTypeDate();
                    return(res);
                }

                switch (dtype.SubType)
                {
                case DbDatetimeSubType.Date:
                    return(new EfzTypeDate());

                case DbDatetimeSubType.Datetime:
                    if (dtype.HasTimeZone)
                    {
                        return(new EfzTypeTimestampTz());
                    }
                    else
                    {
                        return(new EfzTypeTimestamp());
                    }

                case DbDatetimeSubType.Interval:
                    return(new EfzTypeIntervalDayToSecond());

                case DbDatetimeSubType.Time:
                    return(new EfzTypeTimestamp());

                case DbDatetimeSubType.Year:
                    return(new EfzTypeDate());
                }
                return(new EfzTypeTimestamp());
            }

            case DbTypeCode.Numeric:
            {
                var res = new EfzTypeNumber();
                res.Precision  = ((DbTypeNumeric)type).Precision;
                res.Scale      = ((DbTypeNumeric)type).Scale;
                res.IsIdentity = ((DbTypeNumeric)type).Autoincrement;

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

            case DbTypeCode.Blob:
            {
                var    res  = new EfzTypeBlob();
                string size = type.GetSpecificAttribute("effiproz", "maxbytes");
                if (size != null)
                {
                    res.MaxBytes = Int32.Parse(size);
                }
                return(res);
            }

            case DbTypeCode.Text:
            {
                var    res  = new EfzTypeClob();
                string size = type.GetSpecificAttribute("effiproz", "maxbytes");
                if (size != null)
                {
                    res.MaxBytes = Int32.Parse(size);
                }
                return(res);
            }

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

            case DbTypeCode.Float:
                return(new EfzTypeDouble());

            case DbTypeCode.Xml:
                return(new EfzTypeClob());

            case DbTypeCode.Generic:
                return(new EfzTypeGeneric {
                    Sql = ((DbTypeGeneric)type).Sql
                });
            }
            throw new Exception("DAE-00323 unknown type");
        }
Beispiel #6
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");
        }