Let’s say I have 2 tables, Contacts and Phones. User can input name for Contacts query. I use this
Cursor cur = cr.query(
CONTACT_URI,
new String[] { CONTACT_COLUMN_ID, CONTACT_COLUMN_NAME },
CONTACT_COLLUMN_NAME + " LIKE '%" + search + "%'",
null,
null
);
And then I want to query from Phones for the matching contact I got from first query. I can use third parameter to input my condition such as "WHERE _ID = xx OR _ID = xx" and so on…
The question is,
Can I use first query/cursor as condition for next query? My second query is like this :
Cursor pCur = cr.query(
PHONE_URI,
new String[] { PHONE_COLUMN_ID, PHONE_COLUMN_DATA },
null,
null,
null
);
EDIT : extra note, I’m querying from device database, so I only have Uri to use.
EDIT 2 : alternatively, I can use this
Cursor pCur = cr.query(
PHONE_URI,
new String[] { PHONE_COLUMN_ID, PHONE_COLUMN_DATA },
PHONE_COLUMN_ID,
selectedIds,
null
);
but if selectedIds got too big, I got this exception
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): FATAL EXCEPTION: main
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.laac.comp.phonelookup/com.laac.comp.phonelookup.PhoneContactLookup}: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x199d7c0
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.os.Handler.dispatchMessage(Handler.java:99)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.os.Looper.loop(Looper.java:143)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread.main(ActivityThread.java:4196)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at java.lang.reflect.Method.invoke(Method.java:507)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at dalvik.system.NativeStart.main(Native Method)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): Caused by: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x199d7c0
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:158)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:372)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.content.ContentProviderProxy.query(ContentProviderNative.java:408)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.content.ContentResolver.query(ContentResolver.java:264)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at com.laac.comp.phonelookup.PhoneContactLookup.getContactWithPhone(PhoneContactLookup.java:255)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at com.laac.comp.phonelookup.PhoneContactLookup.onCreate(PhoneContactLookup.java:84)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
07-13 11:06:48.496: ERROR/AndroidRuntime(25137): ... 11 more
PhoneContactLookup.java:255 is my query on EDIT 2
first thought is part of the comment:
second thought is based on your edit 2 I think you need to first create a format query string that has ? in the right places to be filled in by the selected ids list, so I think it would be something like: