Search code examples
androidsqliteandroid-cursorgettype

cursor.getType() and CursorIndexOutOfBoundsException exception


There is a thing that I can not understand about Cursor.getType(), can anyone explain why do I get this stupid exception when I want to get columns type if cursor has no record but there are columns? I mean, if cursor has record there is no problem, I can use getType method to get columns type without any problem but if there is no any record it throws this exception out.

The question is why must I need records to get columns type? Why just knowing columns name is not enough to get types of it? Is this ridiculous?


Solution

  • It's because SQLite uses dynamic typing:

    Most SQL database engines (every SQL database engine other than SQLite, as far as we know) uses static, rigid typing. With static typing, the datatype of a value is determined by its container - the particular column in which the value is stored.

    SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container.

    http://www.sqlite.org/datatype3.html

    So no value, no data type.