[Twisted-Python] Twisted Enterprise (newbie question)

Steve Waterbury steve.waterbury at gsfc.nasa.gov
Wed May 22 11:38:31 MDT 2002


Twisted Gurus,

I'm just starting to experiment with Twisted, and am trying out the 
example in the "Introduction to Twisted Enterprise", slightly modified: 
I have a PostgreSQL database called "test", which has a table called 
"schema", which has columns called "schema_name" and "identification" 
(among others), and the value of schema_name in one row is "pgpdm_schema").  
My script is:
------------------------------------------------------------------------
from twisted.enterprise import adbapi
import sys
class TestDatabase(adbapi.Augmentation):
    def getSchemaByName(self,schemaname):
        sql = """SELECT identification from schema WHERE schema_name = %s"""
        return self.runOperation(sql,schemaname)

def gotSchemaByName(resultlist):
    ident = resultlist[0][0]
    print resultlist
    print "Schema has identifier %s." % ident

# dbpool = adbapi.ConnectionPool("psycopg","test","waterbug","")
dbpool = adbapi.ConnectionPool("pyPgSQL.PgSQL","test","waterbug","")
db = TestDatabase(dbpool)
db.getSchemaByName("pgpdm_schema").addCallbacks(gotSchemaByName, db.operationError).arm()
------------------------------------------------------------------------

I've tested the sql using both psycopg and pyPgSQL in interactive 
sessions, so I know this query should produce an output of 

[['PGPDM-1.0']]

I've tried it with both pyPgSQL and psycopg ... in both cases, the 
output is:
--------------------------------------------------------------------------
[waterbug at beeblebrox twisted]$ python db_test.py 
Enabling Multithreading.
Connecting to database: pyPgSQL.PgSQL ('test', 'waterbug', '') {}
--------------------------------------------------------------------------

Shouldn't the print statements be producing output on stdout?  
(I'm new to callbacks, so I'm sure I've missed something ...)  

TIA!
-- Steve.

Stephen C. Waterbury  http://misspiggy.gsfc.nasa.gov/people/waterbug.html
    "An idiot with a computer is a faster, better idiot." - Rick Julius




More information about the Twisted-Python mailing list