Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#13101 closed (fixed)

Documentation: Add note about multiple databases and debugging raw sql

Reported by: anonymous Owned by: David Fischer
Component: Documentation Version: dev
Severity: Keywords: multidb, 1.2, debug
Cc: djfische@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (1)

13101-queries.diff (693 bytes ) - added by David Fischer 15 years ago.
Updated the attached file with Russell's proposal

Download all attachments as: .zip

Change History (8)

comment:1 by Russell Keith-Magee, 15 years ago

milestone: 1.2

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

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

by David Fischer, 15 years ago

Attachment: 13101-queries.diff added

Updated the attached file with Russell's proposal

comment:3 by David Fischer, 15 years ago

Has patch: set
Owner: changed from nobody to David Fischer
Status: newassigned

comment:4 by David Fischer, 15 years ago

Cc: djfische@… added

Adding myself as cc in case more is required

comment:5 by Russell Keith-Magee, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

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

comment:7 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top