Cheers Aaron,
Your excellent explanation makes it all clear now :)
Thanks
Adam
--- Aaron Held <[EMAIL PROTECTED]> wrote: > Your
AOLServer example is the way to go.
>
> I think the confusion is that you use dbPool like a
> Python module, not a
> Webware specific thing.
> In Python Modules are executed and loaded once, no
> matter how many times
> they are imported. Due to this simple fact you can
> create a class or
> varriable in a module and that class will exist
> once, regardless of how
> many times its called.
>
> So you should create dbPool in a seperate module.
> 1) create a module called configuration.py that
> contains:
> from MiscUtils.DBPool import DBPool
> from pyPgSQL import PgSQL
>
> # set up the database connection pool
> datapool = DBPool(PgSQL, 5,
> 'localhost::databasename:user:pass')
> #The actual syntax of
> 'localhost::databasename:user:pass' will depend
> upon your database connector
>
> 2) When you want to use a connection:
> from configuration import datapool
> class selCity(SecurePage):
>
> def writeHTML(self):
> conn = datapool.getConnection()
> c = conn.cursor()
> c.execute('select "CalledCity" from
> "UniqueCalledCities"')
> rsCity = c.fetchall()
> c.execute('select "CalledState" from
> "UniqueCalledStates"')
> rsState = c.fetchall()
> c.close()
> conn.close()
> .....
>
> A better way would be to put all of the database
> work into another
> module and call that from a servlet.
>
> CSData.py:
> from configuration import datapool,clientpool
>
> def summaryStats(user):
> summary={}
> conn=datapool.getConnection()
> c=conn.cursor()
> c.execute("Select numrows from numrows")
> r=c.fetchone()
> summary['numrows'] = r.numrows
> c.close()
> return summary
>
>
> and in your servlet:
>
> import CSData
>
> class servlet....:
>
> def writeContent(self):
> dataStats=CSData.summaryStats(user)
> self..writeln("Summary: %s" %
> dataStats)
>
>
> You should be able to get dbPool working outside of
> webware.
>
> Write a simple test module that pulls some data out
> using dbPool and get
> that running furst. You may need to add the webware
> directory to your
> pythonpath first
> -Aaron
__________________________________________________
Yahoo! Plus - For a better Internet experience
http://uk.promotions.yahoo.com/yplus/yoffer.html
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss