From: <wzi...@co...> - 2009-03-03 17:55:44
|
Hello, ... has anyone gotten SQLObject to work with Sybase? I can query the database but I can't insert. Any advice would be appreciated. The table already exists and is extremely simple, with just two columns, a key and a text string. Here's the class for the table: ========================================== from sqlobject import * class titles( SQLObject ): title_id = IntCol() title = StringCol() class sqlmeta: print 'class sqlmeta' idName = 'title_id' lazyUpdate = False autoCommit = True ========================================== And here's a separate class where I attempt to insert: ========================================== from sqlobject import * import titles class InsertNewTitle: def __init__( self, newKey, newTitle ): sybURI = "sybase://my_user_id:my_password@DBSERVER//library_info" konnection = connectionForURI( sybURI ) sqlhub.processConnection = konnection book_a = titles.titles(title_id=0, title='zero') book_a._connection.debug = True book_a._connection.autoCommit = True book_b = titles.titles(title_id=newKey, title=newTitle) book_b._connection.debug = True book_b._connection.autoCommit = True book_b.id = newKey book_b.set(title_id=newKey, title = newTitle) book_b.syncUpdate() print 'for ID %d the title is %s' % ( book_b.title_id, book_b.title ) return None if __name__ == "__main__": instantiatedObject = InsertNewTitle(506,"Spy Story") ========================================== This code actually appears to work with no errors, but I can run it many times with no duplicate rows because nothing gets inserted into the database. I tried wrapping it all in a transaction and doing a commit, but that didn't help. It's not a permission problem because I've used the same ID and password in an SQL tool and I can insert. Note I instantiate two books. I don't want to, but I'm forced to because if I try to give it a non-zero first key I get the error: "sqlobject.main.SQLObjectNotFound: The object titles by the ID 0 does not exist" ....even though I'm providing a non-zero key! So I have 2 questions, if anyone would be kind enough to help: why does it complain about 0 not existing when I create only one book using a non-zero key (but doesn't complain as long as I use the 2 book work-around shown) and why does nothing get written to the database, even when I put in a commit? Thanks in advance for any help. .....WZ |