Skip to content

sql logger should quote query params #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jla415 opened this issue May 13, 2010 · 1 comment · May be fixed by #66
Open

sql logger should quote query params #13

jla415 opened this issue May 13, 2010 · 1 comment · May be fixed by #66

Comments

@jla415
Copy link

jla415 commented May 13, 2010

It would be nice if the sql logger would quote params in the printed queries to make it easier to copy/paste into a CLI client for closer optimization/examination.

Eg instead of:

sql SELECT ...
FROM foo
WHERE foo.name = bob
sql Found 1 matching rows

it would print:

sql SELECT ...
FROM foo
WHERE foo.name = "bob"
sql Found 1 matching rows

@acdha
Copy link
Contributor

acdha commented Nov 7, 2012

In addition to making this easier to reuse, it would fix an actual bug in the display where data values are processed as if they're part of the actual query:

NATIONAL-archives-AND-records-administration

instead of:

'national-archives-and-records-administration'

acdha added a commit to acdha/django-devserver that referenced this issue Nov 7, 2012
Previously string values were not quoted, causing sqlparse to interpret them as
code. Any value which matched a SQL keyword would be capitalized and indented,
causing garbled display of queries containing text like 'of', 'and', 'key',
'limit', etc.

django.db.backends.BaseDatabaseOperations has a helpful last_executed_query
method which expands query placeholders (django-debug-toolbar also uses this)
reliably. This commit changes the SQL realtime module to use last_executed_query
and to perform the formatting after the actual query executes to match the
expected semantics.

Closes dcramer#13
@acdha acdha linked a pull request Nov 7, 2012 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants