0

I am new in android sqlite and I want to know what is the point of using null in some sqlite codes. for example here with ContentValues :

    ContentValues values = new ContentValues();
    values.put(KEY_VALUE1, x.getVALUE1()); 
    values.put(KEY_VALUE2, x.getVALUE2());
    db.insert(TABLE_NAM, null, values); 

or with select:

Cursor cursor = db.rawQuery("SELECT  * FROM " + TABLE_NAM , null); 
0

2 Answers 2

1

It depends on what the API states, from the docs we can see this for the method insert()

on the second parameter of db.insert(TABLE_NAM, null, values); the null is the nullColumnHack:

nullColumnHack optional; may be null. SQL doesn't allow inserting a completely empty row without naming at least one column name. If your provided values is empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty.

As for the rawQuery() method it means:

selectionArgs You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.

Sign up to request clarification or add additional context in comments.

Comments

0

If you use eclipse you should be able to see what the method ask for parameter by moving your mouse on the method name. After that it will be easy to understand why the parameter is null.

Otherwise, you can easily check android developers website and see the documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.