private void Run(StringBuilder builder, CreateColumnCommand command) { // name builder.Append(_dialect.QuoteForColumnName(command.ColumnName)).Append(Space); if (!command.IsIdentity || _dialect.HasDataTypeInIdentityColumn) { builder.Append(_dialect.GetTypeName(command.DbType, command.Length, command.Precision, command.Scale)); } // append identity if handled if (command.IsIdentity && _dialect.SupportsIdentityColumns) { builder.Append(Space).Append(_dialect.IdentityColumnString); } // [default value] if (command.Default != null) { builder.Append(" default ").Append(_dialect.GetSqlValue(command.Default)).Append(Space); } // nullable builder.Append(command.IsNotNull ? " not null" : !command.IsPrimaryKey && !command.IsUnique ? _dialect.NullColumnString : string.Empty); // append unique if handled, otherwise at the end of the satement if (command.IsUnique && _dialect.SupportsUnique) { builder.Append(" unique"); } }
public void FieldColumn(string fieldName, string fieldTypeName, Action <CreateColumnCommand> column = null) { var type = _dynamicAssemblyBuilder.GetFieldType(fieldTypeName); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { type = Nullable.GetUnderlyingType(type); } var dbType = SchemaUtils.ToDbType(type); var command = new CreateColumnCommand(_tableCommand.Name, fieldName); command.WithType(dbType); if (column != null) { column(command); } _tableCommand.TableCommands.Add(command); }
public virtual void VisitCreateColumn(CreateColumnCommand cmd) { this.AppendFormat("ALTER TABLE {0} ", cmd.TableName); this.AppendNewLine(); this.Append("ADD "); this.VisitTableColumn(cmd); this.ExecuteCommandText(cmd.ConnectionString, builder.ToString()); }