Пример #1
0
 public ColumnWriterTests()
 {
     _sb = new StringBuilder();
     _col = new ColumnDefinition();
     _col.Name = "User Id";
     _col.Type=DbType.Boolean;
     _cw = new SqlServerColumnWriter(_sb);
 }
Пример #2
0
 public override void Write(ColumnDefinition col)
 {
     if (col.IsIdentity)
     {
         Builder.AppendFormat("{0} serial not null", EscapeName(col.Name));
     }
     else base.Write(col);
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
 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;
 }
Пример #6
0
        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;
        }
Пример #7
0
 protected override void WriteIdentity(ColumnDefinition col)
 {
     Builder.Append(" auto_increment");
 }
Пример #8
0
 protected override void WriteIdentity(ColumnDefinition col)
 {
     Builder.Append(" IDENTITY(1,1)");
 }
Пример #9
0
 protected virtual void WriteNameAndType(ColumnDefinition col)
 {
     Builder.AppendFormat("{0} {1}", EscapeName(col.Name), GetType(col.Type, col.Size));
     WriteCollation(col.Collate);
 }
Пример #10
0
 protected bool RedefineHandled(ColumnDefinition col)
 {
     if (col.IsRedefined(Engine))
     {
         Builder.Append(EscapeName(col.Name) + " " + col.GetDefinition(Engine));
         return true;
     }
     return false;
 }
Пример #11
0
 protected abstract void WriteIdentity(ColumnDefinition col);
Пример #12
0
 protected override void WriteIdentity(ColumnDefinition col)
 {
 }
Пример #13
0
 public MySqlColumnWriterTests()
 {
     _sb = new StringBuilder();
     _writer = new MySqlColumnWriter(_sb);
     _col = new ColumnDefinition();
 }