internal static ColumnInfo FromSqlSchemaRow(DataRow row) { ColumnInfo ci = new ColumnInfo(); ci.columnName = (string)row["column_name"]; object o = row["ordinal_position"]; if (o is short) { ci.ordinalPosition = (short)o; } else { ci.ordinalPosition = (int)o; } ci.dataType = DbTypeUtility.GetDbTypeFromSqlTypeName((string)row["data_type"]); string[] type = ((string)row["data_type"]).Split(' '); if (type.Length > 1 && type[1].ToLower() == "identity") { ci.isIdentity = true; } ci.nullable = ((string)row["is_nullable"] == "YES"); //Length o = row["character_maximum_length"]; if (o is DBNull) { ci.length = 0; } else if (o is short) { ci.length = (short)o; } else if (o is int) { ci.length = (int)o; } o = row["numeric_precision"]; if (o is DBNull) { ci.precition = 0; } else { ci.precition = (byte)o; } o = row["numeric_scale"]; if (o is DBNull) { ci.scale = 0; } else { ci.scale = (int)o; } return(ci); }
public static ColumnInfo FromSqlSpColumnsRow(DataRow row) { ColumnInfo ci = new ColumnInfo(); ci.columnName = (string)row["COLUMN_NAME"]; object o = row["ORDINAL_POSITION"]; if (o is short) { ci.ordinalPosition = (short)o; } else { ci.ordinalPosition = (int)o; } ci.dataType = DbTypeUtility.GetDbTypeFromSqlTypeName((string)row["TYPE_NAME"]); string[] type = ((string)row["TYPE_NAME"]).Split(' '); if (type.Length > 1 && type[1].ToLower() == "identity") { ci.isIdentity = true; } ci.nullable = ((short)row["NULLABLE"] == 1); //Length o = row["CHAR_OCTET_LENGTH"]; if (o is DBNull) { ci.length = 0; } else if (o is short) { ci.length = (short)o; } else if (o is int) { ci.length = (int)o; } if (ci.dataType == DbType.String || ci.dataType == DbType.StringFixedLength) { ci.length /= 2; } if (ci.dataType == DbType.Decimal || ci.dataType == DbType.Currency) { o = row["PRECISION"]; if (o is DBNull) { ci.precition = 0; } else { ci.precition = (byte)(int)o; } o = row["SCALE"]; if (o is DBNull) { ci.scale = 0; } else { ci.scale = (short)o; } } return(ci); }