mattwar / iqtoolkit

A Toolkit for building LINQ IQueryable providers. This is the official move of my IQToolkit project from CodePlex.
Other
237 stars 77 forks source link

Error with real number when generating Sql #17

Closed IfZen closed 4 years ago

IfZen commented 6 years ago

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;
                }
mattwar commented 4 years ago

Fixed by techseat's PR.