Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use Query in a Query?
    text
    copied!<p>Let's say I have 2 tables, <code>Contacts</code> and <code>Phones</code>. User can input name for <code>Contacts</code> query. I use this </p> <pre><code>Cursor cur = cr.query( CONTACT_URI, new String[] { CONTACT_COLUMN_ID, CONTACT_COLUMN_NAME }, CONTACT_COLLUMN_NAME + " LIKE '%" + search + "%'", null, null ); </code></pre> <p>And then I want to query from <code>Phones</code> 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...</p> <h3>The question is,</h3> <p>Can I use first query/cursor as condition for next query? My second query is like this : </p> <pre><code>Cursor pCur = cr.query( PHONE_URI, new String[] { PHONE_COLUMN_ID, PHONE_COLUMN_DATA }, null, null, null ); </code></pre> <p>EDIT : extra note, I'm querying from device database, so I only have Uri to use. </p> <p>EDIT 2 : alternatively, I can use this</p> <pre><code>Cursor pCur = cr.query( PHONE_URI, new String[] { PHONE_COLUMN_ID, PHONE_COLUMN_DATA }, PHONE_COLUMN_ID, selectedIds, null ); </code></pre> <p>but if selectedIds got too big, I got this exception </p> <pre><code>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 </code></pre> <p><code>PhoneContactLookup.java:255</code> is my query on EDIT 2</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload