Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:03+00:00 2026-05-23T17:54:03+00:00

Let’s say I have 2 tables, Contacts and Phones . User can input name

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:54:04+00:00Added an answer on May 23, 2026 at 5:54 pm

    first thought is part of the comment:

    cr.rawQuery("SELECT * FROM " + CONTACT_URI + "as cu LEFT JOIN " + PHONE_URI + " as pu ON  (cu.PHONE_COLUMN_ID = pu.PHONE_COLUMN_ID) WHERE CONTACT_COLUMN_NAME LIKE '%"+search+"%'");
    

    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:

    if(selectedIds.length==0)
        return;
    
    String formatString = "PHONE_COLUMN_ID=?";
    for(int i=0;i<selectedIds.length-1;i++)
    {
        formatString+=" OR PHONE_COLUMN_ID=? ";
    }
    Cursor pCur = cr.query(
        PHONE_URI, 
        new String[] { PHONE_COLUMN_ID, PHONE_COLUMN_DATA }, 
        formatString, 
        selectedIds, 
        null
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a RoR app with 3 pages. The user can get
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have an facebook application running using the JS SDK. First user
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have a list of objects TheListOfObjects. If I write this: TheListOfObjects
Let's say I have this string which I want to put in a multidimensional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.