[IronPython] Making adonet-dbapi's dbapi a drop-in replacement in django-mssql

Markus Törnqvist mjt at nysv.org
Tue Oct 27 15:44:52 CET 2009


On Tue, Oct 27, 2009 at 08:36:03AM -0600, Jeff Hardy wrote:
>
>No, the query still needs to be changed to have the right parameter
>markers so that ADO.NET knows where to insert the values. There should
>be a line that sets  command.CommandText to the query. Then the
>parameter values are added to the Parameters collection.

Ok.

>> I tried of course duplicating all the %s's in the query to ?s but that
>> didn't help me out.
>
>I think SQL Server's parameters are "@param", which means you'll have
>to name them :). However, IMHO this should happen before the Django
>layer passes the query to the MSSQL layer. mssql.py is supposed to be
>a generic dbapi adapter, so I don't think adding a djngo-specific
>conversion is a good idea.

Yes. There is, in fact, code for this in mssql.py :)

>> mssql.py is sort of weird.
>
>No surprise, I haven't really had time to polish it.

But do you remember what's happening in class Connection, when we request
a cursor?

I verified the connection being used is like
  <sqlserver_ado.dbapi.mssql.Connection instance at 0x0000000000000044>

but its cursor() method does not appear to get called even.

This is from generic.py:
class Cursor:
    def __init__(self, connection):
        self.id = random.randint(1, 1000)
        print "Creating cursor", self.id
        # snip

That debug print comes ok, but if I put a print in Connection's
cursor method, it doesn't print.

Does something very strange happen here with these objects?

If I move the parameter substitution code from mssql.py Cursor.execute
into generic, I actually get syncdb running(!!!) to a point where
it can't import gzip(!!!)

But of course that is a faux solution, driver-specific hacks need to
be in the drivers...

>> Now is there some chance that it's just broken, that it instantiates the
>> wrong kind of cursor which calls, naturally, the wrong execute() method?
>
>There's a very good chance that it's broken; I have no idea what state
>it was in when I left it. If you get it working, patches are welcome.

Of course :)

-- 
mjt




More information about the Ironpython-users mailing list