|
francois lepoutre
francoislepoutre at compuserve.com
Wed May 14 08:14:39 EST 2003
Hi
> So... the script that is referenced in my handler..... if it has an
> _init_ section, will that do the trick ?? and it'll only get run once,
> when the interpreter calls the handler for the first time ???
No _init_ section or objectified kind of code required.
Some plain python stuff will do :)
An example... not tested here. Hope you pick the idea
You just need to dive in now .. Good luck.
François
############################
#! C:\Python22\python.exe
# mod_python handling
from mod_python import apache,util
# database connectivity
from mx import DateTime,ODBC
# your database connectivity here
# this is mxODBC/ODBC code
# will depend on your midlle ware...
# this code will run rarely..
# a couple of 1/n of seconds upon setup
database_handle = ODBC.iODBC.Connect("my_connectionion","dba","sql",0)
cursor_handle = database_handle.cursor()
cursor_handle.execute("select * from customers")
my_shared_data = cursor_handle.fetchall()
cursor_handle.close()
################################
def handler(req):
# should be long the first time
# very fast the next one...
req.content_type = "text/plain"
req.send_http_header()
req.write(str(my_shared_data))
return apache.OK
|