public void TestBinary()
        {
            //arrange
            _column.DbDataType = "BINARY";
            _column.Length = 400;
            //specify that we are coming from SqlServer, so keep Binary format
            var typeWriter = new DataTypeWriter(SqlType.SqlServer);

            //act
            var result = typeWriter.WriteDataType(_column);

            //assert
            Assert.AreEqual("BINARY (400)", result);
        }
示例#2
0
        protected override string WriteDataType(DatabaseColumn column)
        {
            if (HandleComputed(column))
            {
                return("AS " + column.ComputedDefinition);
            }

            var sql = DataTypeWriter.WriteDataType(column);

            if (sql == "BIT")
            {
                _hasBit = true;
            }

            var defaultValue = string.Empty;

            if (!string.IsNullOrEmpty(column.DefaultValue) && IncludeDefaultValues)
            {
                var value = FixDefaultValue(column.DefaultValue);
                if (_hasBit)
                {
                    //Access Yes/No boolean
                    if (value.Equals("No", StringComparison.OrdinalIgnoreCase))
                    {
                        value = "0";
                    }
                    if (value.Equals("Yes", StringComparison.OrdinalIgnoreCase))
                    {
                        value = "1";
                    }
                }
                if (value.StartsWith("(NEXT VALUE FOR ", StringComparison.OrdinalIgnoreCase) && !SupportsNextValueForSequence)
                {
                    //SQLServer 2012 "NEXT VALUE FOR [Sequence]". Allow it to be turned back to identity.
                    column.IsAutoNumber       = true;
                    column.IdentityDefinition = new DatabaseColumnIdentity();
                    value = null;
                }
                //strings should already have the single quotes in place
                if (!string.IsNullOrEmpty(value))
                {
                    defaultValue = "DEFAULT " + value;
                }
            }

            if (DataTypeWriter.LooksLikeOracleIdentityColumn(Table, column))
            {
                column.IsAutoNumber       = true;
                column.IdentityDefinition = new DatabaseColumnIdentity();
            }
            if (column.IdentityDefinition != null)
            {
                var id = column.IdentityDefinition;
                sql += " IDENTITY(" + id.IdentitySeed + "," + id.IdentityIncrement + ")";
            }
            if (column.IsPrimaryKey)
            {
                sql += " NOT NULL";
                if (!string.IsNullOrEmpty(defaultValue))
                {
                    sql += " " + defaultValue;
                }
            }
            else
            {
                sql += " " + (!column.Nullable ? " NOT NULL" : string.Empty) + " " + defaultValue;
            }
            return(sql);
        }
示例#3
0
 protected override string ColumnDataType(string dataType)
 {
     return(DataTypeWriter.WriteDataType(dataType));
 }
示例#4
0
 protected override string ColumnDataType(DatabaseColumn column)
 {
     return(_dataTypeWriter.WriteDataType(column));
 }