浏览代码

Fixed #24200 -- Made introspection bypass statement cache

Josh Smeaton 10 年之前
父节点
当前提交
1fbe8a2de3

+ 0 - 1
django/db/backends/oracle/features.py

@@ -35,7 +35,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
     supports_combined_alters = False
     supports_combined_alters = False
     nulls_order_largest = True
     nulls_order_largest = True
     requires_literal_defaults = True
     requires_literal_defaults = True
-    connection_persists_old_columns = True
     closed_cursor_error_class = InterfaceError
     closed_cursor_error_class = InterfaceError
     bare_select_suffix = " FROM DUAL"
     bare_select_suffix = " FROM DUAL"
     uppercases_column_names = True
     uppercases_column_names = True

+ 6 - 1
django/db/backends/oracle/introspection.py

@@ -33,6 +33,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
     except AttributeError:
     except AttributeError:
         pass
         pass
 
 
+    cache_bust_counter = 1
+
     def get_field_type(self, data_type, description):
     def get_field_type(self, data_type, description):
         # If it's a NUMBER with scale == 0, consider it an IntegerField
         # If it's a NUMBER with scale == 0, consider it an IntegerField
         if data_type == cx_Oracle.NUMBER:
         if data_type == cx_Oracle.NUMBER:
@@ -59,7 +61,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
 
 
     def get_table_description(self, cursor, table_name):
     def get_table_description(self, cursor, table_name):
         "Returns a description of the table, with the DB-API cursor.description interface."
         "Returns a description of the table, with the DB-API cursor.description interface."
-        cursor.execute("SELECT * FROM %s WHERE ROWNUM < 2" % self.connection.ops.quote_name(table_name))
+        self.cache_bust_counter += 1
+        cursor.execute("SELECT * FROM {} WHERE ROWNUM < 2 AND {} > 0".format(
+            self.connection.ops.quote_name(table_name),
+            self.cache_bust_counter))
         description = []
         description = []
         for desc in cursor.description:
         for desc in cursor.description:
             name = force_text(desc[0])  # cx_Oracle always returns a 'str' on both Python 2 and 3
             name = force_text(desc[0])  # cx_Oracle always returns a 'str' on both Python 2 and 3

+ 0 - 3
django/db/backends/oracle/schema.py

@@ -87,9 +87,6 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
         self.remove_field(model, old_field)
         self.remove_field(model, old_field)
         # Rename the new field
         # Rename the new field
         self.alter_field(model, new_temp_field, new_field)
         self.alter_field(model, new_temp_field, new_field)
-        # Close the connection to force cx_Oracle to get column types right
-        # on a new cursor
-        self.connection.close()
 
 
     def normalize_name(self, name):
     def normalize_name(self, name):
         """
         """

+ 4 - 0
docs/releases/1.8.txt

@@ -286,6 +286,10 @@ Database backends
 * The MySQL backend no longer creates explicit indexes for foreign keys when
 * The MySQL backend no longer creates explicit indexes for foreign keys when
   using the InnoDB storage engine, as MySQL already creates them automatically.
   using the InnoDB storage engine, as MySQL already creates them automatically.
 
 
+* The Oracle backend no longer defines the ``connection_persists_old_columns``
+  feature as ``True``. Instead, Oracle will now include a cache busting clause
+  when getting the description of a table.
+
 Email
 Email
 ^^^^^
 ^^^^^