Geek stuff - SQL Server support in web.py
web.py is a python web framework. It makes developing database-driven web applications pretty easy and straightforward. I've been experimenting with these lately in an effort to broaden my horizons beyond the worlds of perl and php.
I ran into a bit of trouble with it, though. Out of the box, it does not support sql server. Normally this would not be a problem, but here at the office, we use sql server exclusively. So I set about trying to figure out how to add support. There are a few forum and newsgroup postings dealing with it, but none give actual instructions, so I thought I'd post some here.
The first step is to install the pymssql module. This adds sql server support to python.
Next, you need to edit <PYTHON_HOME>/Lib/site-packages/web/db.py:
-
elif dbn == "firebird":
-
import kinterbasdb as db
-
if 'pw' in keywords:
-
keywords['passwd'] = keywords['pw']
-
del keywords['pw']
-
keywords['database'] = keywords['db']
-
del keywords['db']
-
-
else:
-
raise UnknownDB, dbn
-
elif dbn == "firebird":
-
import kinterbasdb as db
-
if 'pw' in keywords:
-
keywords['passwd'] = keywords['pw']
-
del keywords['pw']
-
keywords['database'] = keywords['db']
-
del keywords['db']
-
-
# mssql support?
-
-
elif dbn == "mssql":
-
import pymssql as db
-
if 'pw' in keywords:
-
keywords['password'] = keywords['pw']
-
del keywords['pw']
-
keywords['database'] = keywords['db']
-
del keywords['db']
-
-
else:
-
raise UnknownDB, dbn
You can then call web.config.db_parameters = dict(); as usual. The config parameter names are the same. Don't forget to specify mssql as the dbn.
That's all there is to it. It's pretty self-explanatory, but I didn't see anything anywhere that explained exactly what to change to make it work.