[PATCHv2] Re: LocalStatusSQLite: Fix bug when deleting messages

Nicolas Sebrecht nicolas.s-dev at laposte.net
Sun May 8 12:47:50 BST 2011


On Sat, May 07, 2011 at 08:28:17PM +0200, Sebastian Spaeth wrote:
> 
> The syntax was not right, and deleting messages from the LocalStatus
> failed. (We passed in the full list of uids and we need to pass in one
> uid at a time (as a tuple). Deleting messages works now.
> 
> Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
> ---
> DAMMIT, Sorry I did not include all changes in v1. Here it is again with
> the correct version. Ignore v1 from a few minutes ago. I am now going to
> take a brief offlineimap break or I am going crazy :)
> 
>  offlineimap/folder/LocalStatusSQLite.py |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/offlineimap/folder/LocalStatusSQLite.py b/offlineimap/folder/LocalStatusSQLite.py
> index 63452f8..f470599 100644
> --- a/offlineimap/folder/LocalStatusSQLite.py
> +++ b/offlineimap/folder/LocalStatusSQLite.py
> @@ -238,5 +238,5 @@ class LocalStatusSQLiteFolder(LocalStatusFolder):
>              return
>          for uid in uidlist:
>              del(self.messagelist[uid])
> -            self.sql_write('DELETE FROM status WHERE id=?',
> -                             uidlist)
> +            #TODO: we want a way to do executemany(.., uidlist) to delete all

Got back to message

  Subject: Re: [PATCH 5/7] Re: Don't keep sqlite connections open
  From: Sebastian Spaeth <Sebastian at SSpaeth.de>
  Date: Fri, 06 May 2011 08:59:11 +0200
  To: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
  Message-ID: <87aaf02u2o.fsf at SSpaeth.de>

I think you'll understand why I was talking about

  "statements including additional code to execute: pass both the
  request and a function to the wrapper"

We are asking the wrapper sql_write() to execute one write per call. It
has the reponsability to handle locks, commit(), etc. What we miss is
something to acquire the lock, treat many writes and commit() when all
done.

I'm definetly not a python expert but I guess that optionnaly passing a
function to this wrapper could help us:

  def sql_write(self, sql, vars=None, manywrite=None):
      #
      # prepare write, acquire locks, etc
      #

      if manywrite == None:
        # easy case, execute given sql

      else:
        # run the manywrite() given function
        manywrite(sql, vars=None)

      #
      # close the write process running commit(), etc
      #

So, we should be able to define the manywrite() content from the caller
level while still letting the SQL wrapper do the SQL related work like
managing locks, commit(), etc.

> +            self.sql_write('DELETE FROM status WHERE id=?', (uid, ))

-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list