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:

PYTHON:
  1. elif dbn == "firebird":
  2.         import kinterbasdb as db
  3.         if 'pw' in keywords:
  4.             keywords['passwd'] = keywords['pw']
  5.             del keywords['pw']
  6.         keywords['database'] = keywords['db']
  7.         del keywords['db']
  8.  
  9.     else:
  10.         raise UnknownDB, dbn

PYTHON:
  1. elif dbn == "firebird":
  2.         import kinterbasdb as db
  3.         if 'pw' in keywords:
  4.             keywords['passwd'] = keywords['pw']
  5.             del keywords['pw']
  6.         keywords['database'] = keywords['db']
  7.         del keywords['db']
  8.    
  9.     # mssql support?
  10.  
  11.     elif dbn == "mssql":
  12.         import pymssql as db
  13.         if 'pw' in keywords:
  14.             keywords['password'] = keywords['pw']
  15.             del keywords['pw']
  16.         keywords['database'] = keywords['db']
  17.         del keywords['db']
  18.  
  19.     else:
  20.         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.

Leave a comment



XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
The URI you submitted has disallowed characters.