Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does nullColumnHack means? [duplicate]

According to the SQLiteDatabase API documentation:

  • insert(String table, String nullColumnHack, ContentValues values)

    Convenience method for inserting a row into the database.

What does nullColumnHack means?

Can you give me an example?

like image 714
Ethyl Casin Avatar asked Sep 25 '15 03:09

Ethyl Casin


1 Answers

Sometimes you want to insert an empty row, in that case ContentValues have no content value, and you should use nullColumnHack.

For example, you want to insert an empty row into a table student(id, name), which id is auto generated and name is null. You could invoke like this:

ContentValues cv = new ContentValues();
db.insert("student", "name", cv);
like image 158
Ted Yu Avatar answered Oct 08 '22 04:10

Ted Yu