Home > Uncategorized > More Django on SQL Server 2000

More Django on SQL Server 2000

January 15th, 2009

Today was a good day.

I managed to hammer in the last couple pieces into jTDS backend driver for SQL Server 2000 so that Django passes all but the lone test for forward reference test in modeltests.serializers.

SQL Server 2000 can’t seem to do deferrable constraints which is problematic but well – it’s not the end of the world.  Other than that - all tests are passing for Django on Jython for SQL Server 2000.

The lack of deferrable constraint checking in SQL Server is just bizarre though.  It seems like a fairly arbitrary omission of SQL92.  Strange.

Woot!

I’m going to start packaging up the changes I’ve made and stick it up into a public repository now.  Anybody have preferences on where they like this stuff?

Here’s a quick rundown of what to expect:

  • patches are going to be against only stable versions of Django.  I just don’t have the time to track trunk.
  • Jython 2.5b0 is what I’m currently using to run test.  2.5b1 won’t work, but later versions of Jython are expected to be ok
  • I’ve added full blown connection pooling to this backend via the Apache Commons.
  • Regular expression matching works properly and is passing all the tests.   VBScript’s regexp is powering the matching routines.
  • LIMIT/OFFSET is emulated properly using a mix of stored procedures, temp tables, cursor introspection and other awful trickery.  It’s not exactly “highly performant”, but you really can’t use Django’s ORM without slice support on the Queryset iterator.
  • Foreign keys won’t bung up Django’s client side CASCADE DELETE operations anymore.  The backend will automatically code generate database triggers to clean up foreign key relationships so SQL Server doesn’t bark at you.
  • SQL Server’s nonstandard treatment of UNIQUE NULL columns is managed so you can insert multiple rows where the column is defined as both “unique=True” and “null=True”.

Introspection code to reverse engineer existing SQL Server databases is non-existant.

Along the way, I’ve hit a couple bugs with the Jython beta that were annoying, but Frank and gang are a busy bunch.  They’ve already fixed one bug related to weird indentation of Python code.

Some of the MSSQL backend code needs some work to de-uglify the code into a more readable state.  One bit of Django that would be nice to change is the way that models are loaded incrementally and the SQL DDL is created at the same time.

So there are times when you have SQL tables that have foreign key relationships to tables that don’t exist, but Django will create the ALTER TABLE constraint later.  This works fine in some cases, but for MSSQL – I actually needed to know that all models for the current application were fully loaded by the class loader.

Heck – even the syncdb command has to work around this same problem.

I’ll get more into that once the public code repository is setup.

victorng Uncategorized , , ,

  1. May 28th, 2009 at 10:59 | #1

    Hi,

    Do you have any plans to publish your work on MSSQL for Django-on-jython?

    Regards,

    Alan.