Code

Opened 8 years ago

Closed 6 years ago

#1412 closed defect (invalid)

[patch] ado_mssql queries broken

Reported by: kent37@… Owned by: adamv
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

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(codeexact='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. Attached is a diff,
with this fix I can query my database correctly.

Attachments (1)

ado_mssql.diff (907 bytes) - added by kent37@… 8 years ago.
Patch

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by kent37@…

Patch

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

If somebody other than the original reporter can confirm this works as advertised, we can commit it. I'm wondering how version sensitive it is (MS SQL Server underwent a few radical changes in recent years).

comment:3 Changed 7 years ago by kent37@…

This patch shouldn't be sensitive to MS SQL version at all. ado_mssql is monkey-patching adodbapi incorrectly. This patch makes the monkey-patch actually work as intended. This patch might be sensitive to adodbapi version but that project seems to be dead.

comment:4 Changed 6 years ago by FogleBird

I can confirm that the fix works on MSSQL Server 2000. I just ran into the same issue, found this bug and applied the patch and now it's working. This is my test:

from django.db import models

class OrderExecution(models.Model):
	transaction_id = models.IntegerField(primary_key=True)
	competition_id = models.IntegerField()
	symbol = models.CharField(maxlength=10)
	tx_date = models.DateTimeField()
	trader = models.CharField(maxlength=50)
	quantity = models.IntegerField()
	price = models.FloatField()
	amount = models.FloatField()
	commission = models.FloatField()
	code = models.CharField(maxlength=10)
	class Meta:
		db_table = 'view_order_executions'
	class Admin:
		pass

print OrderExecution.objects.filter(competition_id=176)

comment:5 Changed 6 years ago by adamv

  • Owner changed from nobody to adamv
  • Status changed from new to assigned

This patch also works against MS SQL Server 2005, against adodbapi 2.0.1 and 2.1.

If the ado_mssql backend is going to be kept in core, this patch should be committed to trunk.
Otherwise, if MS SQL support is moving external, this case can be closed as duplicate or invalid vs. case 5947.

comment:6 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from assigned to closed

This should become part of an external backend as discussed in #2358.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.