Re: [SQLObject] cannot insert with Sybase
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <wzi...@co...> - 2009-03-04 10:31:34
|
Hello Oleg and others, Thanks sincerely for the help; I'm much further along because now rows are inserted successfully. However, I still get an odd error message referring to key 0 when I do a simple print to show the values in the object. BTW, I will do my best to preserve indenting but my web-based email service is determined to ruin the code. better class 1: =========================================================== from sqlobject import * class titles( SQLObject ): title_id = IntCol() title = StringCol() class sqlmeta: print 'class sqlmeta' idName = 'title_id' lazyUpdate = False =========================================================== better class 2: =========================================================== from sqlobject import * import titles class InsertNewTitle: def makeNewBook( self ): sybURI = "sybase://my_user_id:my_password@DBSERVER//library_info" konnection = connectionForURI( sybURI ) konnection.debug = True konnection.autoCommit = True sqlhub.processConnection = konnection newKey = 1234 newTitle = "Mystery Book" book_b = titles.titles(title_id=newKey, title=newTitle) # works! # book_b.id = newKey # book_b.set(title_id=newKey, title = newTitle) # book_b.syncUpdate() # book_b = titles.get(newKey) print 'for ID %d the title is %s' % ( book_b.title_id, book_b.title ) # fails return None if __name__ == "__main__": instantiatedObject = InsertNewTitle() instantiatedObject.makeNewBook() =========================================================== and the error and the messages I cannot prevent are: =========================================================== class sqlmeta QueryIns: INSERT INTO titles (title_id, title) VALUES (1234, 'Mystery Book') 1/QueryOne: SELECT title_id, title FROM titles WHERE ((titles.title_id) = (0)) 1/QueryR : SELECT title_id, title FROM titles WHERE ((titles.title_id) = (0)) Traceback (most recent call last): File "/diska/data/workspace/PyXtern/src/tmpTry/InsertNewTitle.py", line 30, in <module> instantiatedObject.makeNewBook() File "/diska/data/workspace/PyXtern/src/tmpTry/InsertNewTitle.py", line 18, in makeNewBook book_b = titles.titles(title_id=newKey, title=newTitle) File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1203, in __init__ File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1251, in _create File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 1278, in _SO_finishCreate File "/diska/data/workspace/PyXtern/Bibliothek/eggs/SQLObject-0.10.4-py2.5.egg/sqlobject/main.py", line 931, in _init sqlobject.main.SQLObjectNotFound: The object titles by the ID 0 does not exist =========================================================== Note the commented code showing ways I have tried to persuade the object to think about my new key, but clearly it remains focused on key 0 which does not exist in the database, so the commented lines did not help. What might be the appropriate remedy for this error? Again thank you for the timely help, .....WZ |