[Twisted-Python] DBReflector.loadObjectFrom question

Sean Riley sean at twistedmatrix.com
Thu Sep 19 12:25:32 MDT 2002


there have been changes to improve the Row interface recently. Here is your
code modified to use the new interface:

from twisted.enterprise import adbapi, row, dbreflector
from twisted.internet import app

class AcctRow( row.RowObject ):
    rowColumns = [
        'id',
        't_id',
        'name',
        'label'
        ]
    rowKeyColumns = [( 'id', 'int4' )]
    rowTableName = "acct"

    def __repr__( self ):
        return 'Acct: <%d %s>' % ( self.id, self.name )


def gotData( data ):
    print "got Data:", data

def refInit( result ):
    print 'refInit', result
    reflector.loadObjectsFrom( 'acct' ).addCallback( gotData)

dbpool = adbapi.ConnectionPool("pyPgSQL.PgSQL", database="sean",
host="localhost", port=5432)
reflector = dbreflector.SQLReflector( dbpool,[ AcctRow], refInit)

application = app.Application('rowTest')
application.run(save=0)

BTW, loadObjects must be run _after_ the reflector has been initialized
(after refInit) has been invoked because the initialization may be
asynchronous.

here is the above code running:

$ python e.py
Connecting to database: pyPgSQL.PgSQL () {'host': 'localhost'}
Enabling Multithreading.
starting waker
adbapi connecting: pyPgSQL.PgSQL {'host': 'localhost', 'port': 5432,
'database': 'sean'}
refInit None
got Data: [Acct: <1 afd>, Acct: <2 afd>, Acct: <3 afd>, Acct: <4 afd>, Acct:
<5 afd>]


-----Original Message-----
From: twisted-python-admin at twistedmatrix.com
[mailto:twisted-python-admin at twistedmatrix.com]On Behalf Of
carball at hush.com
Sent: Wednesday, September 18, 2002 10:44 PM
To: twisted-python at twistedmatrix.com
Subject: [Twisted-Python] DBReflector.loadObjectFrom question



greetings,

using loadObjectsFrom, it seems the RowClass i am passing in
should have dbColumns with data in it in order to build a
correct sql query. .

where does said data come from?
my dbColumns is just an empty list

also, i dont understand why i have to tell an instantiated
DBReflector what tablename, keys, and RowClass to use again in
loadObjectsFrom?

i apologize if i'm missing something obvious
i've read 'some' T.enterprise code, not enough to
understand it all. .

thanks in advance,
cary

--------------code-----------------------------
#!/usr/bin/env python
from twisted.enterprise import adbapi, row
from twisted.internet import app

class AcctRow( row.RowObject ):
rowColumns = [
'id',
't_id',
'name',
'label'
]
dbKeyColumns = [( 'id', 'int4' )]
def __repr__( self ):
return '%d %s' % ( self.id, self.name )

def refInit( result ):
print 'refInit', result

dbpool = adbapi.ConnectionPool( 'pyPgSQL.PgSQL' )
reflector = row.DBReflector( dbpool,
[( AcctRow,
'acct',
AcctRow.dbKeyColumns )],
refInit )

reflector.loadObjectsFrom( 'acct',
AcctRow.dbKeyColumns,
None,
AcctRow )

application = app.Application('rowTest')
application.run(save=0)

---------------------------
this fails in DBReflector._objectLoader, dbColumns is []??????
i'm using twisted 0.99.0

-----------output------------------
car at platypus car $ ./rowTest.py
Installing SelectReactor, since unspecified.
Connecting to database: pyPgSQL.PgSQL ('',) {}
Enabling Multithreading.
adbapi connecting: pyPgSQL.PgSQL ('',)
Exception in SQL interaction! rolling back...
Traceback (most recent call last):
File '/usr/lib/python2.2/site-packages/twisted/enterprise/adbapi.py', line
154
, in _runInteraction
result = apply(interaction, (trans,)+args, kw)
File '/usr/lib/python2.2/site-packages/twisted/enterprise/row.py', line 245,
i
n _objectLoader
transaction.execute(sql)
File '/usr/lib/python2.2/site-packages/pyPgSQL/PgSQL.py', line 2393, in
execut
e
adbapi connecting: pyPgSQL.PgSQL ('',)
raise OperationalError, msg
libpq.OperationalError: ERROR: parser: parse error at or near 'FROM'

Traceback (most recent call last):
File '/usr/lib/python2.2/site-packages/twisted/internet/threads.py', line
33,
in _putResultInDeferred
result = apply(f, args, kwargs)
File '/usr/lib/python2.2/site-packages/twisted/enterprise/adbapi.py', line
154
, in _runInteraction
result = apply(interaction, (trans,)+args, kw)
File '/usr/lib/python2.2/site-packages/twisted/enterprise/row.py', line 245,
i
n _objectLoader
transaction.execute(sql)
File '/usr/lib/python2.2/site-packages/pyPgSQL/PgSQL.py', line 2393, in
execut
e
raise OperationalError, msg
libpq.OperationalError: ERROR: parser: parse error at or near 'FROM'

refInit None
Main loop terminated.





Get your free encrypted email at https://www.hushmail.com

_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python





More information about the Twisted-Python mailing list