From: Hugo v. d. M. <hu...@ds...> - 2005-07-04 09:02:24
|
Bryan Murdock 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 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. > > That sounds a bit problematic. In general, if you make a change to a database, it is already saved. As such it seems File->Open and File->New will have to do more or less the same thing, "open" a file, existing or not. File->Save As will probably then want to copy the file in question to the new filename, then open the newly created file (that should be easier than loading all the data from one file and saving it to another). I would "open" a file with a connectionForURI call, then assume it is automatically saved after every transaction. To open a new file, just use another connectionForURI call, and always pass the connection created in this way as the "connection" parameter to all SQLObject methods. (I've had some trouble when I try to use and change the connections in the tables directly, using _connection or the module-wide __connection__, so I prefer just passing it as a parameter, *always*.) Take my advice with a pinch of salt, and wait for some answers from some guru's too, since I'm also a newbie at this. I just try to help where I can. (Thus, anyone, please correct me if I'm talking some nonsense.) Hugo |