From: Kevin D. <da...@gm...> - 2005-07-04 14:19:58
|
On 7/4/05, Bryan Murdock <bmu...@gm...> wrote: > I'm trying to get the hang of SQLObject for a little desktop app I'm > writing that will use sqlite for data storage. SQLObject seems very > nice. I'm having trouble with connections though, in particular > trying to get the normal desktop file->open, file->new, file->save as > type functionality going. Is there a way to delay setting up the > connection when importing my module of SQLObject classes until we get > some user imput on a filename? Is there a way to close a connection > to one database (i.e. an sqlite file) and open a connection to > another? I'd really recommend going with the SVN trunk of SQLObject at this point. For one, if you do so you can use pysqlite2, which seems much better than the earlier version. Additionally, you can get the ConnectionHub. ConnectionHub uses a descriptor to set the connection, which means that you don't have to pass the connection into methods manually and you don't have to have it open at the very beginning. As Hugo points out, doing "Save As" type of functionality with an actual database may be awkward, but that really depends on your application. > I see the makeConnection and releaseConnection methods in > dbconnection.py, but I guess I'm too new at all this to be able to > read the source and see how to use them exactly. The unfortunate thing about my suggestion to use the SVN trunk of SQLObject is that you'll need to read some of the source. It's fairly clear if you know python. dbconnection.py in the trunk has the ConnectionHub class, and a hub is set up for you from the get-go. Ian Bicking has posted some documentation on his blog that covers some of the changes that have occurred since 0.6. Besides the ConnectionHub, you'll need to be aware of the new sqlmeta class... sqlmeta is a good thing. It cleans up your classes quite a bit. Here is a useful links: http://blog.ianbicking.org/another-plan-sqlobject-07.html I'll note that you can do what ConnectionHub is doing without the svn trunk version of SQLObject. I was using a descriptor myself early on. You can't use pysqlite2 with the currentl SQLObject release, however. Kevin |