[Twisted-Python] Again about query mapped

Mauro Colorio linuxbox at interfree.it
Tue Jun 15 04:22:33 EDT 2004

Il mar, 2004-06-15 alle 01:14, Dave Peticolas ha scritto:
> You can use runInteraction to get at the cursor directly
> (see the example I just posted for another message). The
> cursor is wrapped by the transaction object passed as the
> first argument to the interaction callback.

this is what I produced, subclassing connectionpool,
I hope it's right (well it works :) but I'm new at twisted so I don't
know if it just works or it does it in the right way), the
db_row module is linked in my past mail, comments?:


from twisted.enterprise import adbapi 
from db_row import *

class my_ConnectionPool(adbapi.ConnectionPool):
    "Modified connectionPool"

    def mappedInteraction(self, transaction, sql_string):
        "Returns the result of a query in a more useful way"

        # Make a class to store the resulting rows
        R = IMetaRow(transaction.description)

        # Build the rows from the row class and each tuple returned from
the cursor
        results = [ R(row) for row in transaction.fetchall() ]
        return results

    def runMappedQuery(self, sql_string):
        "Runs the query"
        return self.runInteraction(self.mappedInteraction,sql_string)

More information about the Twisted-Python mailing list