Ejemplo n.º 1
0
        public virtual string GetTableColumnLine(DatabaseTableColumn tableColumn)
        {
            StringBuilder tableColumnLine = new StringBuilder($"{ColumnSyntax(tableColumn.ColumnName)} {GetDataTypeField(tableColumn)}");

            if (tableColumn.DataConstraints.HasFlag(DataConstraint.NotNull))
            {
                tableColumnLine.Append($" {NotNull}");
            }
            if (tableColumn.AutoIncrement)
            {
                tableColumnLine.Append($" {AutoIncrement}");
            }
            if (tableColumn.DataConstraints.HasFlag(DataConstraint.Default))
            {
                tableColumnLine.Append($" {Default} {ValueSyntax(tableColumn.DefaultValue)}");
            }
            return(tableColumnLine.ToString());
        }
Ejemplo n.º 2
0
        public virtual IList <string> GetTableColumnConstraints(DatabaseTableColumn tableColumn)
        {
            IList <string> tableColumnConstraints = new List <string>();

            if (tableColumn.DataConstraints.HasFlag(DataConstraint.PrimaryKey))
            {
                tableColumnConstraints.Add($"{Constraint} {ColumnSyntax($"PK_{TableName}_{tableColumn.ColumnName}")} {PrimaryKey} ({ColumnSyntax(tableColumn.ColumnName)})");
            }
            if (tableColumn.DataConstraints.HasFlag(DataConstraint.ForeignKey))
            {
                tableColumnConstraints.Add($"{Constraint} {ColumnSyntax($"FK_{TableName}_{tableColumn.ColumnName}")} {ForeignKey} ({ColumnSyntax(tableColumn.ColumnName)}) {References} " +
                                           $"{ColumnSyntax(tableColumn.ForeignKeyReference.x)}({ColumnSyntax(tableColumn.ForeignKeyReference.y)}) " +
                                           $"{OnDelete} {GetOnDeleteActionValue(tableColumn.ForeignKeyReference.z)}");
            }
            if (tableColumn.DataConstraints.HasFlag(DataConstraint.Unique))
            {
                tableColumnConstraints.Add($"{Constraint} {ColumnSyntax($"UK_{TableName}_{tableColumn.ColumnName}")} {Unique} ({ColumnSyntax(tableColumn.ColumnName)})");
            }
            if (tableColumn.DataConstraints.HasFlag(DataConstraint.Index))
            {
                tableColumnConstraints.Add($"{Index} {ColumnSyntax($"IX_{TableName}_{tableColumn.ColumnName}")} {NonClustered} ({ColumnSyntax(tableColumn.ColumnName)})");
            }
            return(tableColumnConstraints);
        }
Ejemplo n.º 3
0
        public override string GetDataTypeField(DatabaseTableColumn tableColumn)
        {
            switch (tableColumn.DataType)
            {
            case DataType.Bit:
                return("BIT");

            case DataType.TinyInt:
                return("TINYINT");

            case DataType.Year:
            case DataType.SmallInt:
                return("SMALLINT");

            case DataType.Int:
                return("INT");

            case DataType.BigInt:
                return("BIGINT");

            case DataType.Decimal:
                return(GetDataTypeValues(tableColumn, "DECIMAL"));

            case DataType.Numeric:
                return(GetDataTypeValues(tableColumn, "NUMERIC"));

            case DataType.Float:
                return(GetDataTypeValues(tableColumn, "FLOAT"));

            case DataType.Real:
                return("REAL");

            case DataType.Date:
                return("DATE");

            case DataType.Time:
                return(GetDataTypeValues(tableColumn, "TIME"));

            case DataType.DateTime:
                return("DATETIME2");

            case DataType.TimeStamp:
                return("SMALLDATETIME");

            case DataType.Char:
                return(GetDataTypeValues(tableColumn, "CHAR"));

            case DataType.VarChar:
                return(GetDataTypeValues(tableColumn, "VARCHAR"));

            case DataType.Text:
                return("TEXT");

            case DataType.NChar:
                return(GetDataTypeValues(tableColumn, "NCHAR"));

            case DataType.NVarChar:
                return(GetDataTypeValues(tableColumn, "NVARCHAR"));

            case DataType.NText:
                return("NTEXT");

            case DataType.Binary:
                return(GetDataTypeValues(tableColumn, "BINARY"));

            default:
            case DataType.VarBinary:
                return(GetDataTypeValues(tableColumn, "VARBINARY"));
            }
        }
Ejemplo n.º 4
0
 public CreateTableQuery AddColumn(DatabaseTableColumn tableColumn, params DatabaseTableColumn[] tableColumns)
 {
     DatabaseTableColumns.Add(tableColumn);
     return(AddColumn(tableColumns));
 }
Ejemplo n.º 5
0
 public CreateTableQuery(Query query, DatabaseTableColumn tableColumn, params DatabaseTableColumn[] tableColumns) : this(query, tableColumns)
 {
     DatabaseTableColumns.Insert(0, tableColumn);
 }
Ejemplo n.º 6
0
 public string GetDataTypeValues(DatabaseTableColumn tableColumn, string dataTypeText)
 {
     return(tableColumn.DataTypeValues.Count <= 0 ?
            dataTypeText :
            $"{dataTypeText}({string.Join(", ", tableColumn.DataTypeValues)})");
 }