How to Add a Boolean Column in Android SQlite

android, android-sqlite, sqlite

Solution

You could use something like this:

Create your table:

static final String CREATE_DB_TABLE = 
    "CREATE TABLE " + CONTACTS_TABLE_NAME " + 
    " (_id INTEGER PRIMARY KEY AUTOINCREMENT," + 
    "..." + " flag INTEGER DEFAULT 0)";

retrieve your value as:

Boolean flag = (cursor.getInt(cursor.getColumnIndex("flag")) == 1);

Problem

I have created a table for my `ContentProvider` using the following line : ``` static final String CREATE_DB_TABLE = " CREATE TABLE " + CONTACTS_TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " pid TEXT NOT NULL, " + " name TEXT NOT NULL,"+ "number TEXT NOT NULL);"; ``` It has 4 columns. Now i want to add a column with a boolean value of true/false. How can i add append/change this statement if i have to add a boolean column named "status".

Original source

Related problems