Code

Ticket #12941: django-multidb-cursor.diff

File django-multidb-cursor.diff, 684 bytes (added by Alex, 4 years ago)
Line 
1diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt
2index 5ec0485..a8ff88a 100644
3--- a/docs/topics/db/sql.txt
4+++ b/docs/topics/db/sql.txt
5@@ -220,6 +220,18 @@ is required. For example::
6 
7         return row
8 
9+
10+If you are using more than one database you'll need to get the connection and
11+cursor for the right database.  Django provides a ``connections`` object which
12+is a dictionary-like object that lets you get connections by their alias::
13+   
14+    def my_custom_sql(alias):
15+        from django.db import connections
16+       
17+        cursor = connections[alias].cursor()
18+        # ... execute SQL
19+
20+
21 .. _transactions-and-raw-sql:
22 
23 Transactions and raw SQL