user3368764
user3368764

Reputation: 19

default value of a created SQLiteDatabase

hello I am trying to use the sqlite database on android to push an integer array and store it in the database then use it and update it on demand. what i do not understand is that android has a create or open function for the sqlite database what is the default value of created database containing an integer column? is it 0? and if i am running the program for the first time i should use the create then each consecutive run should use open how can i separate them ? i have created the databases using

SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS MyTable(isChkd INT(1));");

Upvotes: 0

Views: 109

Answers (2)

ucsunil
ucsunil

Reputation: 7494

By default, there will not be any values in a table that you have just created and not entered any data in. It will resolve to null and if you did try to access data without having made any entries, you will get a NullPointerException. You could set the default value to be entered in a column by setting the DEFAULT flag.

Once you have created a database in onCreate(), you only need to call getReadableDatabase() or getWritableDatabase() on an instance of an object of the class which extends SQLLiteOpenHelper to execute your queries.

Upvotes: 0

akirk
akirk

Reputation: 6837

Android uses SQLite. If you want to be sure just specify a default value, as seen in the documentation, resp. here:

CREATE TABLE IF NOT EXISTS MyTable (isChkd INT(1) DEFAULT 0)

Upvotes: 1

Related Questions