[Twisted-Python] newbie adbapi question

Martin Waite martin at datacash.com
Tue Mar 11 04:36:56 EST 2003


I'm making some progress on my application, but there are
a few ugly looking things in here and I wonder if I'm doing 
them right:

1) one theme (I would have said thread, but I'm not using 
   threads) of execution requires that 3 database queries
   are executed one after the other.  My current solution 
   involves chaining calls to adbapi.operation() and 
   adbapi.query() together.  My first query updates a table
   and so calls adbapi.operation().  In the callback to this,
   I make a call to adbapi.query().  In the callback to this, 
   I make another call to adbapi.operation().  My final callback
   reschedules the original call with the reactor - effectively
   making this sequence of operations repeat indefinitely.

   This seems to work, but is making my code look a bit like 
   a state machine.  This could get hairy.  Instead, should I be 
   adding all my callbacks at one time to the same Deferred ?

2) I'm using MySQL as the database.  Normally, following an update,
   I would fetch the result code. adbapi._run_operation() seems to 
   throw it away however, so all I ever get is None.  I would prefer
   to get the MySQL result, which tells me how many rows I updated.
   This lets me decide whether to run other queries.

   The suspicious code in _run_operation (v1.0.2):

            apply(curs.execute, args, kw)
            result = None

   To me, this doesn't look interested in the result code from the   
   database. I'm used to using the Perl DBI - that distinguishes 
   between queries returning rows (select) and those
   returning result codes (delete, update).  Am I mistaken mapping
   these onto adbapi.query() and adbapi.operation() ?



More information about the Twisted-Python mailing list