Artem
Artem

Reputation: 4639

How to read a boolean from database (use cursor)?

Why can't I read bool type from cursor? I'm using this code:

private boolean readBooleanByKey(Cursor cursor, int key) {

    try {
        return cursor.getInt(key) > 0; // always return false 
    } catch (Exception e) {            
    }
}

This is part of DDL from database table

  CREATE TABLE [dn_user_cars] (
     [id] [INTEGER PRIMARY KEY AUTOINCREMENT],   
     [archived] BOOLEAN; // this variable I cant read

Upvotes: 1

Views: 1022

Answers (2)

Robert
Robert

Reputation: 1266

To store value you can user integer value:

int flag = (boolValue) ? 1 : 0;

to read value from integer "number" value to boolean:

boolean flag2 = (intValue == 1) ? true : false;

Upvotes: 3

alpinescrambler
alpinescrambler

Reputation: 1954

I don't think there is a BOOLEAN data type in SQLite. See some docs here: http://www.sqlite.org/datatype3.html

Upvotes: 1

Related Questions