Code

Ticket #9405: django-db-operations.diff

File django-db-operations.diff, 5.2 KB (added by Tarken, 6 years ago)
Line 
1Index: db/backends/dummy/base.py
2===================================================================
3--- db/backends/dummy/base.py   (revision 2)
4+++ db/backends/dummy/base.py   (working copy)
5@@ -45,7 +45,7 @@
6         super(DatabaseWrapper, self).__init__(*args, **kwargs)
7 
8         self.features = BaseDatabaseFeatures()
9-        self.ops = DatabaseOperations()
10+        self.ops = DatabaseOperations(self)
11         self.client = DatabaseClient()
12         self.creation = BaseDatabaseCreation(self)
13         self.introspection = DatabaseIntrospection(self)
14Index: db/backends/mysql/base.py
15===================================================================
16--- db/backends/mysql/base.py   (revision 2)
17+++ db/backends/mysql/base.py   (working copy)
18@@ -223,7 +223,7 @@
19         self.server_version = None
20 
21         self.features = DatabaseFeatures()
22-        self.ops = DatabaseOperations()
23+        self.ops = DatabaseOperations(self)
24         self.client = DatabaseClient()
25         self.creation = DatabaseCreation(self)
26         self.introspection = DatabaseIntrospection(self)
27Index: db/backends/oracle/base.py
28===================================================================
29--- db/backends/oracle/base.py  (revision 2)
30+++ db/backends/oracle/base.py  (working copy)
31@@ -137,8 +137,7 @@
32     def regex_lookup(self, lookup_type):
33         # If regex_lookup is called before it's been initialized, then create
34         # a cursor to initialize it and recur.
35-        from django.db import connection
36-        connection.cursor()
37+        self.connection.cursor()
38         return connection.ops.regex_lookup(lookup_type)
39 
40     def sql_flush(self, style, tables, sequences):
41@@ -231,7 +230,7 @@
42         super(DatabaseWrapper, self).__init__(*args, **kwargs)
43 
44         self.features = DatabaseFeatures()
45-        self.ops = DatabaseOperations()
46+        self.ops = DatabaseOperations(self)
47         self.client = DatabaseClient()
48         self.creation = DatabaseCreation(self)
49         self.introspection = DatabaseIntrospection(self)
50Index: db/backends/postgresql/base.py
51===================================================================
52--- db/backends/postgresql/base.py      (revision 2)
53+++ db/backends/postgresql/base.py      (working copy)
54@@ -89,7 +89,7 @@
55         super(DatabaseWrapper, self).__init__(*args, **kwargs)
56 
57         self.features = DatabaseFeatures()
58-        self.ops = DatabaseOperations()
59+        self.ops = DatabaseOperations(self)
60         self.client = DatabaseClient()
61         self.creation = DatabaseCreation(self)
62         self.introspection = DatabaseIntrospection(self)
63Index: db/backends/postgresql/operations.py
64===================================================================
65--- db/backends/postgresql/operations.py        (revision 2)
66+++ db/backends/postgresql/operations.py        (working copy)
67@@ -8,13 +8,13 @@
68 # used by both the 'postgresql' and 'postgresql_psycopg2' backends.
69 
70 class DatabaseOperations(BaseDatabaseOperations):
71-    def __init__(self):
72+    def __init__(self, *args):
73         self._postgres_version = None
74+        return super(DatabaseOperations, self).__init__(*args)
75 
76     def _get_postgres_version(self):
77         if self._postgres_version is None:
78-            from django.db import connection
79-            cursor = connection.cursor()
80+            cursor = self.connection.cursor()
81             cursor.execute("SELECT version()")
82             version_string = cursor.fetchone()[0]
83             m = server_version_re.match(version_string)
84Index: db/backends/postgresql_psycopg2/base.py
85===================================================================
86--- db/backends/postgresql_psycopg2/base.py     (revision 2)
87+++ db/backends/postgresql_psycopg2/base.py     (working copy)
88@@ -59,7 +59,7 @@
89         super(DatabaseWrapper, self).__init__(*args, **kwargs)
90         
91         self.features = DatabaseFeatures()
92-        self.ops = DatabaseOperations()
93+        self.ops = DatabaseOperations(self)
94         self.client = DatabaseClient()
95         self.creation = DatabaseCreation(self)
96         self.introspection = DatabaseIntrospection(self)
97Index: db/backends/sqlite3/base.py
98===================================================================
99--- db/backends/sqlite3/base.py (revision 2)
100+++ db/backends/sqlite3/base.py (working copy)
101@@ -126,7 +126,7 @@
102         super(DatabaseWrapper, self).__init__(*args, **kwargs)
103         
104         self.features = DatabaseFeatures()
105-        self.ops = DatabaseOperations()
106+        self.ops = DatabaseOperations(self)
107         self.client = DatabaseClient()
108         self.creation = DatabaseCreation(self)
109         self.introspection = DatabaseIntrospection(self)
110Index: db/backends/__init__.py
111===================================================================
112--- db/backends/__init__.py     (revision 2)
113+++ db/backends/__init__.py     (working copy)
114@@ -81,6 +81,9 @@
115     a backend performs ordering or calculates the ID of a recently-inserted
116     row.
117     """
118+    def __init__(self, connection):
119+        self.connection = connection
120+
121     def autoinc_sql(self, table, column):
122         """
123         Returns any SQL needed to support auto-incrementing primary keys, or