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]Error parsing column 8 (X=0 - Int64) #1285

Closed
rustbomber opened this issue Jun 20, 2019 · 4 comments
Closed

[sqlite]Error parsing column 8 (X=0 - Int64) #1285

rustbomber opened this issue Jun 20, 2019 · 4 comments

Comments

@rustbomber
Copy link

rustbomber commented Jun 20, 2019

I have query,the result is :
image

use dapper 1.60.1 and microsoft.data.sqlite.core 2.2.3, my application report :

---- System.Data.DataException : Error parsing column 8 (IS_SEARCH=0 - Int64)
-------- System.InvalidCastException : Unable to cast object of type 'System.Int64' to type 'System.Int32'.

these filed is interger in sqlite, my class like this:

public class T
{

        public int IsList { get; set; }
        public int IsAdd { get; set; }
        public int IsEdit { get; set; }
        public int IsSearch { get; set; }
        public int IsMany { get; set; }
}

when change int to int? or int to long? still not working 。

If change the provider to System.Data.SQLite.Core is working fine.

@kelvindules
Copy link

kelvindules commented Jun 20, 2019

Unable to cast object of type 'System.Int64' to type 'System.Int32'

Sqlite is weird with INTEGER.
From what I can see, when your column value is null, Sqlite returns it as a long/Int64 (8 bytes) so you should have a long property to map to, not an int/Int32 (4 bytes).

public long IsSearch { get; set; }

Theres is no need to make it nullable unless you need nulls.
When querying a null column value to a non-nullable type, you'll get it's default, in this case 0.

You may also try using ifnull to see if it casts to Int32 properly.

select ifnull(Is_Search, 0) from table

@rustbomber
Copy link
Author

rustbomber commented Jun 20, 2019

@kelvindules long property also test, but still not working, exception info:

---- System.Data.DataException : Error parsing column 8 (IS_SEARCH=0 - Int64)
-------- System.InvalidCastException : Unable to cast object of type 'System.Int64' to type 'System.Int32'.

from the message ,long property still present as 'System.Int32'.

@kelvindules
Copy link

@akaylh This looks like #524 . Try casting it as bigint

select cast(Is_Search as bigint) from table

Not sure if that is already addressed.

@rustbomber
Copy link
Author

@kelvindules thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants