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. paging boss Aj

haloooo...boss aja klo mantau tlg call hp Ane yah,stay Ada yg tau um ama
gtalknya?
thk u

disundul pake robot ijo nexus one

-- 
"Indonesian Android Community [id-android]" 

2. Android-indonesia

Guys,
Www.android-indonesia.com itu punya siapa ya? Punya boss Yop?

Salam,

Lucky Sebastian
@ n e x u s  one

-- 
"Indonesian Android Community [id-android]" 

3. Nubi

4. Question about draw dialog

5. Review nexusdesire Rom remix 1.0

6. mail telat masuk

7. Salam kena