SQLite & concurrent access best practices

by Evgeny V » Sun, 09 May 2010 15:06:59 GMT


Sponsored Links
 I believe you can provide the safe concurrency managment by using DB
transactions. Since you don't care about sequence between separate
activities you can run following snippet:

try
db.BeginTransaction
 db.RunCommand(insert or update etc.)
db.CommitTransaction
catch
db.RollbackTransaction

Evgeny





> >



SQLite & concurrent access best practices

by Thierry Legras » Mon, 10 May 2010 06:02:38 GMT


 Thank you both for your answers.

Are you sure using synchronized is enough inside the insert or update? I
also got exceptions in call to getReadableDatabase while another thread was
being writing so i don't think it would work. I am already using transaction
for DB write but it did not seem to make any changes.

The way i do each time i need to read/write/update DB is something like
that:

OnRead() {
 db = new myDBHelperClass();
 db.getReadableDatabase
 db.query(...)
 db.close()
}


OnWrite() {
 db = new myDBHelperClass();
 db.getWriteableDatabase
 db.beginTransaction
 db.insert(...)
 db.endTransaction
}

I was rather thinking of using a synchronized in OnRead and OnWrite, but has
such methods exists in differents Activities and Task, i am pretty reluctant
to do that.

I also so design were DB is open in Activity onCreate and closed in
onDestroy, but i guess i will not work when a task also needs write in the
DB while the DB is open by the activity.


2010/5/9 Evgeny V <evgen...@gmail.com>



(snip)

-- 
Thierry.

--


Sponsored Links


Other Threads

1. Androidology.com

Hi All,

Somebody interested in Androidology.com?

So contact me then.

Greetings,

Anton

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

2. What all do I need to begin programming in Android

> I wanted to know what all I will be needing to begin programming with

I have a Knol set up with some pointers to places to learn more about
Android:

http://knol.google.com/k/mark-murphy/android-programming

The tutorials at anddev.org, plus the (*cough*) books on Android
development, may be able to help.

--
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.2 Published!



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

3. Create custom zoom contols in Mapview

4. AlertDialog.Builder not showing items but when there is selection by up-down key it shows

5. parse XML String...

6. web service capability

7. question about process restart management