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 throws System.FormatException: 'Input string was not in a correct format' when decimal numbers stored in exponential format #6205

Closed
ghost opened this issue Jul 29, 2016 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ghost
Copy link

ghost commented Jul 29, 2016

Steps to reproduce

Build a Sqlite DB with a table with a field with decimal(16,8).
Update the field with the value 0.0001 and try to make a linq select wit .ToList();

The issue

I have a code similar to this:

IQueryable<Instrument> query = context.Instruments
                .Include(x => x.Tags)
                .Include(x => x.Exchange)
                .Include(x => x.PrimaryExchange)
                .Include(x => x.Datasource)
                .Include(x => x.Sessions)
                .Include(x => x.ContinuousFuture)
                .Include(x => x.ContinuousFuture.UnderlyingSymbol)
                .AsQueryable();
IQueryable<Instrument> query;
var allInstruments = query.ToList();

At the last line, i face an exception.

This issue seems to be similar with #1057.

Exception message: "Input string was not in a correct format." (System.FormatException)
Stack trace:
   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 Microsoft.Data.Sqlite.SqliteDataReader.GetDecimal(Int32 ordinal)
   at lambda_method(Closure , DbDataReader )
   at Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()\
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
[...]

The database table had a content like this:

sqlite> select ID, Symbol, Name, Strike, MinTick FROM instruments;
4|EUR/USD|EUR/USD price||1.0e-05
5|SPY|SPDR S&P 500 ETF Trust||0.01
6|GBP/USD|GBP/USD||
7|USD/JPY|USD/JPY||
8|AUD/USD|AUD/USD||
sqlite> 

After i deleted all decimal values with sqlite> UPDATE instruments SET MinTick = NULL;

sqlite> select ID, Symbol, Name, Strike, MinTick FROM instruments;
4|EUR/USD|EUR/USD price||
5|SPY|SPDR S&P 500 ETF Trust||
6|GBP/USD|GBP/USD||
7|USD/JPY|USD/JPY||
8|AUD/USD|AUD/USD||
sqlite> 

The exception was gone.
So i strongly belief it has to do with the academic number style that sqlite produces and send to the EF Library...

Further technical details

EF Core version: 1.0.0
Operating system: ubuntu 14.04 LTS - linux
Visual Studio version: n/a

@natemcmaster
Copy link
Contributor

The issue is actually in Microsoft.Data.Sqlite.

https://github.com/aspnet/Microsoft.Data.Sqlite/blob/dev/src/Microsoft.Data.Sqlite/SqliteDataReader.cs#L420-L421

In order to parse exponential form, we need to use the NumberStyles option when calling decimal.Parse. e.g. decimal.Parse("1.0e-05", System.Globalization.NumberStyles.Float)

@natemcmaster natemcmaster changed the title sqlite, decimal and academic number - System.FormatException: Input string was not in a correct format #1057 SQLite throws System.FormatException: 'Input string was not in a correct format' when decimal numbers stored in exponential format Aug 1, 2016
@natemcmaster natemcmaster self-assigned this Aug 1, 2016
@natemcmaster natemcmaster added this to the 1.1.0 milestone Aug 1, 2016
@natemcmaster natemcmaster added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 12, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.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. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants