Example #1
0
        public static void CreateTable(this IDAC dac, TableSpecification tableSpecification)
        {
            var builder = dac.CreateSQLBuilder();

            builder.CreateTable(tableSpecification);
            dac.ExecuteBatch(builder);
        }
Example #2
0
        public virtual ISQLBuilder CreateTable(TableSpecification tableSpecification)
        {
            bool singularyPrimaryKey         = tableSpecification.PrimaryKey.Columns.Length == 1;
            bool hasDeclarationsAfterColumns = !singularyPrimaryKey;

            Emit("{0} ", FormatCreateTable(tableSpecification.Type))
            .TableName(tableSpecification.Name, tableSpecification.Type)
            .Emit("(")
            .NewLine();
            this.TabRight();
            foreach (var column in tableSpecification.Columns.WithDescriptions())
            {
                Emit(
                    "{0} {1}{2}{3}{4}",
                    SQLBuilderCommand.ColumnName(column.Item.Name),
                    !string.IsNullOrEmpty(column.Item.DataType) ? column.Item.DataType : ConvertTypeToSQLType(column.Item.Type),
                    singularyPrimaryKey && column.Item.Name == tableSpecification.PrimaryKey.Columns[0] ? " PRIMARY KEY" : string.Empty,
                    !column.Item.Nullable ? " NOT NULL" : string.Empty,
                    (column.Description.HasFlag(EnumeratedItemDescription.Last) && !hasDeclarationsAfterColumns) ? string.Empty : ", "
                    )
                .NewLine();
            }
            if (!singularyPrimaryKey)
            {
                Emit("PRIMARY KEY(");
                foreach (var primaryKeyColumn in tableSpecification.PrimaryKey.Columns.WithDescriptions())
                {
                    if (primaryKeyColumn.Description != EnumeratedItemDescription.Last)
                    {
                        Emit(", ");
                    }
                    this.ColumnName(primaryKeyColumn.Item);
                }
            }
            this.Untab();
            Emit(")");
            Emit(FormatCreateTableEnd(tableSpecification.Type));
            return(EndOfStatement(SQLStatementType.DDL));
        }
 public ISQLBuilder CreateTable(TableSpecification tableSpecification)
 {
     _internalBuilder.CreateTable(tableSpecification);
     return(this);
 }