[Twisted-Python] Again about query mapped

Dave Peticolas dave at krondo.com
Tue Jun 15 17:42:36 EDT 2004

I don't know enough about db_row to know whether that code is right,
but the adbapi code looks correct.


---- Original Message ----
From:		Mauro Colorio
Date:		Tue 6/15/04 1:35
To:		Twisted discussion stuff
Subject:	Re: [Twisted-Python] Again about query mapped

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)

Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list