Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Contrib][T4][SQL Server] Fix retrive column size and precision

  • Loading branch information...
commit 9d836bc1a279e2d28a29220c4797d602f86dbdf3 1 parent ed40874
@spaccabit authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/FluentMigrator.T4/SchemaReaders/SqlServerSchemaReader.cs
View
10 src/FluentMigrator.T4/SchemaReaders/SqlServerSchemaReader.cs
@@ -83,7 +83,7 @@ List<Column> LoadColumns(Table tbl)
{
while (rdr.Read())
{
- var type = GetPropertyType(rdr["DataType"].ToString());
+ var type = GetPropertyType(rdr["DataType"].ToString());
Column col = new Column();
col.Name = rdr["ColumnName"].ToString();
col.PropertyName = CleanUp(col.Name);
@@ -91,8 +91,8 @@ List<Column> LoadColumns(Table tbl)
col.CustomType = type == null
? rdr["DataType"].ToString().ToLowerInvariant()
: null;
- col.Size = GetDatatypeSize(rdr["DataType"].ToString());
- col.Precision = GetDatatypePrecision(rdr["DataType"].ToString());
+ col.Size = rdr.Get("MaxLength", -1);
+ col.Precision = rdr.Get("Precision", -1);
col.IsNullable = rdr["IsNullable"].ToString() == "YES";
col.IsAutoIncrement = ((int)rdr["IsIdentity"]) == 1;
col.DefaultValue = rdr.IsDBNull(5) ? null : rdr["DefaultSetting"].ToString();
@@ -294,8 +294,8 @@ FROM INFORMATION_SCHEMA.TABLES
ORDINAL_POSITION AS OrdinalPosition,
COLUMN_DEFAULT AS DefaultSetting,
IS_NULLABLE AS IsNullable, DATA_TYPE AS DataType,
- CHARACTER_MAXIMUM_LENGTH AS MaxLength,
- DATETIME_PRECISION AS DatePrecision,
+ ISNULL(CHARACTER_MAXIMUM_LENGTH,CAST(NUMERIC_PRECISION as Int)) AS MaxLength,
+ NUMERIC_SCALE AS Precision,
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsIdentity') AS IsIdentity,
COLUMNPROPERTY(object_id('[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']'), COLUMN_NAME, 'IsComputed') as IsComputed
FROM INFORMATION_SCHEMA.COLUMNS
Please sign in to comment.
Something went wrong with that request. Please try again.