Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSqlite: InvalidCastException if the first value in a column is NULL followed by any other value #642
Comments
|
This sounds horribly familiar, and iirc when I got to the bottom of it last On 17 Nov 2016 4:20 pm, "CheeseSucker" notifications@github.com wrote:
|
|
#329 looks a bit similar. Could these problems be related? |
|
Actually the one I was thinking of is #552, but that is mysql; if this is sqlite, I need to investigate from scratch. It could be similar, it could be unrelated. For the record, dapper doesn't do anything with the first row; instead, it asks the reader what the column types are. If the reader (provider-specific) does something stupid, that's when we get trouble. |
|
I think it is indeed the same issue. Just like in the MySQL issue, SQlite will return a different value for GetFieldType() while iterating a result set: Unfortunately, this is by design and so is unlikely to change. |
|
Dammit. That's extremely vexing. I need to think on this. There is no On 21 Nov 2016 4:44 pm, "Håkon Trandal" notifications@github.com wrote:
|
|
The best I can figure off the top of my head is a global
Thoughts? On 21 Nov 2016 6:10 pm, "Marc Gravell" marc.gravell@gmail.com wrote:
|
|
That sounds fine to me. The setting should probably be tied to a DbConnection in case more than one database is used. What are the drawbacks to doing this? |
|
The drawback is that it will be slightly slower. I'm loathe to try to tie Marc On 23 November 2016 at 08:52, CheeseSucker notifications@github.com wrote:
Regards, Marc |
|
Sounds good! |
|
Is there any progress on this? As far as I can make out, this is stopping me from using Dapper in a netcore app. |
|
I also am experiencing this problem with the Microsoft.Data.Sqlite library and Dapper. I switched to Microsoft.Data.Sqlite because the System.Data.Sqlite library doesn't work with linux without recompiling the Interop.Sqlite dll which is quite troublesome. I fix for this would be awesome. My datasets are not very large so a slight performance hit is not so huge a deal for me. |
|
Well, it seems I have the same issue. |
|
This question on SO seems to be a result of this issue: https://stackoverflow.com/questions/39980840/sqlite-using-dapper-error-parsing-column-unable-to-cast-object-of-type-system |
|
Little example of why this is a problem in my case. In one sqlite table, a column has values like this:
Since sqlite will only treat the value "70" as a integer, never a floating point (even if I inserted the value "70.0") this exposes this Dapper casting problem. There does not appear to be any workaround in the DB. |
|
If you use a SQL CAST() on the column having the problem, you can work around this issue. This has been mentioned elsewhere but not yet in this issue, FYI for future readers. |
|
I am having this issue and casting did not help. With my current data I can sort so I don't get nulls in the first row... but it is a shaky solution! |
|
I think it would be better to state on the website that Dapper DOES NOT support SQLite so people will not invest time and money into a non-working package. |
|
Sorry @mgravell but this issue is still there. Does this comment here in Microsoft.Data.Sqlite help any further? Otherwise the suggestion from @kardkovacsi and @hsorbo seems to be fair, as I'm hit with this issue while developing a quick and simple Web API using SQLite and Dapper. |
|
I created a type handler for double? , it seems to work. Assumption here is that if user has specified type as double, it should attempt to convert it to double. As a user I should not be type a memo field as double of course. Is this an acceptable workaround? `
|
|
The error still exists and seems never to be fixed. Thanks @ravimpatel for a good solution. |
Except dapper is fucked because fuckhttps://github.com/StackExchange/Dapper/issues/642
It seems like Dapper uses the first value in a column to decide what type the rest of the values will have.
If the first value is NULL, this fails spectacularly.
I have set up a repository demonstrating this bug:
https://github.com/CheeseSucker/DapperSqliteBug
Tested dapper versions: 1.50.0, 1.50.2, 1.50.3-beta1
Relevant code: