Quoting MichaelG <[EMAIL PROTECTED]>:



Oleg,

Being dense, and having fought with this a while now, can you provide a
very brief example of \\\"pass a connection object to an every method\\\" in
this case Ray presents of two databases?  I am sure there is a very
clean pythonic way to handle this, and I am just missing it.

- Michael


Hi Michael,

(I\\\'ll do my best to answer)

Each SQLObject method has a \\\"connection\\\" parameter.
If not specified the connection set as \\\"sqlhub.processConnection\\\" is used.

See attched example.

Regards,

Ray Smith
http://RaymondSmith.com



from sqlobject import *
import os

# define a table
class Test(SQLObject):
   desc=StringCol()

# open 2 connections to 2 databases
if os.path.exists('c:\\test1.db'):
   os.unlink('c:\\test1.db')
con1=connectionForURI('sqlite:/c|/test1.db')

if os.path.exists('c:\\test2.db'):
   os.unlink('c:\\test2.db')
con2=connectionForURI('sqlite:/c|/test2.db')

# execute methods passing our connection objects
# add record to first database
Test.createTable(connection=con1)
Test(desc='Hello', connection=con1)

# add record to second database
Test.createTable(connection=con2)
Test(desc='There', connection=con2)

# close
con1.close()
con2.close()
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to