Exemplo n.º 1
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     FunctionName.GenerateSql(dmp);
     dmp.Put("%:s", LeftBracket, "(");
     Arguments.GenerateSql(dmp);
     dmp.Put("%:s", RightBracket, ")");
 }
Exemplo n.º 2
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     foreach (var qal in Qualificators)
     {
         qal.GenerateSql(dmp);
     }
     Name.GenerateSql(dmp);
 }
Exemplo n.º 3
0
        public static DbTypeBase Load(XmlElement xml)
        {
            DbTypeCode code = (DbTypeCode)Enum.Parse(typeof(DbTypeCode), xml.GetAttribute("datatype"), true);
            DbTypeBase res  = DbTypeBase.CreateType(code);

            res.LoadFromXml(xml);
            return(res);
        }
Exemplo n.º 4
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     for (int i = 0; i < UnaryMarks.Length; i++)
     {
         dmp.Put("&s%:k", UnaryMarks[i], Operator.Tokens[i]);
     }
     Inner.GenerateSql(dmp, targetType);
 }
Exemplo n.º 5
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     Value.GenerateSql(dmp);
     dmp.Put("&s%:k", BetweenPos, "between");
     LowerBound.GenerateSql(dmp);
     dmp.Put("&s%:k", AndPos, "and");
     UpperBound.GenerateSql(dmp);
 }
Exemplo n.º 6
0
        //public NameWithSchema FullName
        //{
        //    get { return new NameWithSchema(SchemaName, Name); }
        //    set { SchemaName = value.Schema; Name = value.Name; }
        //}

        //#region ITableStructure Members

        //IColumnCollection ITableStructure.Columns
        //{
        //    get { return Columns; }
        //}

        //IList<IConstraint> ITableStructure.Constraints
        //{
        //    get { return Constraints.ToTypedList<IConstraint>(); }
        //}

        //IList<IForeignKey> ITableStructure.ReferencedFrom
        //{
        //    get { return ReferencedFrom.ToTypedList<IForeignKey>(); }
        //}

        ////TableStructureMembers ITableStructure.FilledMembers
        ////{
        ////    get { return FilledMembers; }
        ////}

        //#endregion

        public ColumnStructure AddColumn(string name, DbTypeBase datatype)
        {
            ColumnStructure col = new ColumnStructure();

            col.ColumnName = name;
            col.DataType   = datatype;
            _Columns.Add(col);
            return(col);
        }
Exemplo n.º 7
0
        public virtual DbTypeBase MigrateDataType(IColumnStructure owningColumn, DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            ISpecificType spectype = GenericTypeToSpecific(type, profile, progress);

            //if (!DialectCaps.Arrays && type.ArraySpec.IsArray)
            //{
            //    return new DbTypeText(); // migrate arrays as text blob
            //}
            return(spectype.ToGenericType());
        }
Exemplo n.º 8
0
 // GenerateSql can return NULL, if SQL cannot be generated for given dialect
 public string GenerateSql(ISqlDialect dialect, DbTypeBase targetType, IProgressInfo progress)
 {
     try
     {
         return(dialect.GenerateScript(dmp => { dmp.ProgressInfo = progress; GenerateSql(dmp, targetType); }));
     }
     catch (SyntaxNotSupportedError)
     {
         return(null);
     }
 }
Exemplo n.º 9
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     if (targetType is DbTypeLogical)
     {
         dmp.Put("%:s", Original, dmp.Dialect.GetSqlLiteral(m_value != 0));
     }
     else
     {
         dmp.Put("&s%:s", Original, m_value.ToString(CultureInfo.InvariantCulture));
     }
 }
Exemplo n.º 10
0
        private void LoadInternal(XmlElement xml)
        {
            m_dataType = DbTypeBase.Load(xml);
            XmlTool.LoadSpecificAttributes(SpecificData, "colspec.", xml);
            var defval = xml.FindElement("Default");

            if (defval != null)
            {
                m_defaultValue = SqlExpression.Load(defval);
            }
            Domain = NameWithSchema.LoadFromXml(xml, "domain.");
        }
Exemplo n.º 11
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     if (m_dialect == null)
     {
         dmp.Put("%:s", Original, m_expr);
         return;
     }
     if (dmp.Dialect.DialectName != m_dialect)
     {
         throw new SyntaxNotSupportedError("DAE-00250 Specific expression has other target dialect");
     }
     dmp.Put("%:s", Original, m_expr);
 }
Exemplo n.º 12
0
 public void AdaptValue(IBedValueReader reader, DbTypeBase type, IBedValueWriter writer, IBedValueConvertor converter, ILogger logger)
 {
     if (reader.GetFieldType() == TypeStorage.Null)
     {
         m_holder.SetNull();
     }
     else
     {
         converter.ConvertValue(reader, type.DefaultStorage, m_holder);
         ApplyTypeRestrictions(m_holder, type, logger);
     }
     writer.ReadFrom(m_holder);
 }
Exemplo n.º 13
0
        public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
        {
            string expr = dmp.Dialect.GetSpecificExpression(m_specConst, targetType, dmp.ProgressInfo);

            if (expr != null)
            {
                dmp.Put("%:s", Original, expr);
            }
            else
            {
                throw new SyntaxNotSupportedError("DAE-00249 Specific constant not supported");
            }
        }
Exemplo n.º 14
0
        public DomainStructure(XmlElement xml)
            : base(xml)
        {
            //this.LoadProperties(xml);
            SpecificData = XmlTool.LoadParameters(xml);
            FullName     = NameWithSchema.LoadFromXml(xml);
            DataType     = DbTypeBase.Load(xml);
            var defval = xml.FindElement("Default");

            if (defval != null)
            {
                DefaultValue = SqlExpression.Load(defval);
            }
        }
Exemplo n.º 15
0
 public ColumnStructure(IColumnStructure src)
     : base(src)
 {
     m_columnName   = src.ColumnName;
     m_dataType     = src.DataType.Clone();
     m_isNullable   = src.IsNullable;
     m_defaultValue = src.DefaultValue;
     m_characterSet = src.CharacterSet;
     m_collation    = src.Collation;
     SpecificData.AddAll(src.SpecificData);
     //TableName = src.Table;
     //Table = src.Table;
     Domain = src.Domain;
 }
Exemplo n.º 16
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     dmp.Put("&s%:k", CasePos, "case");
     CaseVal.GenerateSql(dmp);
     foreach (var when in Whens)
     {
         when.GenerateSql(dmp);
     }
     if (ElseVal != null)
     {
         dmp.Put("&s%:k", ElsePos, "else");
         ElseVal.GenerateSql(dmp);
     }
     dmp.Put("&s%:k", EndPos, "end");
 }
Exemplo n.º 17
0
 public static bool EqualTypes(DbTypeBase t1, DbTypeBase t2, DbDiffOptions opts)
 {
     if (!opts.IgnoreSpecificData && !t1.SpecificData.EqualsDictionary(t2.SpecificData, opts.IgnoreDataTypeProperties))
     {
         opts.DiffLogger.Trace("Types {0}, {1}: different specific data: {2}; {3}", t1, t2, t1.SpecificData.Format(), t2.SpecificData.Format());
         return(false);
     }
     if (t1.Code != t2.Code)
     {
         opts.DiffLogger.Trace("Types {0}, {1}: different type code: {2}; {3}", t1, t2, t1.Code, t2.Code);
         return(false);
     }
     if (!XmlTool.PropertiesEquals(t1, t2, opts.DiffLogger))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 18
0
        public override void AddLogicalDependencies(AlterProcessorCaps caps, DbDiffOptions opts, List <AlterOperation> before, List <AlterOperation> after, AlterPlan plan, IDatabaseSource targetDb)
        {
            ParentTable.LoadStructure(TableStructureMembers.ReferencedFrom, targetDb);
            var oldcol = OldObject as ColumnStructure;
            var newcol = NewObject as ColumnStructure;

            List <IForeignKey> recreateFks = new List <IForeignKey>();
            var changeCols = new List <Tuple <IColumnStructure, IColumnStructure> >();

            foreach (ForeignKey fk in ParentTable.GetReferencedFrom())
            {
                for (int i = 0; i < fk.PrimaryKeyColumns.Count; i++)
                {
                    if (fk.PrimaryKeyColumns[i].ColumnName == oldcol.ColumnName)
                    {
                        //plan.RecreateObject(fk, null);
                        TableStructure table = (TableStructure)fk.Table;
                        table.LoadStructure(TableStructureMembers.Columns, targetDb);
                        ColumnStructure othercol = table.Columns[fk.Columns[i].ColumnName] as ColumnStructure;

                        // compare types with ignoring autoincrement flag
                        // HACK: ignore specific attributes
                        var opts2 = opts.Clone();
                        opts2.IgnoreSpecificData = true;
                        DbTypeBase dt1 = othercol.DataType.Clone(), dt2 = newcol.DataType.Clone();
                        dt1.SetAutoincrement(false);
                        dt2.SetAutoincrement(false);
                        if (!DbDiffTool.EqualTypes(dt1, dt2, opts2))
                        {
                            after.Add(new AlterOperation_ChangeColumn
                            {
                                ParentTable = table,
                                OldObject   = othercol,
                                NewObject   = new ColumnStructure(othercol)
                                {
                                    DataType = dt2
                                }
                            });
                        }
                        opts.AlterLogger.Warning(Texts.Get("s_changed_referenced_column$table$column", "table", fk.Table.FullName, "column", othercol.ColumnName));
                    }
                }
            }
        }
Exemplo n.º 19
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     if (dmp.Dialect.PossibleKeywords.Contains(Identifier.ToUpper()))
     {
         // we cannot change quoting
         if (IsQuoted)
         {
             dmp.Put("&s%:s", Original, dmp.Dialect.QuoteIdentBegin + Identifier + dmp.Dialect.QuoteIdentEnd);
         }
         else
         {
             dmp.Put("&s%:s", Original, Identifier);
         }
     }
     else
     {
         dmp.Put("&s%:i", Original, Identifier);
     }
 }
Exemplo n.º 20
0
        public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
        {
            switch (Token)
            {
            case TokenType.StringSingle:
                dmp.Put("%:v", Original, Data);
                break;

            case TokenType.QuotedIdent:
                var old = dmp.FormatProperties.IdentifierQuoteMode;
                dmp.FormatProperties.IdentifierQuoteMode = SqlIdentifierQuoteMode.Quoted;
                dmp.Put("%:v", Original, Data);
                dmp.FormatProperties.IdentifierQuoteMode = old;
                break;

            case TokenType.StringDouble:
                dmp.Put("%:s", Original, '"' + Data + '"');
                break;
            }
        }
Exemplo n.º 21
0
        protected virtual void ApplyTypeRestrictions(BedValueHolder holder, DbTypeBase type, ILogger logger)
        {
            var stype = type as DbTypeString;
            var htype = holder.GetFieldType();

            if (stype != null && htype == TypeStorage.String)
            {
                string sval = holder.GetString();
                if (stype.Length > 0 && sval.Length > stype.Length)
                {
                    sval = sval.Substring(0, stype.Length);
                    holder.SetString(sval);
                }
            }
            if (htype.IsDateRelated() && !m_allowZeroInDate)
            {
                var dt = holder.GetDateTimeValue();
                dt.MakeValidDate();
                m_holder.SetDateTimeEx(dt);
            }
        }
Exemplo n.º 22
0
 public static ISpecificType GenericTypeToSpecific(this ISqlDialect dialect, DbTypeBase type)
 {
     return(dialect.GenericTypeToSpecific(type, null, null));
 }
Exemplo n.º 23
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     dmp.Put("&s%:s", Original, "*");
 }
Exemplo n.º 24
0
        //public virtual string Symbols { get { return "()=+-<>*/"; } }

        public virtual string GetSpecificExpression(SqlSpecialConstant specConst, DbTypeBase type, IProgressInfo progress)
        {
            return(null);
        }
Exemplo n.º 25
0
 public virtual ISpecificType CreateSpecificTypeInstance(object enumValue)
 {
     return(DbTypeBase.CreateType((DbTypeCode)enumValue));
 }
Exemplo n.º 26
0
 public abstract void GenerateSql(ISqlDumper dmp, DbTypeBase targetType);
Exemplo n.º 27
0
 public virtual bool SupportsColumnCollation(DbTypeBase coltype)
 {
     return(false);
 }
Exemplo n.º 28
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     dmp.Put("%:s", LeftBracket, "(");
     Inner.GenerateSql(dmp);
     dmp.Put("%:s", RightBracket, ")");
 }
Exemplo n.º 29
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     dmp.Put("%:v", Original, m_value);
 }
Exemplo n.º 30
0
 public override void GenerateSql(ISqlDumper dmp, DbTypeBase targetType)
 {
     dmp.Put("^:null", Original);
 }