in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

System.OverflowException in SQLiteDataReader

Last post 04-29-2008 8:13 AM by Robert Simpson. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 04-24-2008 8:02 AM

    • Mark2
    • Top 10 Contributor
    • Joined on 04-24-2008
    • Posts 39

    System.OverflowException in SQLiteDataReader

    I have a database column typed Int(13) which contains values which all are 13 digits long.
    When reading an Overflow occurs:
    ...
    bei System.Threading.ThreadHelper.ThreadStart()System.OverflowException: Der Wert für einen Int32 war zu groß oder zu klein.
    bei System.Convert.ToInt32(Int64 value)
    bei System.Int64.System.IConvertible.ToInt32(IFormatProvider provider)
    bei System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    bei System.Data.SQLite.SQLite3.GetValue(SQLiteStatement stmt, Int32 index, SQLiteType typ)
    bei System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i)
    bei System.Data.SQLite.SQLiteDataReader.GetValues(Object[ values)
    bei System.Data.Common.DbEnumerator.MoveNext()
    ...
  • 04-26-2008 7:30 AM In reply to

    Re: System.OverflowException

    You're trying to cram a 13 digit decimal number into a 32 bit variable (Int32).  13 decimal digits will always exceed 32 bits of storage.  You should check out the DataType mappings thread in the General forum for guidance on which data type to use based on the size of your numbers.

  • 04-26-2008 2:00 PM In reply to

    • Mark2
    • Top 10 Contributor
    • Joined on 04-24-2008
    • Posts 39

    Re: System.OverflowException

    No
    The data already is in the database and I try to read it.

  • 04-28-2008 5:32 AM In reply to

    Re: System.OverflowException

    Yes.

    This line in your error messages tells you what's going on:

    > System.Convert.ToInt32(Int64 value)

    The number in your database is defined as Int64 (presumably because of the type you've chosen for the column), and you're trying to stuff it into a smaller number.  If the actual value of the Int64 value being passed will not fit into 32 bits (the Int32 part), you will get an overflow.

    Brad

  • 04-28-2008 5:48 AM In reply to

    Re: System.OverflowException

     Right, but you're trying to read it as an Int32 not an Int64.  You need to be reading the field out as a 64 bit integer not a 32 bit integer.  As the previous poster said, the data type mappings forum can help you here.

  • 04-29-2008 7:57 AM In reply to

    • Mark2
    • Top 10 Contributor
    • Joined on 04-24-2008
    • Posts 39

    Re: System.OverflowException

    Sorry for having been not clear enough. In my program I simply do the following:

    Dim bs As New System.Windows.Forms.BindingSource

    Dim cmd As New System.Data.SQLite.SQLiteCommand("SELECT ROWID,* FROM " & tablename, cn)

    Dim dr As System.Data.SQLite.SQLiteDataReader = cmd.ExecuteReader

    bs.DataSource = dr

     

    The crash occurs in the last statement. It does not occur when I change the columntype of the offending column from Int(13) to TEXT. So I think it is a bug.

  • 04-29-2008 8:13 AM In reply to

    Re: System.OverflowException

    The SQLite provider doesn't understand the (13) part after the INT.  It sees INT and assumes 32-bit integer.  If you need to store an integer outside the bounds of 32-bit land, then use the datatype INTEGER or LONG.  INT is meant to be compatible with JET, which dictates that INT is 32-bit.  INTEGER is native to SQLite and means 64-bit.  LONG is also 64-bit.

     

Page 1 of 1 (7 items)
Powered by Community Server (Commercial Edition), by Telligent Systems