Hi, I am new to Django and building a model to show an existing MS SQL Server database using ado_mssql and adodbapi on Windows.
I have a simple 'courses' model working and I can call courses.get_list() and get the full list of courses. When I try to do a query such as courses.get_list(code__exact='HR5166') I get a DatabaseError. The error is the same one shown here: http://code.djangoproject.com/ticket/644 The problem is that the %s parameters are never getting converted to ? style - the patched Cursor and Connection code in ado_mssql.py is never executed. The reason the patch code is never executed is because the Connection class is actually defined and accessed in adodbapi.adodbapi (the adodbapi module of the adodbapi package). The current patch only changes the package-level reference to Connection created in adodbapi.__init__, it doesn't change the class actually used in adodbapi.connect() The fix is to patch in both places - the public reference in adodbapi and the module-level reference in adodbapi.adodbapi. Here is a diff, with this fix I can query my database correctly: Index: django/core/db/backends/ado_mssql.py =================================================================== --- django/core/db/backends/ado_mssql.py (revision 2415) +++ django/core/db/backends/ado_mssql.py (working copy) @@ -27,7 +27,11 @@ class Connection(Database.Connection): def cursor(self): return Cursor(self) + +# Patch adodbapi to use our connection. It's patched two places because +# adodbapi.__init__ promotes adodbapi.adodbapi.Connection to package scope Database.Connection = Connection +Database.adodbapi.Connection = Connection origCVtoP = Database.convertVariantToPython def variantToPython(variant, adType): @@ -43,6 +47,7 @@ return int(res) # If float but int, then int. return res Database.convertVariantToPython = variantToPython +Database.adodbapi.convertVariantToPython = variantToPython class DatabaseWrapper: def __init__(self): Kent PS I tried submitting this as a patch in the tracker but I didn't see any 'attach file' button... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---

