I have a query statement with a LEFT JOIN in my ContentProvider
the left table is posts and it has a post_id column, the right table is taggings it it has a post_id column as well and I’m doing posts left join taggings on posts.post_id=taggings.post_id
when querying the ContentProvider, if there is no matching row in the taggings table, for some reason the returned value from cursor.getColumnIndex("post_id") is wrong and the int value of the id is always 0.
if there is a matching row in taggings, everything work as expected.
what am I missing here ?
ContentProvider query:
case POSTS:
qb.setTables(MetaData.TABLE_POSTS
+ " LEFT JOIN " + MetaData.TABLE_TAGGINGS + " ON "
+ MetaData.TABLE_POSTS + "." + MetaData.COLUMN_POST_ID
+ "=" + MetaData.TABLE_TAGGINGS + "." + MetaData.COLUMN_POST_ID
);
break;
cursor query statement:
Cursor cursor = context.getContentResolver().query(MetaData.POSTS_URI,
null, null,
null, MetaData.TABLE_POSTS + "." + MetaData.COLUMN_POST_ID + " DESC");
I fixed that by using
setProjectionMap()to mapMetaData.COLUMN_POST_IDtoMetaData.TABLE_POSTS + "," + MetaData.COLUMN_POST_ID