BST Kaal BST Kaal - 3 days ago 5
Android Question

How to Add a Boolean Column in Android SQlite

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".

Answer

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);
Comments