Django

Code

Ticket #9055 (new)

Opened 2 years ago

Last modified 1 year ago

Percent sign in SQL statement behaves different with CursorDebugWrapper

Reported by: guettli Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: 1.0 Keywords:
Cc: hv@tbz-pariv.de, walter+django@wjd.nu Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description

Hi,

cursor.execute(sql_string) behaves different if used with CursorDebugWrapper or not, if the string contains a percent sign.

If it is a psycopg2 cursor I need no escaping. If it is a CursorDebugWrapper, I need to do sql=sql.replace('%', '%%') first.

The one line patch is attached.

My question on comp.lang.python: http://groups.google.de/group/comp.lang.python/browse_frm/thread/10ed61a621ea5aaa/0ff82407042441b1?hl=de&lnk=st&q=corner+case+python+guettler#0ff82407042441b1

Related: #3041

Attachments

9055.diff (485 bytes) - added by guettli on 09/12/08 07:15:43.

Change History

09/12/08 07:15:43 changed by guettli

  • attachment 9055.diff added.

09/12/08 07:17:32 changed by guettli

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Other backends might need to be changed, too:

user@host:~/_djangosvn/trunk/django/db/backends> find -name '*.py' | xargs grep -E 'def execute\('
./postgresql/base.py:    def execute(self, sql, params=()):
./sqlite3/base.py:    def execute(self, query, params=()):
./mysql/base.py:    def execute(self, query, args=None):
./oracle/base.py:    def execute(self, query, params=None):
./util.py:    def execute(self, sql, params=None):

09/16/08 20:27:32 changed by mtredinnick

  • component changed from Uncategorized to Database layer (models, ORM).
  • needs_tests set to 1.
  • stage changed from Unreviewed to Accepted.

This needs a test case, please. Something that fails beforehand and passes afterwards. You will see a few tests that set DEBUG=True and the start and reset it at the end to test things like this.

04/18/09 13:42:10 changed by kmtracey

Note: the patch provided for MySQL backend on #10851 also made the same change to executemany, so when this is looked at for check in it should be investigated whether executemany needs fixing as well.

04/19/09 01:34:08 changed by wdoekes

"""also made the same change to executemany"""

No I didn't ;-) I only replaced the parameter name "args" with "params" (which should've been "param_list" anyway, sloppy me). There was no actual change in the code for executemany.

04/19/09 01:34:39 changed by wdoekes

  • cc changed from hv@tbz-pariv.de to hv@tbz-pariv.de, walter+django@wjd.nu.

Add/Change #9055 (Percent sign in SQL statement behaves different with CursorDebugWrapper)




Change Properties
Action