#10 Int64 not correctly handled

closed-fixed
Robert Foster
None
4
2004-12-17
2004-09-29
PeeJ
No

Hi,

When using SQLite3 and SQLite.NET, if I insert a large
64-bit integer (eg. 632320567151401552) into a column
and then read it back I get a different number
(presumably because the value is interpreted as a
32-bit equivalent).

Please see my attached test case (using VS.NET C# with
.NET Framework 1.1)

Cheers,

Paul

Discussion

1 2 > >> (Page 1 of 2)
  • PeeJ
    PeeJ
    2004-09-29

    Test case

     
    Attachments
  • PeeJ
    PeeJ
    2004-09-29

    • summary: Int64 not correcly handled --> Int64 not correctly handled
     
  • PeeJ
    PeeJ
    2004-09-29

    Logged In: YES
    user_id=1130008

    Reading the SQLite document it seemed that there was a very
    scant list of types and all INTEGER types were generated
    on-the-fly based on the value in a given column/row.
    However, after tracing thru' the C-code looking for the
    problem, I noticed it appeared to be converting the value
    based on the declaration used for column. Hence, I tried
    creating the column with type LONG. Alas, it fixed the
    problem - although, I think the bug is still a bug.

     
  • Logged In: YES
    user_id=1000441

    The SQLite.NET provider infers the C# type based on the
    declaration of the column. The declaration of the column as
    INTEGER leads to 'Int32' type. 'BIGINT' leads to 'Int64' and
    'Long' leads to 'String' type. I think it's the correct
    behavior. The other databases will truncate the value of
    Int64 if you'll pass it to 'INTEGER' column, won't they?

     
    • status: open --> open-wont-fix
     
  • PeeJ
    PeeJ
    2004-09-29

    Logged In: YES
    user_id=1130008

    On the SQLite site, in the documentation section, under
    SQLite 3 types
    (http://www.hwaci.com/sw/sqlite/datatype3.html) it
    describes the integer column type as:

    <i>INTEGER. The value is a signed integer, stored in 1, 2, 3,
    4, 6, or 8 bytes depending on the magnitude of the value.</i>

    Consistent with this, the 64 bit quantity goes into SQLite
    correctly. It only gets truncated when it is read out by
    SQLite.NET.

    In the same document in section 2 - Column Affinity it says:

    <i>In SQLite version 3, the type of a value is associated with
    the value itself, not with the column or variable in which the
    value is stored</i>

    That is why I was expecting different behaviour. Strangely,
    the SQLite site only mentions 4 types TEXT, NUMERIC,
    INTEGER, NONE.

    I guess if you can determine the cell specific type then that
    would be more in keeping with the SQLite documentation.
    Otherwise I guess it is something for the SQLite.NET
    documentation.

    Either way, the product is fantastic. Thanks.

     
  • Logged In: YES
    user_id=1000441

    You're right. The code inferring C# data types was written
    for SQLite 2 and wasn't changed much since. I'm accepting
    it as a bug.

     
    • assigned_to: nobody --> alexhau
    • priority: 5 --> 4
    • status: open-wont-fix --> open-accepted
     
    • assigned_to: alexhau --> robertjf
     
  • Robert Foster
    Robert Foster
    2004-12-17

    Logged In: YES
    user_id=526041

    Ok, I've modified the code so that any INT's not a SMALLINt
    will be returned as Int64 (for now). Is this an acceptable
    solution? It fits with the way that SQLite handles INTEGER
    data. I'll commit it to CVS if no one has any objections
    within the next day or so.

     
1 2 > >> (Page 1 of 2)