Django

Code

Ticket #13101 (closed: fixed)

Opened 6 months ago

Last modified 4 months ago

Documentation: Add note about multiple databases and debugging raw sql

Reported by: anonymous Assigned to: davidfischer
Milestone: 1.2 Component: Documentation
Version: SVN Keywords: multidb, 1.2, debug
Cc: djfische@gmail.com Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

http://docs.djangoproject.com/en/dev/faq/models/ has a section called "How can I see the raw SQL queries Django is running?", where it suggests:

>>> from django.db import connection
>>> connection.queries
[{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls',
'time': '0.002'}]

However, in a multidb scenario, that only gets the sql from the default connection. I found a better way is this function:

def get_sql():
    from django import db
    q = []
    for c in db.connections.all():
        q.extend(c.queries)
    return q

A note should probably be made about this.

Attachments

13101-queries.diff (0.7 kB) - added by davidfischer on 03/15/10 10:51:49.
Updated the attached file with Russell's proposal

Change History

03/12/10 21:48:53 changed by russellm

  • needs_better_patch changed.
  • needs_docs changed.
  • needs_tests changed.
  • milestone set to 1.2.

There is an even better way: connections['mydb'].queries. Notes about this approach were added in r12709, but not to the FAQ.

03/12/10 21:49:10 changed by russellm

  • stage changed from Unreviewed to Accepted.

03/15/10 10:51:49 changed by davidfischer

  • attachment 13101-queries.diff added.

Updated the attached file with Russell's proposal

03/15/10 10:52:16 changed by davidfischer

  • owner changed from nobody to davidfischer.
  • status changed from new to assigned.
  • has_patch set to 1.

03/15/10 11:22:05 changed by davidfischer

  • cc set to djfische@gmail.com.

Adding myself as cc in case more is required

05/08/10 02:53:49 changed by russellm

  • stage changed from Accepted to Ready for checkin.

05/08/10 23:50:48 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [13156]) Fixed #13101 -- Added multi-db info about debugging queries. Thanks to David Fischer for the patch.


Add/Change #13101 (Documentation: Add note about multiple databases and debugging raw sql)




Change Properties
Action