how to deal complex sql in ContentProvider

by James Wang » Tue, 09 Feb 2010 10:40:17 GMT


Sponsored Links
 Hi,
We want to add below update sql into our contentprovider:
update tableName
   set column1 = column1 + 1
   where column1 >= 50

We found current update of contentprovider does not support it, which
would not recognize the "column1" of "column1 + 1" as column name.

So we have to add execSQL method into ContentProvider and I think it
is dirt.

So I wonder if anyone know how to do such thing with ContentProvider
or any more elegant way to achieve it.

Best Regards

James

--



how to deal complex sql in ContentProvider

by Mark Murphy » Tue, 09 Feb 2010 10:47:42 GMT


 > We want to add below update sql into our contentprovider:

I am guessing what you meant to write is that you are calling execSQL() on
your SQLiteDatabase from some spot in a ContentProvider.

For SQLiteDatabase, execSQL() is certainly a viable answer for your UPDATE
statement (regardless of whether you think it is "dirt"), and I do not
think you have any alternative but to use execSQL().

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 


--


Sponsored Links


how to deal complex sql in ContentProvider

by Mark Murphy » Tue, 09 Feb 2010 11:06:35 GMT


 > We want to add below update sql into our contentprovider:

It dawns on me that another possible interpretation of what you have above
is that a client of your ContentProvider is attempting to use that UPDATE
statement against the ContentProvider.

ContentProvider is not a database abstraction -- it's a content store
abstraction. Not all ContentProviders will be backed up by a SQLite
database or anything else that interprets SQL. Hence, it is not surprising
to me that ContentProvider does not support arbitrary SQL statements.

Since a ContentProvider -- particularly one needing your proposed UPDATE
statement -- is only needed for inter-process content sharing, you might
consider switching to a remote service (using AIDL) instead.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 


--



how to deal complex sql in ContentProvider

by Jens » Tue, 09 Feb 2010 15:49:51 GMT


 Sure, but in almost all cases it is backed by SQLite - so
intentionally gimping the API that's supposed to be used for
exchanging data across applications is monumentally stupid - since
JDBC is not an alternative on Android.


Designing for the lowest common denominator != good.


--



how to deal complex sql in ContentProvider

by James Wang » Wed, 10 Feb 2010 09:40:34 GMT


 Thanks Murphy, Jens!
We are using one contentprovider two share all data amount many apps.
In fact, we are developing contentprovider as the bridge between apps
and database, sound like JDBC. Switching to a remote service sounds
like a option but we don't think it is good design that exposing one
service and one contentprovider to other apps which need process with
database.

I have to agree with Jens. In real world, content provider seems not
enough for every one.

Now we think about another option - to refactor our db design. Hope we
can get something at the end of this road.

James

--



Other Threads

1. Provider.Settings.Secure database is lacking some entries

That seems okay.  What do you think is wrong?  Not all of the possible
entries are initialized, like on 1.0.

On Mon, Jan 26, 2009 at 1:57 PM, laubea...@googlemail.com <





-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~

2. Marketplace Sponsorship

I have been working on an Application that displays in-game time
information for a popular MMO Final Fantasy XI. Its finally complete
and I wanted to release it to the market but I noticed you have to
spend 25$ to activate your account. I don't really want to spend any
money right now on it and was wondering if there was any kind of
sponsorship program to help out with the fee. I don't mind providing
all my contact information just don't want to spend all the money on
it.

Cheers.
--~--~---------~--~----~------------~-------~--~----~

3. 3G network response different from Wifi

4. Map Server

5. Screen on/off Intents Can't Be Declared in AndroidManifest?

6. XML 'keywords'

7. question about KEYCODE_NOTIFICATION