On 1/10/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > On 1/10/06, Rich Bakos <[EMAIL PROTECTED]> wrote: > > Here is the exact SQL that is passed to MS SQL: > > > > SELECT > > [core_sessions].[session_key],[core_sessions].[session_data],[core_sessions].[expire_date] > > FROM [core_sessions] WHERE [core_sessions].[session_key] = %s > > > > As you can see, it has stopped at %s. > > > > Is there anything I can do to help? > > Yes, help would be great, because I don't have access to a SQL Server > installation... > > Here's what's happening. All Django queries use "%s" as placeholders > for values that will be quoted by the database backend. For example: > > cursor.execute("UPDATE foo set bar=%s", ['fred']) > > The database backend translates this to: > > UPDATE foo set bar='fred' > > Note that it properly applies quote marks as necessary. > > 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? >
D'oh, dang it. This is one of the bits I'd run into before when I was testing it. Sorry I didn't recognize it; I've slept since then. Yeah, adodbapi was doing something weird with the executeHelper, so we did this: # We need to use a special Cursor class because adodbapi expects question-mark # param style, but Django expects "%s". This cursor converts question marks to # format-string style. #class Cursor(Database.Cursor): # def executeHelper(self, operation, isStoredProcedureCall, parameters=None): # print "got operation %s" % (operation) # if parameters is not None and "%s" in operation: # operation = operation.replace("%s", "?") # print "replaced operation to %s" % (operation) # Database.Cursor.executeHelper(self, operation, isStoredProcedureCall, parameters) # #class Connection(Database.Connection): # def foo(): # pass # def cursor(self): # return Cursor(self) #Database.Connection = Connection ##dbg #Database.XConnection = Connection # old_executeHelper = Database.Cursor.executeHelper def executeHelper(self, operation, isStoredProcedureCall, parameters=None): if parameters is not None and "%s" in operation: operation = operation.replace("%s", "?") old_executeHelper(self, operation, isStoredProcedureCall, parameters) Database.Cursor.executeHelper = executeHelper