How does Linqpad know what type a column in Sqlite is ?

I have a c# script which no longer compiles in the beta as it thinks it is a column is a string and I was expecting it to be numeric.

I am currently using LinqPad 9.10.8 which thinks it is a string but is reported as a double? with 9.9.10 and 8.10.4 versions of LinqPad.

The sql pragma_table_info command shows the same results for all three LP versions which is

type decimal(3,2)
notnull 0

I know sqlite doesn't really enforce type checking, but that should not be the case here and to check I ran a SELECT distinct TYPEOF(columnName) from tableName statement which showed just

null
real
integer

EF version was the same with the two LP 9 versions, so I think this is a change of behaviour with the beta.

Best Answer

  • JoeAlbahari
    Answer ✓

    That explains it. There are two factors at work:

    1. A regression related to a recent fix to avoid timeouts on large tables (which has now been fixed in 9.10.9)
    2. A long-standing feature - arguably a bug - whereby columns declared as NUMERIC/NUMBER/DECIMAL lack intrinsic numeric affinity.

    Because LINQPad no longer relies on Microsoft.Data.SqlClient for column-type affinity, I've added an option in the connection properties to map NUMERIC/NUMBER/DECIMAL columns to System.Double where possible. This will fire when a table either has no rows, or the column is sparse.

    Let me know whether this fixes it for you.

Answers