public ColumnWriterTests() { _sb = new StringBuilder(); _col = new ColumnDefinition(); _col.Name = "User Id"; _col.Type=DbType.Boolean; _cw = new SqlServerColumnWriter(_sb); }
public override void Write(ColumnDefinition col) { if (col.IsIdentity) { Builder.AppendFormat("{0} serial not null", EscapeName(col.Name)); } else base.Write(col); }
public ISupportSpecificColumnsOptions this[string name] { get { var col = _table.Columns[name]; if (col != null) { _currentColumn = col; return this; } throw new KeyNotFoundException(string.Format("No column with the name '{0}' was defined in the builder",name)); } }
public virtual void Write(ColumnDefinition col) { if (RedefineHandled(col)) { return; } _definition = col; col.Options.Use(Engine); WriteNameAndType(col); WriteNullable(col.IsNullable); if (!col.IsIdentity) WriteDefault(col.DefaultValue); else WriteIdentity(col); }
public IConfigureColumns Add(string name, DbType type, string size = "", bool isNullable = true, string defaultValue = "", string collation = "", bool autoIncrement = false) { var col = new ColumnDefinition { Name = name, Type = type, Size = size, DefaultValue = defaultValue, IsNullable = isNullable, IsIdentity = autoIncrement, Collate = collation }; _currentColumn = col; _table.Columns.AddColumn(col); return this; }
private ColumnDefinition AddColumn(PropertyInfo pi, ColumnOptionsAttribute attr) { DbType type; var tp = pi.PropertyType; var asString = pi.GetModelAttributes<InsertAsStringAttribute>().FirstOrDefault(); if (asString != null) { type = DbType.String; } else { if (tp.IsEnum) { tp = Enum.GetUnderlyingType(tp); } type = FromType(tp); } var col = new ColumnDefinition(); col.Name = pi.Name; col.DefaultValue = attr.DefaultValue; col.IsIdentity = (_ti.PrimaryKey == col.Name && _ti.AutoGenerated); col.Size = attr.Size; col.Type = type; if (pi.PropertyType.IsNullable()) { col.IsNullable = true; } else { col.IsNullable = attr.IsNullable; } _schema.Columns.AddColumn(col); return col; }
protected override void WriteIdentity(ColumnDefinition col) { Builder.Append(" auto_increment"); }
protected override void WriteIdentity(ColumnDefinition col) { Builder.Append(" IDENTITY(1,1)"); }
protected virtual void WriteNameAndType(ColumnDefinition col) { Builder.AppendFormat("{0} {1}", EscapeName(col.Name), GetType(col.Type, col.Size)); WriteCollation(col.Collate); }
protected bool RedefineHandled(ColumnDefinition col) { if (col.IsRedefined(Engine)) { Builder.Append(EscapeName(col.Name) + " " + col.GetDefinition(Engine)); return true; } return false; }
protected abstract void WriteIdentity(ColumnDefinition col);
protected override void WriteIdentity(ColumnDefinition col) { }
public MySqlColumnWriterTests() { _sb = new StringBuilder(); _writer = new MySqlColumnWriter(_sb); _col = new ColumnDefinition(); }