mattwar/iqtoolkit

Error with real number when generating Sql

Closed this issue · 1 comments

IfZen commented

First thank for taking time to write this big and very interesting project. this is a "always-want-to-do-it-but-don't-have-a-clue-where-to-start-and-i-am-too-lazy-anyway" kind of project.
When reading and testing your code, I noticed some test did not pass because my thread has a french culture
The error is simple, so is the fix, we just need to replace the following code
(in file SqlFormatter.cs , in namespace IQToolkit.Data.Common)

switch (Type.GetTypeCode(value.GetType()))
                {
                    case TypeCode.Boolean:
                        this.Write(((bool)value) ? 1 : 0);
                        break;
                    case TypeCode.String:
                        this.Write("'");
                        this.Write(value);
                        this.Write("'");
                        break;
                    case TypeCode.Object:
                        throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", value));
                    case TypeCode.Single:
                    case TypeCode.Double:
                        string str = value.ToString();
                        if (!str.Contains('.'))
                        {
                            str += ".0";
                        }
                        this.Write(str);
                        break;
                    default:
                        this.Write(value);
                        break;
                }

by this

                switch (Type.GetTypeCode(value.GetType()))
                {
                    case TypeCode.Boolean:
                        this.Write(((bool)value) ? 1 : 0);
                        break;
                    case TypeCode.String:
                        this.Write("'");
                        this.Write(value);
                        this.Write("'");
                        break;
                    case TypeCode.Object:
                        throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", value));
                    case TypeCode.Single:
                    case TypeCode.Double:
                        string str = ((IConvertible)value).ToString(CultureInfo.InvariantCulture);
                        if (!str.Contains('.'))
                        {
                            str += ".0";
                        }
                        this.Write(str);
                        break;
                    default:
                        var convertible = value as IConvertible;
                        if (convertible != null)
                            this.Write(convertible.ToString(CultureInfo.InvariantCulture));
                        else
                            this.Write(value);
                        break;
                }

Fixed by techseat's PR.