On Tue, Aug 24, 2010 at 08:38:03AM -0400, Chad Rebuck scratched on the wall:
> After changing my script to make use of querysingle instead of the
> query/fetchArray loop I was still seeing database locked notices.  My
> scripts would end unexpectedly if the database lock occured at the right
> moment.  Finally found the root cause of the trouble was due to not defining
> a busyTimeout().

  A busy handler will help reduce the number of SQLITE_BUSY errors, but
  it will not eliminate them all together.  Your code must still be
  able to deal with SQLITE_BUSY errors, even if a handler is set.

  From <http://www.sqlite.org/c3ref/busy_handler.html>:

      The presence of a busy handler does not guarantee that it will be
      invoked when there is lock contention. If SQLite determines that
      invoking the busy handler could result in a deadlock, it will go
      ahead and return SQLITE_BUSY or SQLITE_IOERR_BLOCKED instead of
      invoking the busy handler. Consider a scenario where one process
      is holding a read lock that it is trying to promote to a reserved
      lock and a second process is holding a reserved lock that it is
      trying to promote to an exclusive lock. The first process cannot
      proceed because it is blocked by the second and the second
      process cannot proceed because it is blocked by the first. If
      both processes invoke the busy handlers, neither will make any
      progress. Therefore, SQLite returns SQLITE_BUSY for the first
      process, hoping that this will induce the first process to
      release its read lock and allow the second process to proceed.

  Basically, if you have a handler set or not, if you get an
  SQLITE_BUSY error, your application must back off and rollback
  whatever it is working on.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to