Elegant way of doing complex raw queries using a ContentProvider?

Up vote 1 down vote favorite share g+ share fb share tw.

I use a ContentProvider to speak with my application's database and I'm running into a bit of a problem. I have a query that is slightly complicated. It looks something like this: String sql = "select " + " tblHistory.

_id _id, " + " tblHistory. Item item, " + " tblHistory. Updated_on updated_on, " + " (select _id from tblList where tblList.

Item = tblHistory. Item) list_id, " + " 1 priority, " + "from " + " tblHistory " + "where " + " tblHistory. Status 'STATE_DELETING' and " + selection + " " + "union " + "select " + " tblSearch.

_id _id, " + " tblSearch. Item item, " + " -1 updated_on, " + " (select _id from tblList where tblList. Item = tblSearch.

Product_name) list_id, " + " 2 priority, " + "from " + " tblSearch " + "where " + " not exists (select * from tblHistory where tblHistory. Item = tblSearch. Product_name) " + "order by " + " priority, _id asc"; c = mDb.

RawQuery(sql, null); selection is String where = "tblHistory. User_id=" + Integer. ToString(intUserId) + " and tblHistory.

Item like '%" + strSearch + "%'"; My problem is my sub-queries. I have a constraint I need to add, but no good way of getting that constraint down the pipe to the method. I need to use the correct user_id on the sub-queries.

At this point, I think I have 2 options: 1) Parse out the user_id substring from selection. 2) Use selectionArgs as a hack to pass "user_id = " + Integer. ToString(intUserId) to the method.

Any other ideas? I should note that while I'd rather not doing anything hack-ish, I have made my ContentProvider private as it is intended to only be used by my application; so if I absolutely have to, I can. Android contentprovider link|improve this question edited Dec 28 '10 at 21:18 asked Dec 28 '10 at 20:24Andrew1,3491245 79% accept rate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions