Home > android > SQLite, IFNULL, weird…

SQLite, IFNULL, weird…

I have some SQLite queries in my project where I use things like:

... "... IFNULL(table1.col1, table1.col2) = table2.col3 ... "

Did this in some new code:

db.update(TABLE_NAME, contentValues, "... IFNULL(table1.col1, table1.col2) = ?...", new String[] { val1, val2, ...} );

… and the update never actually updated any messages.

Expanding IFNULL “by hand” started producing expected results:

db.update(TABLE_NAME, contentValues, "... table1.col1 IS NULL AND table1.col2 = ? OR table1.col1 = ? ...", new String[] { val1, val1, val2, ...} );

Probably has something to do with how Android’s SQLiteDatabase methods always bind query arguments as strings.

( an hour or so lost… sigh )

Advertisements
Categories: android
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s