Skip to content

Commit

Permalink
Support Float and Double properly on all connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Racheli Dambeck committed Sep 21, 2014
1 parent 0c52973 commit 7fd59b5
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 43 deletions.
2 changes: 2 additions & 0 deletions dg.Sql.Connector.MsSql/MsSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ public override string func_SECOND(string Date)
public override string type_NUMERIC { get { return @"NUMERIC"; } }
public override string type_DECIMAL { get { return @"DECIMAL"; } }
public override string type_MONEY { get { return @"MONEY"; } }
public override string type_FLOAT { get { return @"FLOAT(4)"; } }
public override string type_DOUBLE { get { return @"FLOAT(8)"; } }
public override string type_VARCHAR { get { return @"NVARCHAR"; } }
public override string type_CHAR { get { return @"NCHAR"; } }
public override string type_TEXT { get { return @"NTEXT"; } }
Expand Down
2 changes: 2 additions & 0 deletions dg.Sql.Connector.MySql/MySqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ public override string func_UTC_NOW
public override string type_NUMERIC { get { return @"NUMERIC"; } }
public override string type_DECIMAL { get { return @"DECIMAL"; } }
public override string type_MONEY { get { return @"DECIMAL"; } }
public override string type_FLOAT { get { return @"FLOAT"; } }
public override string type_DOUBLE { get { return @"DOUBLE"; } }
public override string type_VARCHAR { get { return @"NATIONAL VARCHAR"; } }
public override string type_CHAR { get { return @"NATIONAL CHAR"; } }
public override string type_TEXT { get { return @"TEXT"; } }
Expand Down
3 changes: 3 additions & 0 deletions dg.Sql.Connector.OleDb/OleDbConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ public override string func_SECOND(string Date)
public override string type_UNSIGNEDBIGINT { get { return @"INT"; } }
public override string type_NUMERIC { get { return @"NUMERIC"; } }
public override string type_DECIMAL { get { return @"DECIMAL"; } }
public override string type_MONEY { get { return @"DECIMAL"; } }
public override string type_FLOAT { get { return @"SINGLE"; } }
public override string type_DOUBLE { get { return @"DOUBLE"; } }
public override string type_VARCHAR { get { return @"VARCHAR"; } }
public override string type_CHAR { get { return @"CHAR"; } }
public override string type_TEXT { get { return @"TEXT"; } }
Expand Down
2 changes: 2 additions & 0 deletions dg.Sql.Connector.PostgreSQL/PostgreSQLConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ public override string func_SECOND(string Date)
public override string type_NUMERIC { get { return @"NUMERIC"; } }
public override string type_DECIMAL { get { return @"DECIMAL"; } }
public override string type_MONEY { get { return @"DECIMAL"; } }
public override string type_FLOAT { get { return @"FLOAT4"; } }
public override string type_DOUBLE { get { return @"FLOAT8"; } }
public override string type_VARCHAR { get { return @"VARCHAR"; } }
public override string type_CHAR { get { return @"CHAR"; } }
public override string type_TEXT { get { return @"TEXT"; } }
Expand Down
78 changes: 41 additions & 37 deletions dg.Sql.SchemaGeneratorAddIn/SchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static void GenerateDalClass(DTE2 application)

bool staticColumns = false;

object[] maxLength;
string singleColumnPrimaryKeyName = null;
string str5 = null;
string str6 = null;
Expand Down Expand Up @@ -359,22 +358,18 @@ public static void GenerateDalClass(DTE2 application)
else if (columnKeywordUpper.Equals("GUID", StringComparison.Ordinal))
{
dalColumn.Type = DalColumnType.TGuid;
}
else if (columnKeywordUpper.Equals("DECIMAL", StringComparison.Ordinal))
{
dalColumn.Type = DalColumnType.TDecimal;
}
else if (columnKeywordUpper.StartsWith("DECIMAL", StringComparison.Ordinal))
}
else if (columnKeywordUpper.Equals("DECIMAL", StringComparison.Ordinal))
{
dalColumn.Type = DalColumnType.TDecimal;
}
else if (columnKeywordUpper.Equals("MONEY", StringComparison.Ordinal))
{
dalColumn.Type = DalColumnType.TMoney;
}
else if (columnKeywordUpper.StartsWith("DECIMAL", StringComparison.Ordinal) |
columnKeywordUpper.StartsWith("MONEY", StringComparison.Ordinal))
{
string str28 = "";
string str29 = "";
int num8 = -1;
int num9 = -1;
int num10 = -1;
num8 = columnKeyword.IndexOf("(");
num9 = columnKeyword.IndexOf(",");
num10 = columnKeyword.IndexOf(")");
if (num8 > -1 & num9 > -1)
string precision = "";
string scale = "";
int leftPartIndex = columnKeyword.IndexOf("(");
Expand All @@ -397,7 +392,14 @@ public static void GenerateDalClass(DTE2 application)
{
dalColumn.Scale = Convert.ToInt32(scale);
}
dalColumn.Type = DalColumnType.TDecimal;
if (columnKeywordUpper.StartsWith("MONEY", StringComparison.Ordinal))
{
dalColumn.Type = DalColumnType.TMoney;
}
else
{
dalColumn.Type = DalColumnType.TDecimal;
}
}
else if (columnKeywordUpper.Equals("DOUBLE", StringComparison.Ordinal))
{
Expand Down Expand Up @@ -732,7 +734,7 @@ public static void GenerateDalClass(DTE2 application)
{
enumTypeName.ActualType = "string";
}
else if (enumTypeName.Type == DalColumnType.TDecimal)
else if (enumTypeName.Type == DalColumnType.TDecimal || enumTypeName.Type == DalColumnType.TMoney)
{
enumTypeName.ActualType = "decimal";
}
Expand Down Expand Up @@ -868,11 +870,15 @@ public static void GenerateDalClass(DTE2 application)
else if (enumTypeName.Type == DalColumnType.TMediumText)
{
stringBuilder.Append(", DataType.MediumText");
}
else if (enumTypeName.Type == DalColumnType.TFixedString)
{
stringBuilder.Append(", DataType.Char");
}
}
else if (enumTypeName.Type == DalColumnType.TFixedString)
{
stringBuilder.Append(", DataType.Char");
}
else if (enumTypeName.Type == DalColumnType.TMoney)
{
stringBuilder.Append(", DataType.Money");
}
else if (enumTypeName.Type == DalColumnType.TGeometry)
{
stringBuilder.Append(", DataType.Geometry");
Expand Down Expand Up @@ -1024,15 +1030,13 @@ public static void GenerateDalClass(DTE2 application)
{
enumTypeName.ActualType += "?";
}
maxLength = new object[] { "\r\n", enumTypeName.MaxLength, enumTypeName.Precision, enumTypeName.Scale, null, null, null, null };
object[] objArray = maxLength;
objArray[4] = (enumTypeName.AutoIncrement ? "true" : "false");
object[] objArray1 = maxLength;
objArray1[5] = (enumTypeName.IsPrimaryKey ? "true" : "false");
object[] objArray2 = maxLength;
objArray2[6] = (enumTypeName.IsNullable ? "true" : "false");
maxLength[7] = enumTypeName.DefaultValue;
stringBuilder.AppendFormat(", {1}, {2}, {3}, {4}, {5}, {6}, {7});{0}", maxLength);

object[] dataTypeFormatArgs = new object[] { "\r\n", enumTypeName.MaxLength, enumTypeName.Precision, enumTypeName.Scale, null, null, null, null };
dataTypeFormatArgs[4] = (enumTypeName.AutoIncrement ? "true" : "false");
dataTypeFormatArgs[5] = (enumTypeName.IsPrimaryKey ? "true" : "false");
dataTypeFormatArgs[6] = (enumTypeName.IsNullable ? "true" : "false");
dataTypeFormatArgs[7] = enumTypeName.DefaultValue;
stringBuilder.AppendFormat(", {1}, {2}, {3}, {4}, {5}, {6}, {7});{0}", dataTypeFormatArgs);
if (string.IsNullOrEmpty(actualType))
{
continue;
Expand Down Expand Up @@ -1064,7 +1068,7 @@ public static void GenerateDalClass(DTE2 application)
stringBuilder.AppendFormat("{0}", "\r\n");
foreach (DalIndex dalIndex2 in dalIndices)
{
maxLength = new object[4];
object[] maxLength = new object[4];
object[] objArray3 = maxLength;
objArray3[0] = (dalIndex2.IndexName == null ? "null" : ("\"" + dalIndex2.IndexName + "\""));
maxLength[1] = dalIndex2.ClusterMode.ToString();
Expand Down Expand Up @@ -1208,7 +1212,7 @@ public static void GenerateDalClass(DTE2 application)
{
defaultValue = "string.Empty";
}
else if (dalColumn3.Type == DalColumnType.TDecimal)
else if (dalColumn3.Type == DalColumnType.TDecimal || dalColumn3.Type == DalColumnType.TMoney)
{
defaultValue = "0m";
}
Expand Down Expand Up @@ -1252,7 +1256,7 @@ public static void GenerateDalClass(DTE2 application)
{
continue;
}
maxLength = new object[] { "\r\n", dalColumn4.ActualType, dalColumn4.Name, null };
object[] maxLength = new object[] { "\r\n", dalColumn4.ActualType, dalColumn4.Name, null };
object[] objArray4 = maxLength;
objArray4[3] = (dalColumn4.Virtual ? "virtual " : "");
stringBuilder.AppendFormat("public {3}{1} {2}{0}{{{0}get{{return _{2};}}{0}set{{_{2}=value;}}{0}}}{0}", maxLength);
Expand Down Expand Up @@ -1352,7 +1356,7 @@ public static void GenerateDalClass(DTE2 application)
{
str32 = "Convert.ToUInt64({0})";
}
else if (dalColumn6.Type == DalColumnType.TDecimal)
else if (dalColumn6.Type == DalColumnType.TDecimal || dalColumn6.Type == DalColumnType.TMoney)
{
str32 = "Convert.ToDecimal({0})";
}
Expand Down Expand Up @@ -1549,7 +1553,7 @@ public static void GenerateDalClass(DTE2 application)
fromDb = (!column.ActualType.EndsWith("?") ? "IsNull({0}) ? {1} : Convert.ToUInt64({0})" : string.Format("IsNull({{0}}) ? ({0}){{1}} : Convert.ToUInt64({{0}})", column.ActualType));
}
}
else if (column.Type == DalColumnType.TDecimal)
else if (column.Type == DalColumnType.TDecimal || column.Type == DalColumnType.TMoney)
{
if (!column.IsNullable)
{
Expand Down
1 change: 1 addition & 0 deletions dg.Sql.SchemaGeneratorAddIn/Types/DalColumnType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum DalColumnType
TGuid,
TDateTime,
TDecimal,
TMoney,
TDouble,
TFloat,
TGeometry,
Expand Down
2 changes: 2 additions & 0 deletions dg.Sql/Connector/ConnectorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public virtual string func_SECOND(string Date)
public virtual string type_NUMERIC { get { return @"NUMERIC"; } }
public virtual string type_DECIMAL { get { return @"DECIMAL"; } }
public virtual string type_MONEY { get { return @"DECIMAL"; } }
public virtual string type_FLOAT { get { return @"FLOAT"; } }
public virtual string type_DOUBLE { get { return @"DOUBLE"; } }
public virtual string type_VARCHAR { get { return @"NVARCHAR"; } }
public virtual string type_CHAR { get { return @"NCHAR"; } }
public virtual string type_TEXT { get { return @"NTEXT"; } }
Expand Down
14 changes: 11 additions & 3 deletions dg.Sql/Sql/Enumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,26 @@ public enum DataType
/// </summary>
Blob,
/// <summary>
/// Float, Double
/// Float
/// </summary>
Numeric,
Float,
/// <summary>
/// Double
/// </summary>
Double,
/// <summary>
/// Decimal
/// </summary>
Decimal,
/// <summary>
/// Decimal
/// Money
/// </summary>
Money,
/// <summary>
/// Numeric
/// </summary>
Numeric,
/// <summary>
/// SByte
/// </summary>
TinyInt,
Expand Down
25 changes: 24 additions & 1 deletion dg.Sql/Sql/Query/Builders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ public void BuildColumnPropertiesDataType(StringBuilder sb, ConnectorBase connec
{
sb.Append(connection.type_DATETIME);
}

else if (dataType == DataType.Numeric)
{
if (column.NumberPrecision > 0)
Expand All @@ -585,6 +584,30 @@ public void BuildColumnPropertiesDataType(StringBuilder sb, ConnectorBase connec
sb.Append(connection.type_NUMERIC);
}
}
else if (dataType == DataType.Float)
{
if (column.NumberPrecision > 0 && connection.TYPE == ConnectorBase.SqlServiceType.MYSQL)
{
sb.Append(connection.type_FLOAT);
sb.AppendFormat(@"({0}, {1})", column.NumberPrecision, column.NumberScale);
}
else
{
sb.Append(connection.type_FLOAT);
}
}
else if (dataType == DataType.Double)
{
if (column.NumberPrecision > 0 && connection.TYPE == ConnectorBase.SqlServiceType.MYSQL)
{
sb.Append(connection.type_DOUBLE);
sb.AppendFormat(@"({0}, {1})", column.NumberPrecision, column.NumberScale);
}
else
{
sb.Append(connection.type_DOUBLE);
}
}
else if (dataType == DataType.Decimal)
{
if (column.NumberPrecision > 0)
Expand Down
8 changes: 6 additions & 2 deletions dg.Sql/Sql/Schema/TableSchema.Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ private DataType GetDataType()
if (this.MaxLength > 0) return DataType.VarChar;
return DataType.Text;
}
else if (this.Type.Equals(typeof(double)) || this.Type.Equals(typeof(float)))
else if (this.Type.Equals(typeof(float)))
{
return DataType.Numeric;
return DataType.Float;
}
else if (this.Type.Equals(typeof(double)))
{
return DataType.Double;
}
else if (this.Type.Equals(typeof(decimal)))
{
Expand Down

0 comments on commit 7fd59b5

Please sign in to comment.