protected override string GetColumnDefinition(IAddColumnNode columnDefinition, bool enforceNullable)
        {
            bool? pk = columnDefinition.PrimaryKey;
            columnDefinition.PrimaryKey = false;

            string definition = base.GetColumnDefinition(columnDefinition, enforceNullable);

            columnDefinition.PrimaryKey = pk;

            return definition;
        }
        /// <summary>
        /// Visits the given <paramref name="addColumnNode"/>.
        /// </summary>
        /// <param name="addColumnNode"></param>
        public override void Visit(IAddColumnNode addColumnNode)
        {
            //
            // Create an "IAddReferenceNode" for "references" property
            if(addColumnNode.Properties[MdlSyntax.References] != null)
            {
                IAstNodeProperty referencesProperty = addColumnNode.Properties[MdlSyntax.References];
                string references = AstNodePropertyUtil.AsString(referencesProperty.Value);

                IAddReferenceNode addReferenceNode = new AddReferenceNode(addColumnNode, "");
                addReferenceNode.Location = referencesProperty.Location;
                addReferenceNode.Properties.AddProperty(AstNodeProperty.String(MdlSyntax.PkTable, references));

                //
                // Propagate on-delete and on-update
                var onDelete = addColumnNode.Properties["on-delete"];
                if(onDelete != null)
                    addReferenceNode.Properties.AddProperty(onDelete);

                var onUpdate = addColumnNode.Properties["on-update"];
                if(onUpdate != null)
                    addReferenceNode.Properties.AddProperty(onUpdate);

                addColumnNode.ChildNodes.Add(addReferenceNode);
            } // if

            //
            // Create an 'IAddIndexNode" for "unique" property
            if(addColumnNode.Properties[MdlSyntax.Unique] != null)
            {
                IAstNodeProperty uniqueProperty = addColumnNode.Properties[MdlSyntax.Unique];

                IAddIndexNode addIndexNode = new AddIndexNode(addColumnNode, "");
                addIndexNode.Location = uniqueProperty.Location;
                addIndexNode.Properties.AddProperty(AstNodeProperty.String(MdlSyntax.Unique, "true"));

                addColumnNode.ChildNodes.Add(addIndexNode);
            } // if

            //
            // Create an 'IAddConstraintNode" for "default" property
            if(addColumnNode.Properties[MdlSyntax.Default] != null)
            {
                IAstNodeProperty defaultProperty = addColumnNode.Properties[MdlSyntax.Default];

                IAddConstraintNode addConstraintNode = new AddConstraintNode(addColumnNode, "");
                addConstraintNode.Location = defaultProperty.Location;
                addConstraintNode.Properties.AddProperty(new AstNodeProperty(MdlSyntax.Default, defaultProperty.Value));

                addColumnNode.ChildNodes.Add(addConstraintNode);
            } // if
        }
 /// <summary>
 /// Visits the given <paramref name="addColumnNode"/>.
 /// </summary>
 /// <param name="addColumnNode"></param>
 public override void Visit(IAddColumnNode addColumnNode)
 {
     Visit(addColumnNode.ChildNodes);
 }
        protected override string GetAddColumnDefinition(IAddColumnNode column)
        {
            var addColumn = base.GetAddColumnDefinition(column);
            if(column.Identity ?? false)
                addColumn += "identity ";

            return addColumn;
        }
        public override void Visit(IAddColumnNode addColumnNode)
        {
            textWriter.Write("add column {0}", GetIdentifier(addColumnNode.Name));

            WriteProperties(addColumnNode);
            VisitBlock(addColumnNode);
        }
        private ColumnDefinition BindAddColumn(IAddColumnNode addColumnNode)
        {
            ColumnDefinition column = new ColumnDefinition(addColumnNode.Name);
            BindColumnProperties(addColumnNode, column);

            return column;
        }
 /// <summary>
 /// Visits the given <paramref name="addColumnNode"/>.
 /// </summary>
 /// <param name="addColumnNode"></param>
 public override void Visit(IAddColumnNode addColumnNode)
 {
     /*IColumnDef
     IColumnBinding columnBinding = Environment.Resolve<IColumnBinding>(addColumnNode);
     InferColumnType(addColumnNode, columnBinding);*/
 }
        /// <summary>
        /// Visits the given <paramref name="addColumnNode"/>.
        /// </summary>
        /// <param name="addColumnNode"></param>
        public override void Visit(IAddColumnNode addColumnNode)
        {
            base.Visit(addColumnNode);

            //
            // If no "type" is specified, we can get that from the type of the
            // referenced column, if there is one
            if(addColumnNode.Type == null)
            {
                IAddReferenceNode addReferenceNode = GetFirst<IAddReferenceNode>(addColumnNode.ChildNodes);
                if(addReferenceNode != null)
                {
                    ITableDefinition pkTable = Environment.Schema.GetTable(addReferenceNode.PkTable);
                    IColumnDefinition pkColumn = pkTable.GetColumn(addReferenceNode.PkColumns[0]);
                    IColumnDefinition fkColumn =
                        Environment.Schema.GetTable(((ITableNode)addColumnNode.Parent).Name).GetColumn(addColumnNode.Name);

                    addColumnNode.Type = fkColumn.Type = pkColumn.Type;

                    if(!addColumnNode.Nullable.HasValue || !fkColumn.Nullable.HasValue)
                        addColumnNode.Nullable = fkColumn.Nullable = false;
                } // if
            } // if
        }
 /// <summary>
 /// Visits the given <paramref name="addColumnNode"/>.
 /// </summary>
 /// <param name="addColumnNode"></param>
 public override void Visit(IAddColumnNode addColumnNode)
 {
     ResolveTypeAlias(addColumnNode);
 }
        protected virtual string GetAddColumnDefinition(IAddColumnNode column)
        {
            var builder = new StringBuilder();
            builder.AppendFormat("\t{0} {1} {2} ", 
                EscapeIdentifier(column.Name),
                MapToNativeType(column),
                GetNullabilitySpecification(column));

            var @default = column. Properties[MdlSyntax.Default];
            if(@default != null)
                builder.AppendFormat(" default '{0}'", 
                    @default.Value is IStringAstNodePropertyValue ? 
                        AstNodePropertyUtil.AsString(@default.Value) :
                        AstNodePropertyUtil.AsInteger(@default.Value).ToString());
             
            return builder.ToString();
        }
        protected virtual string GetColumnDefinition(IAddColumnNode columnDefinition, bool enforceNullable)
        {
            StringBuilder columnDefinitionBuilder = new StringBuilder();
            columnDefinitionBuilder.AppendFormat("{0} {1} {2}", 
                Platform.Dialect.EscapeIdentifier(columnDefinition.Name),
                MapToNativeType(columnDefinition),
                    enforceNullable ? 
                        "null" :
                        columnDefinition.Nullable.HasValue ?
                            columnDefinition.Nullable.Value ? "null" : "not null" :
                            "");

            if(columnDefinition.Identity.HasValue && columnDefinition.Identity.Value)
                columnDefinitionBuilder.Append(" identity");

            if(columnDefinition.PrimaryKey.HasValue && columnDefinition.PrimaryKey.Value)
                columnDefinitionBuilder.Append(" primary key");
            else
                columnDefinitionBuilder.Append("");

            var @default = columnDefinition. Properties[MdlSyntax.Default];
            if(@default != null)
                columnDefinitionBuilder.AppendFormat(" default '{0}'", 
                    @default.Value is IStringAstNodePropertyValue ? 
                        AstNodePropertyUtil.AsString(@default.Value) :
                        AstNodePropertyUtil.AsInteger(@default.Value).ToString());

            return columnDefinitionBuilder.ToString();
        }
예제 #12
0
        /// <summary>
        /// Clones the given <paramref name="addColumnNode"/>.
        /// </summary>
        /// <param name="addColumnNode"></param>
        /// <returns></returns>
        public static IAddColumnNode Clone(IAddColumnNode addColumnNode)
        {
            IAddColumnNode node = new AddColumnNode(addColumnNode.Parent, addColumnNode.Name);
            SemanticModelUtil.Copy(addColumnNode, node);

            foreach(IAstNodeProperty property in addColumnNode.Properties)
                node.Properties.AddProperty(new AstNodeProperty(property.Name, property.Value));

            return node;
        }