Re: [android-developers] Re: error code 5: database is locked

2010-11-02 Thread Kostya Vasilyev

William,

This:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#setLockingEnabled(boolean)

suggests that thread-safe locking is enabled by default.

Are you turning it off somewhere, perhaps?

If not, I think you could try calling this method to explicitly enable 
locking.


-- Kostya

02.11.2010 8:07, William Ferguson пишет:

I have seen some other discussions on this issue for Sqlite and the
solution was to increase the busy timeout for the DB.
Anyone know how that is achieved on Android?


On Nov 2, 12:14 am, William Fergusonwilliam.ferguson...@gmail.com
wrote:

I'm seeing the same thing.

And to answer the questions:
1 - There is no other app using my db, though it is accessed from both
my Activity and an IntentService within my app. Both of which needs
write access.
2 - I closed the cursor every time.

I cannot see any need for the entire DB to be locked (there is no DDL
being executed).
But its possible that there is a collision between the 2 Threads. Ie
both trying to write at the same time (though never to the same
record).
But I had presumed that one would halt (unless it times out) waiting
for the first to release a write lock.
But it doesn't look like there is any waiting being done.
Is that an option that can be configure? for an SQLite transaction? I
couldn't find anything that suggested that.

Stacktrace below.

William

11-01 23:40:30.173: ERROR/Database(8715): Error inserting ..
crane=large length=6
 android.database.sqlite.SQLiteException: error code 5:
database is locked
 at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
 at
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
66)
 at
android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:
1426)
 at
android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:
1286)

On Oct 25, 10:48 pm, AJajeet.invinci...@gmail.com  wrote:


Hi gcstang,
Very basic but check the following:-
1- Is any other app using your DB?
2- Did you close the cursor every time when you opened it?
Thanks,
AJ
On Oct 25,5:41 pm, gcstanggcst...@gmail.com  wrote:

ping, anyone that can answer this?
On Oct 16, 10:58 am, gcstanggcst...@gmail.com  wrote:

Here is the stack:
android.database.sqlite.SQLiteException:errorcode5:databaseislocked
 at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
 at
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
55)
 at
android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
1779)
 at
android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
1709)
 at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
 at com.myapp.MyView$13.run(MyView.java:1260)
 at java.lang.Thread.run(Thread.java:1102)
On Oct 15, 11:54 am, DanHdanhi...@ieee.org  wrote:

Where is theerrorbeing thrown from?  (You might include the
exception traceback.)
On Oct 15, 9:44 am, gcstanggcst...@gmail.com  wrote:

Has anyone encountered this and is there a solution to work around it?
I'm creating a Thread and in that thread I open adatabaseconnection
using the DBHelper, perform an update on a field in mydatabaseand
close it. I create a separate one in the Thread because if the View is
closed the global one for that view is closed, causing my Thread
update to throw anerror.
The thread is in a View, that also has it's own instance of the
DBHelper and
opens thedatabaseonCreate
closes it onPause
opens it onResume
closes it onDestroy
The instance in my Thread is throwing this but not all the time :error
code5:databaseislocked
Is there a known practice I should implement so I don't get thiserror?





--
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


[android-developers] Re: error code 5: database is locked

2010-11-01 Thread William Ferguson
I'm seeing the same thing.

And to answer the questions:
1 - There is no other app using my db, though it is accessed from both
my Activity and an IntentService within my app. Both of which needs
write access.
2 - I closed the cursor every time.

I cannot see any need for the entire DB to be locked (there is no DDL
being executed).
But its possible that there is a collision between the 2 Threads. Ie
both trying to write at the same time (though never to the same
record).
But I had presumed that one would halt (unless it times out) waiting
for the first to release a write lock.
But it doesn't look like there is any waiting being done.
Is that an option that can be configure? for an SQLite transaction? I
couldn't find anything that suggested that.

Stacktrace below.

William


11-01 23:40:30.173: ERROR/Database(8715): Error inserting ..
crane=large length=6
android.database.sqlite.SQLiteException: error code 5:
database is locked
at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
66)
at
android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:
1426)
at
android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:
1286)




On Oct 25, 10:48 pm, AJ ajeet.invinci...@gmail.com wrote:
 Hi gcstang,

 Very basic but check the following:-
 1- Is any other app using your DB?
 2- Did you close the cursor every time when you opened it?

 Thanks,
 AJ

 On Oct 25,5:41 pm, gcstang gcst...@gmail.com wrote:

  ping, anyone that can answer this?

  On Oct 16, 10:58 am, gcstang gcst...@gmail.com wrote:

   Here is the stack:

   android.database.sqlite.SQLiteException:errorcode5:databaseislocked
           at
   android.database.sqlite.SQLiteStatement.native_execute(Native Method)
           at
   android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
   55)
           at
   android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
   1779)
           at
   android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
   1709)
           at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
           at com.myapp.MyView$13.run(MyView.java:1260)
           at java.lang.Thread.run(Thread.java:1102)

   On Oct 15, 11:54 am, DanH danhi...@ieee.org wrote:

Where is theerrorbeing thrown from?  (You might include the
exception traceback.)

On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:

 Has anyone encountered this and is there a solution to work around it?

 I'm creating a Thread and in that thread I open adatabaseconnection
 using the DBHelper, perform an update on a field in mydatabaseand
 close it. I create a separate one in the Thread because if the View is
 closed the global one for that view is closed, causing my Thread
 update to throw anerror.

 The thread is in a View, that also has it's own instance of the
 DBHelper and
 opens thedatabaseonCreate
 closes it onPause
 opens it onResume
 closes it onDestroy

 The instance in my Thread is throwing this but not all the time :error
code5:databaseislocked

 Is there a known practice I should implement so I don't get thiserror?

-- 
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


[android-developers] Re: error code 5: database is locked

2010-11-01 Thread William Ferguson
I have seen some other discussions on this issue for Sqlite and the
solution was to increase the busy timeout for the DB.
Anyone know how that is achieved on Android?


On Nov 2, 12:14 am, William Ferguson william.ferguson...@gmail.com
wrote:
 I'm seeing the same thing.

 And to answer the questions:
 1 - There is no other app using my db, though it is accessed from both
 my Activity and an IntentService within my app. Both of which needs
 write access.
 2 - I closed the cursor every time.

 I cannot see any need for the entire DB to be locked (there is no DDL
 being executed).
 But its possible that there is a collision between the 2 Threads. Ie
 both trying to write at the same time (though never to the same
 record).
 But I had presumed that one would halt (unless it times out) waiting
 for the first to release a write lock.
 But it doesn't look like there is any waiting being done.
 Is that an option that can be configure? for an SQLite transaction? I
 couldn't find anything that suggested that.

 Stacktrace below.

 William

 11-01 23:40:30.173: ERROR/Database(8715): Error inserting ..
 crane=large length=6
         android.database.sqlite.SQLiteException: error code 5:
 database is locked
         at
 android.database.sqlite.SQLiteStatement.native_execute(Native Method)
         at
 android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
 66)
         at
 android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:
 1426)
         at
 android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:
 1286)

 On Oct 25, 10:48 pm, AJ ajeet.invinci...@gmail.com wrote:

  Hi gcstang,

  Very basic but check the following:-
  1- Is any other app using your DB?
  2- Did you close the cursor every time when you opened it?

  Thanks,
  AJ

  On Oct 25,5:41 pm, gcstang gcst...@gmail.com wrote:

   ping, anyone that can answer this?

   On Oct 16, 10:58 am, gcstang gcst...@gmail.com wrote:

Here is the stack:

android.database.sqlite.SQLiteException:errorcode5:databaseislocked
        at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
        at
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
55)
        at
android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
1779)
        at
android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
1709)
        at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
        at com.myapp.MyView$13.run(MyView.java:1260)
        at java.lang.Thread.run(Thread.java:1102)

On Oct 15, 11:54 am, DanH danhi...@ieee.org wrote:

 Where is theerrorbeing thrown from?  (You might include the
 exception traceback.)

 On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:

  Has anyone encountered this and is there a solution to work around 
  it?

  I'm creating a Thread and in that thread I open adatabaseconnection
  using the DBHelper, perform an update on a field in mydatabaseand
  close it. I create a separate one in the Thread because if the View 
  is
  closed the global one for that view is closed, causing my Thread
  update to throw anerror.

  The thread is in a View, that also has it's own instance of the
  DBHelper and
  opens thedatabaseonCreate
  closes it onPause
  opens it onResume
  closes it onDestroy

  The instance in my Thread is throwing this but not all the time 
  :error
 code5:databaseislocked

  Is there a known practice I should implement so I don't get 
  thiserror?



-- 
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


[android-developers] Re: error code 5: database is locked

2010-10-25 Thread gcstang
ping, anyone that can answer this?

On Oct 16, 10:58 am, gcstang gcst...@gmail.com wrote:
 Here is the stack:

 android.database.sqlite.SQLiteException:errorcode5:databaseislocked
         at
 android.database.sqlite.SQLiteStatement.native_execute(Native Method)
         at
 android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
 55)
         at
 android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
 1779)
         at
 android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
 1709)
         at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
         at com.myapp.MyView$13.run(MyView.java:1260)
         at java.lang.Thread.run(Thread.java:1102)

 On Oct 15, 11:54 am, DanH danhi...@ieee.org wrote:

  Where is theerrorbeing thrown from?  (You might include the
  exception traceback.)

  On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:

   Has anyone encountered this and is there a solution to work around it?

   I'm creating a Thread and in that thread I open adatabaseconnection
   using the DBHelper, perform an update on a field in mydatabaseand
   close it. I create a separate one in the Thread because if the View is
   closed the global one for that view is closed, causing my Thread
   update to throw anerror.

   The thread is in a View, that also has it's own instance of the
   DBHelper and
   opens thedatabaseonCreate
   closes it onPause
   opens it onResume
   closes it onDestroy

   The instance in my Thread is throwing this but not all the time :error
  code5:databaseislocked

   Is there a known practice I should implement so I don't get thiserror?



-- 
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


[android-developers] Re: error code 5: database is locked

2010-10-25 Thread AJ
Hi gcstang,

Very basic but check the following:-
1- Is any other app using your DB?
2- Did you close the cursor every time when you opened it?


Thanks,
AJ

On Oct 25, 5:41 pm, gcstang gcst...@gmail.com wrote:
 ping, anyone that can answer this?

 On Oct 16, 10:58 am, gcstang gcst...@gmail.com wrote:

  Here is the stack:

  android.database.sqlite.SQLiteException:errorcode5:databaseislocked
          at
  android.database.sqlite.SQLiteStatement.native_execute(Native Method)
          at
  android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
  55)
          at
  android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
  1779)
          at
  android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
  1709)
          at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
          at com.myapp.MyView$13.run(MyView.java:1260)
          at java.lang.Thread.run(Thread.java:1102)

  On Oct 15, 11:54 am, DanH danhi...@ieee.org wrote:

   Where is theerrorbeing thrown from?  (You might include the
   exception traceback.)

   On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:

Has anyone encountered this and is there a solution to work around it?

I'm creating a Thread and in that thread I open adatabaseconnection
using the DBHelper, perform an update on a field in mydatabaseand
close it. I create a separate one in the Thread because if the View is
closed the global one for that view is closed, causing my Thread
update to throw anerror.

The thread is in a View, that also has it's own instance of the
DBHelper and
opens thedatabaseonCreate
closes it onPause
opens it onResume
closes it onDestroy

The instance in my Thread is throwing this but not all the time :error
   code5:databaseislocked

Is there a known practice I should implement so I don't get thiserror?

-- 
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


[android-developers] Re: error code 5: database is locked

2010-10-16 Thread gcstang
Here is the stack:

android.database.sqlite.SQLiteException: error code 5: database is
locked
at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
at
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:
55)
at
android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:
1779)
at
android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:
1709)
at com.myapp.MyDbAdapter.updateField2(MyDbAdapter.java:468)
at com.myapp.MyView$13.run(MyView.java:1260)
at java.lang.Thread.run(Thread.java:1102)

On Oct 15, 11:54 am, DanH danhi...@ieee.org wrote:
 Where is the error being thrown from?  (You might include the
 exception traceback.)

 On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:

  Has anyone encountered this and is there a solution to work around it?

  I'm creating a Thread and in that thread I open a database connection
  using the DBHelper, perform an update on a field in my database and
  close it. I create a separate one in the Thread because if the View is
  closed the global one for that view is closed, causing my Thread
  update to throw an error.

  The thread is in a View, that also has it's own instance of the
  DBHelper and
  opens the database onCreate
  closes it onPause
  opens it onResume
  closes it onDestroy

  The instance in my Thread is throwing this but not all the time :error
  code 5: database is locked

  Is there a known practice I should implement so I don't get this error?



-- 
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


[android-developers] Re: error code 5: database is locked

2010-10-15 Thread DanH
Where is the error being thrown from?  (You might include the
exception traceback.)

On Oct 15, 9:44 am, gcstang gcst...@gmail.com wrote:
 Has anyone encountered this and is there a solution to work around it?

 I'm creating a Thread and in that thread I open a database connection
 using the DBHelper, perform an update on a field in my database and
 close it. I create a separate one in the Thread because if the View is
 closed the global one for that view is closed, causing my Thread
 update to throw an error.

 The thread is in a View, that also has it's own instance of the
 DBHelper and
 opens the database onCreate
 closes it onPause
 opens it onResume
 closes it onDestroy

 The instance in my Thread is throwing this but not all the time :error
 code 5: database is locked

 Is there a known practice I should implement so I don't get this error?

-- 
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


[android-developers] Re: Error Code 5: Database is locked

2009-10-14 Thread mathias axelsson
I use
synchronized(ExampleDbAdapter.class){mDb.insert/update/delete/query...} in
ExampleDbAdapter to avoid this. Let me know if there's a better way.

On Mon, Aug 24, 2009 at 10:58 AM, Armond Avanes armond...@yahoo.com wrote:


 So how can I create an in-memory database? I just took a quick look at the
 API and couldn't find any.

 Cheersss,
 Armond

  develop...@googlegroups.com] On Behalf Of Andrei
  Sent: Monday, August 24, 2009 7:35 AM
 
  If your write time take long i would try this
  I would create another in memory database, attach it to yours.
  In memory database table would have same schema.
  You would write to in memory database and after done do insert into
  db1.table as select * from db2.table
  I did something similar but on desktop not phone and of course you
  need to wait for lock to clear
 
  On Aug 23, 2:31 am, Armond Avanes armond...@yahoo.com wrote:
   I forgot to mention that this exception happens (so far) from the
  service I
   have for updating database (is executed every 24 hours).
  
   Cheersss,
   Armond
  
Hi Guys,
  
I have different background threads in my application, one doing
periodical
database updates, another responsible for doing long searches and so.
Obviously some are just reading from database while others are
 writing
  as
well.
  
Once in a while I get database is locked exception. I need to know
  the
safe way of reading/writing from/to database on different threads.
  
As well I've found isDbLockedByCurrentThread() and
isDbLockedByOtherThreads() methods on SQLiteDatabase. Should I use
  them
every time I want to access the database? What if the database is
  locked?
Should I pause the current thread and retry a few milliseconds later?
  
Best Regards,
Armond
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): Caused by:
android.database.sqlite.SQLiteException: error code 5: database is
  locked
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
android.database.sqlite.SQLiteStatement.native_execute(Native Method)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
   
  android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
   
  android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1534)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
com.test.db.TestDao.update (TestDao.java:327)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
com.test.UpdateService.onStart(UpdateService.java:35)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): at
   
 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2557)
  
08-23 10:17:32.029 E/AndroidRuntime( 1331): . 10 more
 

 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: Error Code 5: Database is locked

2009-08-24 Thread Armond Avanes

So how can I create an in-memory database? I just took a quick look at the
API and couldn't find any.

Cheersss,
Armond

 develop...@googlegroups.com] On Behalf Of Andrei
 Sent: Monday, August 24, 2009 7:35 AM
 
 If your write time take long i would try this
 I would create another in memory database, attach it to yours.
 In memory database table would have same schema.
 You would write to in memory database and after done do insert into
 db1.table as select * from db2.table
 I did something similar but on desktop not phone and of course you
 need to wait for lock to clear
 
 On Aug 23, 2:31 am, Armond Avanes armond...@yahoo.com wrote:
  I forgot to mention that this exception happens (so far) from the
 service I
  have for updating database (is executed every 24 hours).
 
  Cheersss,
  Armond
 
   Hi Guys,
 
   I have different background threads in my application, one doing
   periodical
   database updates, another responsible for doing long searches and so.
   Obviously some are just reading from database while others are writing
 as
   well.
 
   Once in a while I get database is locked exception. I need to know
 the
   safe way of reading/writing from/to database on different threads.
 
   As well I've found isDbLockedByCurrentThread() and
   isDbLockedByOtherThreads() methods on SQLiteDatabase. Should I use
 them
   every time I want to access the database? What if the database is
 locked?
   Should I pause the current thread and retry a few milliseconds later?
 
   Best Regards,
   Armond
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331): Caused by:
   android.database.sqlite.SQLiteException: error code 5: database is
 locked
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
   android.database.sqlite.SQLiteStatement.native_execute(Native Method)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  
 android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  
 android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1534)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
   com.test.db.TestDao.update (TestDao.java:327)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
   com.test.UpdateService.onStart(UpdateService.java:35)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
   android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2557)
 
   08-23 10:17:32.029 E/AndroidRuntime( 1331):     . 10 more
 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: Error Code 5: Database is locked

2009-08-23 Thread Armond Avanes

I forgot to mention that this exception happens (so far) from the service I
have for updating database (is executed every 24 hours).

Cheersss,
Armond

 Hi Guys,
 
 I have different background threads in my application, one doing
 periodical
 database updates, another responsible for doing long searches and so.
 Obviously some are just reading from database while others are writing as
 well.
 
 Once in a while I get database is locked exception. I need to know the
 safe way of reading/writing from/to database on different threads.
 
 As well I've found isDbLockedByCurrentThread() and
 isDbLockedByOtherThreads() methods on SQLiteDatabase. Should I use them
 every time I want to access the database? What if the database is locked?
 Should I pause the current thread and retry a few milliseconds later?
 
 Best Regards,
 Armond
 
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): Caused by:
 android.database.sqlite.SQLiteException: error code 5: database is locked
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 android.database.sqlite.SQLiteStatement.native_execute(Native Method)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1534)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 com.test.db.TestDao.update (TestDao.java:327)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 com.test.UpdateService.onStart(UpdateService.java:35)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): at
 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2557)
 
 08-23 10:17:32.029 E/AndroidRuntime( 1331): . 10 more
 
 
 

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[android-developers] Re: Error Code 5: Database is locked

2009-08-23 Thread Andrei

If your write time take long i would try this
I would create another in memory database, attach it to yours.
In memory database table would have same schema.
You would write to in memory database and after done do insert into
db1.table as select * from db2.table
I did something similar but on desktop not phone and of course you
need to wait for lock to clear

On Aug 23, 2:31 am, Armond Avanes armond...@yahoo.com wrote:
 I forgot to mention that this exception happens (so far) from the service I
 have for updating database (is executed every 24 hours).

 Cheersss,
 Armond

  Hi Guys,

  I have different background threads in my application, one doing
  periodical
  database updates, another responsible for doing long searches and so.
  Obviously some are just reading from database while others are writing as
  well.

  Once in a while I get database is locked exception. I need to know the
  safe way of reading/writing from/to database on different threads.

  As well I've found isDbLockedByCurrentThread() and
  isDbLockedByOtherThreads() methods on SQLiteDatabase. Should I use them
  every time I want to access the database? What if the database is locked?
  Should I pause the current thread and retry a few milliseconds later?

  Best Regards,
  Armond

  08-23 10:17:32.029 E/AndroidRuntime( 1331): Caused by:
  android.database.sqlite.SQLiteException: error code 5: database is locked

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  android.database.sqlite.SQLiteStatement.native_execute(Native Method)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1534)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  com.test.db.TestDao.update (TestDao.java:327)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  com.test.UpdateService.onStart(UpdateService.java:35)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     at
  android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2557)

  08-23 10:17:32.029 E/AndroidRuntime( 1331):     . 10 more
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---