[SQLObject] Re: Problem with new database entry
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Ahmed M. A. <ahm...@wa...> - 2004-06-23 08:44:35
|
Hi,
I think that your problem is caused by the next line:
doz=Dozenten(table)
why do you pass the the table argument ? This will lead to the call
self._trans = table
in Table__init__ and will overwrite your Transaction instance with a
Table instance.
Instead use:
doz=Dozenten()
I hope that will work.
Ahmed MOHAMED ALI
"Akki Nitsch" <ak...@ak...> wrote in message
news:Pin...@li......
> Hi everybody!
>
> I've got a problem with creating new database entries when i'm using
> transactions.
>
> Here's my code:
>
> import SQLObject
>
> class DeputatsDB:
> def __init__(self):
> """Initiate a database connection"""
> self._conn = SQLObject.PostgresConnection('user=akki
> dbname=deputat')
>
> def newTransaction(self):
> """Open a new transaction"""
> return self._conn.transaction()
>
> def getDozenten(self, trans):
> """Return an item from table Dozent"""
> return Dozenten(trans)
>
> class Table:
> def __init__(self, trans):
> """Initiate a transaction"""
> self._trans = trans
>
> class Dozent(SQLObject.SQLObject):
> """Class dozent properties of dozent"""
> dozent_uid = SQLObject.StringCol()
> vorname = SQLObject.StringCol()
> name = SQLObject.StringCol()
> kuerzel = SQLObject.StringCol(length=5, default = None)
> anrede = SQLObject.StringCol()
>
> class Dozenten(Table):
> """Class for manipulation of dozenten"""
> def addDozent(self, uid, vorname, name, kuerzel, anrede):
> """Add a new dozent to database"""
> return Dozent.new(connection=self._trans,
> dozent_uid=uid,
> name=name, vorname=vorname,
> kuerzel=kuerzel, anrede=anrede)
>
>
> After creation of instances of DeputatsDB, DeputatsDB.Transaction and
> Table i'm trying to add a new Dozent to the Database:
>
> from deputatsabrechnung import *
>
> debDB = DeputatsDB()
> trans = debDB.newTransaction()
> table = Table(trans)
> doz=Dozenten(table)
>
> doz.addDozent('324534645zgfb', 'James', 'Bond', 'bon', 'Mister')
>
> Now i'm getting this error message:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File
>
"/zope/mniportal/Products/MNIVeranstaltungen/deputatsabrechnung/deputatsabre
chnung.py",
> line 30, in addDozent
> kuerzel=kuerzel, anrede=anrede)
> File "/usr/local/lib/python2.3/site-packages/SQLObject/SQLObject.py",
> line 907, in new
> inst._SO_finishCreate(id, connection=connection)
> File "/usr/local/lib/python2.3/site-packages/SQLObject/SQLObject.py",
> line 928, in _SO_finishCreate
> id = connection.queryInsertID(self._table, self._idName,
> AttributeError: Table instance has no attribute 'queryInsertID'
>
>
> Well, after searching the mail list i haven't found any hint what courses
> this error and i haven't any idea what my fault is.
>
> Can anybody help me?
>
> Thank you very much!
>
> Akki Nitsch
>
> #############################################################
> The freedom of meaning one thing and saying
> something different is not permitted.
> E.W. Dijkstra
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
|