Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert null in Sqlite table

Tags:

android

sqlite

I am trying to figure how to insert a null value into an SQLite table in Android.

This is the table:

"create table my table (_id integer primary key autoincrement, " +                                                "deviceAddress   text not null unique, " +                                                "lookUpKey text , " +                                                 "deviceName text , " +                                                "contactName text , " +                                                "playerName text , " +                                                "playerPhoto blob " +                                                ");";     

I wanted to use a simple Insert command via execSQL but since one of the values is a blob I can't do it (I think).

So, I am using a standard db.Insert command. How do I make one of the values null?

If I just skip it in the ContentValues object will it automatically put a null value in the column?

like image 374
theblitz Avatar asked Mar 22 '12 13:03

theblitz


People also ask

How do I insert a NULL value in a table?

You also can specify the NULL keyword in the VALUES clause to indicate that a column should be assigned a NULL value. The following example inserts values into three columns of the orders table: INSERT INTO orders (orders_num, order_date, customer_num) VALUES (0, NULL, 123);

Can we insert NULL values in table SQL?

You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints. The syntax is as follows. INSERT INTO yourTableName(yourColumnName) values(NULL); To understand the above syntax, let us first create a table.

Does SQLite support NULL?

Based on the SQL standard, PRIMARY KEY should always imply NOT NULL . However, SQLite allows NULL values in the PRIMARY KEY column except that a column is INTEGER PRIMARY KEY column or the table is a WITHOUT ROWID table or the column is defined as a NOT NULL column.


1 Answers

You can use ContentValues.putNull(String key) method.

like image 127
sujith Avatar answered Sep 25 '22 10:09

sujith