Using SQLiteQueryBuilder With Provided CONTENT_URI?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Using SQLiteQueryBuilder With Provided CONTENT_URI?

Postby Wysie » Tue Feb 09, 2010 5:59 pm

Hi all,

I would like to know how I can make use of SQLiteQueryBuilder to query Phone.CONTENT_URI, or Calls.CONTENT_URI, etc. (basically the ones that come with Android)?

I've tried searching but could not find anything similar.

The following code I used:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. SQLiteQueryBuilder sqb = new SQLiteQueryBuilder();
  2.  
  3.                 sqb.query(Phone.CONTENT_URI, PEOPLE_PHONE_PROJECTION, peopleSql, args, null, null, PEOPLE_SORT);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Does not work because Phone.CONTENT_URI is not an SQLiteDatabase object, which they are expecting. Some help would be wonderful, thanks! :)
Wysie
Freshman
Freshman
 
Posts: 4
Joined: Wed Dec 16, 2009 6:26 am

Top

Postby bgta » Wed Feb 10, 2010 10:40 am

Look: http://developer.android.com/guide/topi ... l#querying

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.provider.Contacts.People;
  3.  
  4. import android.content.ContentUris;
  5.  
  6. import android.net.Uri;
  7.  
  8. import android.database.Cursor;
  9.  
  10.  
  11.  
  12. // Use the ContentUris method to produce the base URI for the contact with _ID == 23.
  13.  
  14. Uri myPerson = ContentUris.withAppendedId(People.CONTENT_URI, 23);
  15.  
  16.  
  17.  
  18. // Alternatively, use the Uri method to produce the base URI.
  19.  
  20. // It takes a string rather than an integer.
  21.  
  22. Uri myPerson = Uri.withAppendedPath(People.CONTENT_URI, "23");
  23.  
  24.  
  25.  
  26. // Then query for this specific record:
  27.  
  28. Cursor cur = managedQuery(myPerson, null, null, null, null);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
bgta
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 10, 2010 10:37 am
Location: Terrassa,Spain

Postby bgta » Wed Feb 10, 2010 11:02 am

How about something like this:

SQLiteQueryBuilder sqb = new SQLiteQueryBuilder();
sqb.query(Phone.CONTENT_URI, PEOPLE_PHONE_PROJECTION, peopleSql, args, null, null, PEOPLE_SORT);

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. // Make the query.
  3.  
  4. Cursor cur = managedQuery(Phone.CONTENT_URI,
  5.  
  6.                          PEOPLE_PHONE_PROJECTION,
  7.  
  8.                          peopleSql,
  9.  
  10.                          args,
  11.  
  12.                          People.NAME + " ASC");
  13.  
  14.  
  15.  
  16. if (cur.moveToFirst()) {
  17.  
  18.  
  19.  
  20.         String name;
  21.  
  22.         String phoneNumber;
  23.  
  24.         int nameColumn = cur.getColumnIndex(People.NAME);
  25.  
  26.         int phoneColumn = cur.getColumnIndex(People.NUMBER);
  27.  
  28.         String imagePath;
  29.  
  30.    
  31.  
  32.         do {
  33.  
  34.             // Get the field values
  35.  
  36.             name = cur.getString(nameColumn);
  37.  
  38.             phoneNumber = cur.getString(phoneColumn);
  39.  
  40.            
  41.  
  42.             // Do something with the values.
  43.  
  44.             ...
  45.  
  46.  
  47.  
  48.         } while (cur.moveToNext());
  49.  
  50.  
  51.  
  52.     }
  53.  
  54.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


... where peopleSql is somthing like this:

String peopleSql = Contacts.PhoneNumberColumn+"<>?";
bgta
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 10, 2010 10:37 am
Location: Terrassa,Spain

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests