On Tue, 10 Jan 2006 14:33:18 -0600 Adrian Holovaty wrote:

> The problem is that the SQL Server database backend (the "adodbapi"
> library) assumes placeholders use "?" for placeholders. So the Django
> layer needs to convert all "%s" placeholders in the query to "?".
> 
> It looks like the current way this is happening (in
> django/core/db/backends/ado_mssql.py) isn't working. Could you tinker
> with this and see what you can fix?

Just adding what I know about MS SQL, in complete ignorance of adodbapi:

The best way to do it with MS SQL is to use 'Parametrised SQL'.  In
this case you have a query string that looks like

SELECT foo FROM bar WHERE baz = @baz

and you also pass in (somehow) the value of @baz (I only know how to do
this in C#/.NET - you have a Command object (whose .Text property is
the SQL) to which you add SqlParameter objects).

The advantage of this is that MS SQL can then generate a strategy for
doing the query, (in the same way it does for stored procs) and these
are cached.  Because you are not substituting in the values of @baz
directly, but letting MS SQL do it, you can get good hit ratios on the
'query strategy cache' (I can't remember the right word for it, but you
get my meaning).

I don't know how much adodbapi can do, but if you could make use of
this feature it would be very good.  Performance is one reason often
quoted for doing stored procs instead of straight SQL.  If you can use
parametrised SQL, that argument almost disappears, because MS SQL can
(and does) optimise in the same way that it does for stored procs.

Another thing to note is that the values of parameters should not be
escaped with this method (this is another reason for using parameters
- they avoid SQL injection).

Luke


-- 
"Dysfunction: The only consistent feature of all of your dissatisfying 
relationships is you." (despair.com)

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/

Reply via email to