Skip to content

Commit bd34555

Browse files
committed
Merge pull request #417 from apollo13/sql_fixes
Fixed #383 -- Feed the proper SQL to cursor.execute (the one with placeholders).
2 parents 23dcd93 + 7c8b5b0 commit bd34555

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

debug_toolbar/forms.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ class SQLSelectForm(forms.Form):
1717
"""
1818
Validate params
1919
20-
sql: urlencoded sql with positional arguments
20+
sql: The sql statement with interpolated params
21+
raw_sql: The sql statement with placeholders
2122
params: JSON encoded parameter values
2223
duration: time for SQL to execute passed in from toolbar just for redisplay
2324
hash: the hash of (secret + sql + params) for tamper checking
2425
"""
2526
sql = forms.CharField()
27+
raw_sql = forms.CharField()
2628
params = forms.CharField()
2729
alias = forms.CharField(required=False, initial='default')
2830
duration = forms.FloatField()
@@ -39,8 +41,8 @@ def __init__(self, *args, **kwargs):
3941
for name in self.fields:
4042
self.fields[name].widget = forms.HiddenInput()
4143

42-
def clean_sql(self):
43-
value = self.cleaned_data['sql']
44+
def clean_raw_sql(self):
45+
value = self.cleaned_data['raw_sql']
4446

4547
if not value.lower().strip().startswith('select'):
4648
raise ValidationError("Only 'select' queries are allowed.")
@@ -72,8 +74,7 @@ def clean_hash(self):
7274
return hash
7375

7476
def reformat_sql(self):
75-
sql, params = self.cleaned_data['sql'], self.cleaned_data['params']
76-
return reformat_sql(self.cursor.db.ops.last_executed_query(self.cursor, sql, params))
77+
return reformat_sql(self.cleaned_data['sql'])
7778

7879
def make_hash(self, data):
7980
params = force_text(settings.SECRET_KEY) + data['sql'] + data['params']

debug_toolbar/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def sql_select(request):
1919
form = SQLSelectForm(request.POST or None)
2020

2121
if form.is_valid():
22-
sql = form.cleaned_data['sql']
22+
sql = form.cleaned_data['raw_sql']
2323
params = form.cleaned_data['params']
2424
cursor = form.cursor
2525
cursor.execute(sql, params)
@@ -43,7 +43,7 @@ def sql_explain(request):
4343
form = SQLSelectForm(request.POST or None)
4444

4545
if form.is_valid():
46-
sql = form.cleaned_data['sql']
46+
sql = form.cleaned_data['raw_sql']
4747
params = form.cleaned_data['params']
4848
cursor = form.cursor
4949

@@ -80,7 +80,7 @@ def sql_profile(request):
8080
form = SQLSelectForm(request.POST or None)
8181

8282
if form.is_valid():
83-
sql = form.cleaned_data['sql']
83+
sql = form.cleaned_data['raw_sql']
8484
params = form.cleaned_data['params']
8585
cursor = form.cursor
8686
result = None

0 commit comments

Comments
 (0)