Luca,

The way a ContentProvider maps a query into SQL statements is entirely up to your provider.

The framework only imposes a few things:

- The "data bucket" is selected by the URI.
- The query is specified as an array of values.
- The result is returned as a Cursor (not necessarily a SQLite cursor).

You can do all kinds of subqueries, joins, etc - in your provider. The meaning of the Uri doesn't have to be that it's used to unambiguously select a Sqlite table. So with your own provider, you have a lot of flexibility.

There are times, though, when the ContentResolver interface is somewhat limiting, but you can bypass it for your own provider. See below:

03.01.2011 12:32, Luca Carlon пишет:
I already rooted and executed the queries I need using sqlite3, but I
need to do this programmatically.

Assuming I am the ContentProvider developer, can I somehow execute
these kinds of queries (using functions like replace, using subqueries
etc...) using the SQLiteDatabase class? Its query method seems to
suffer the same limitations, I cannot write a free SQL query command.

For your own content provider, assuming it's local to the process using it, you can get a reference to your provider object like this:

ContentResolver cr = ...

ContentProviderClient client = null;
try {
client = cr.acquireContentProviderClient(AUTHORITY);
ContentProvider localProvider = client.getLocalContentProvider();
YourContentProvider yourContentProvider = (YourContentProvider) localProvider;

// call methods of YourContentProvider

} finally {
if (client != null) {
client.release();
}
}

This is not pretty or clean, but it's a way to call methods defined in your content provider class, which can have more rich functionality (like inserting a bunch of rows in a transaction, etc, etc).

-- Kostya

Thanks for your help!

On Jan 3, 9:37 am, Sarwar Erfan<erfanonl...@gmail.com>  wrote:
On Monday, January 3, 2011 2:32:29 PM UTC+6, Luca Carlon wrote:

Ok, that was just to confirm that it is impossible to use it that way.
And what about making complex queries? The ContentProvider class
provides the query method which, however, seems to be quite a
limitation. What can I do, for instance, if I need to create queries
with subqueries (or some other types of queries doesn't fit the simple
pattern provided by the query method)?
Thanks for your answers!
You can *root* your phone to access the DB (in case you are not developing
any app for general people)
Or, you can send feature request to the content provider developer to add
options to your desired kind of queries.

You *cannot* access others database. You *cannot* use content provider other
than the available options and filters set by the developer.
Please bear with these.

Regards
Sarwar Erfan


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to