Re: [SQLObject] How to disconnect from one database and connect to different database?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2008-10-28 18:41:00
|
On Tue, Oct 28, 2008 at 06:33:01PM +0000, Matthew Wilson wrote: > I have a special case where I need to disconnect from one database, then > connect to another database. After I connect to the second database, I > want to import a different set of SQLObject classes that represent that > database. > > Finally, I want to close that connection to database #2, and then go > back to database #1, and reload all the classes for that one. You don't need to disconnect - you can open as many connections as you need. I have a program, e.g., that connects to PostgreSQL and SQLite and copies data between them. Just open connections: connection1 = connectionForURI('postgres://host:port/db') connection2 = connectionForURI('sqlite:///path/to/db') and use them: class MyTable(SQLObject): name = StringCol() Get a row from the first DB: row1 = MyTable.get(id, connection=connection1) and insert the data into the second: row2 = MyTable(**row.asDict(), connection=connection2) Most methods in SQLObject accept connection parameter. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |