Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite, decimal and non-US locale - System.FormatException: Input string was not in a correct format #1057

Closed
avestnik opened this issue Nov 13, 2014 · 9 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@avestnik
Copy link

when I query decimal non-0 value from sqlite under non-US (Cyrillic to be specific, with comma as decimal separator) I get an exception: System.FormatException: Input string was not in a correct format. looks like there is a disagreement somewhere inside EF about what format to use during query and parsing

SELECT "q"."SalesWeight" FROM "Questions" AS "q" [I got it from ILogger]

An exception occurred in the data store while iterating the results of a query.
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Decimal.Parse(String s)
at Microsoft.Data.SQLite.Utilities.SQLiteTypeMap.<>c__DisplayClass252.<Add>b__27(Object o) at Microsoft.Data.SQLite.Utilities.SQLiteTypeMap.FromInterop(Object value) at Microsoft.Data.SQLite.SQLiteDataReader.GetValue(Int32 ordinal) at Microsoft.Data.SQLite.SQLiteDataReader.GetValues(Object[] values) at Microsoft.Data.Entity.Relational.RelationalObjectArrayValueReader.CreateBuffer(DbDataReader dataReader) at Microsoft.Data.Entity.Relational.RelationalObjectArrayValueReader..ctor(DbDataReader dataReader) at Microsoft.Data.Entity.Relational.RelationalObjectArrayValueReaderFactory.Create(DbDataReader dataReader) at Microsoft.Data.Entity.Relational.Query.RelationalQueryModelVisitor.CreateEntity[TEntity](IQuerySource querySource, QueryContext queryContext, QuerySourceScope parentQuerySourceScope, DbDataReader dataReader, Int32 readerOffset, IEntityType entityType) at lambda_method(Closure , DbDataReader ) at Microsoft.Data.Entity.Relational.Query.AsyncQueryingEnumerable1.AsyncEnumerator.d__1.MoveNext()

@ErikEJ
Copy link
Contributor

ErikEJ commented Nov 13, 2014

Could you share your model and context code?

@avestnik
Copy link
Author

it is a part of a quite big project. I will prepare repro over couple of days

@avestnik
Copy link
Author

using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Metadata;
using System.Linq;

namespace Console
{
    public class LocalContext : DbContext
    {
        public LocalContext(DbContextOptions options)
            : base(options)
        {
        }

        public DbSet<Question> Questions { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Question>().Key(q => q.QuestionId);
        }
    }
    public class Question
    {
        public int QuestionId { get; set; }
        public string Name { get; set; }
        public decimal SalesWeight { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            DbContextOptions options = new DbContextOptions();
            options.UseSQLite("Filename=c:\\temp\\Questions.db");

            LocalContext context = new LocalContext(options);
       //     context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var id = context.Questions.Max(q1 => q1.QuestionId) + 1;

            var q = new Question { QuestionId = id, Name = "Name", SalesWeight = 1.5m };
            context.Add(q);
            context.SaveChanges();

            var qs = context.Questions.ToList();
        }
    }
}

@ErikEJ
Copy link
Contributor

ErikEJ commented Nov 13, 2014

That was quick, the good news are that test in DataCommon.SQLite fails with a similar error

@ErikEJ
Copy link
Contributor

ErikEJ commented Nov 13, 2014

@dbis01 Pull request submitted aspnet/Microsoft.Data.Sqlite#59

@bricelam
Copy link
Contributor

@dbis01 Is this fixed in the latest bits?

@avestnik
Copy link
Author

Yes! Thanks a lot

@bricelam bricelam self-assigned this Nov 17, 2014
@bricelam bricelam added this to the 1.0.0-beta2 milestone Nov 17, 2014
@bricelam
Copy link
Contributor

Thank you, @ErikEJ. I just typed git push 😉

@ErikEJ
Copy link
Contributor

ErikEJ commented Nov 17, 2014

@bricelam Easy for you!

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.0.0-beta2, 1.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

No branches or pull requests

5 participants