[Twisted-Python] psycopg2 and dictcursor

Jonathan Vanasco twisted-python at 2xlp.com
Mon Apr 24 19:30:33 EDT 2006

On Apr 24, 2006, at 5:58 PM, Federico Di Gregorio wrote:
> I really don't know. It works perfectly here. Maybe show us our  
> code and
> how the pool is called.

good idea.  i'm kind of stressed out today - not thinking very  
clearly.  i'm probably dealing with a typo that i'm just not seeing.

i was using this w/twisted words, but i just copied the lines to  
replicate into the stub basic reactor .

from psycopg2 import *
from psycopg2 import _psycopg as _2psycopg
from psycopg2.extensions import connection as _2connection
from psycopg2.extras import DictCursor

del connect
def connect(*args, **kwargs):
     kwargs['connection_factory'] = connection
     return _2psycopg.connect(*args, **kwargs)

class connection(_2connection):
     def cursor(self):
         return _2connection.cursor(self, cursor_factory=DictCursor)
import twistedpg
from twisted.enterprise import adbapi

connection_pool = adbapi.ConnectionPool("twistedpg",  
host="localhost",database="aaaa",user="aaaa",password="" )

from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor

class tester(Protocol):
     def connectionMade(self):

class SQLfactory(Factory):
     protocol = tester
     def __init__(self, quote=None):
         self.quote = self.db_sample__query().addCallback 
     def db_sample__query( self ):
         data = connection_pool.runQuery("SELECT * FROM useraccount",)
         return data
     def print_result( self , data ):
         print data

reactor.listenTCP(8007, SQLfactory("configurable quote"))

More information about the Twisted-Python mailing list