Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11706: Added an Oracle connection option to disable the use of…

… RETURNING INTO in INSERT statements.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14765 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1f68dc4ad4ddc67831c6aa047683a5b53fa33a37 1 parent dceaa82
Ian Kelly authored December 01, 2010
7  django/db/backends/oracle/base.py
@@ -351,6 +351,8 @@ def __init__(self, *args, **kwargs):
351 351
 
352 352
         self.oracle_version = None
353 353
         self.features = DatabaseFeatures(self)
  354
+        use_returning_into = self.settings_dict["OPTIONS"].get('use_returning_into', True)
  355
+        self.features.can_return_id_from_insert = use_returning_into
354 356
         self.ops = DatabaseOperations()
355 357
         self.client = DatabaseClient(self)
356 358
         self.creation = DatabaseCreation(self)
@@ -377,7 +379,10 @@ def _cursor(self):
377 379
         cursor = None
378 380
         if not self._valid_connection():
379 381
             conn_string = convert_unicode(self._connect_string())
380  
-            self.connection = Database.connect(conn_string, **self.settings_dict['OPTIONS'])
  382
+            conn_params = self.settings_dict['OPTIONS'].copy()
  383
+            if 'use_returning_into' in conn_params:
  384
+                del conn_params['use_returning_into']
  385
+            self.connection = Database.connect(conn_string, **conn_params)
381 386
             cursor = FormatStylePlaceholderCursor(self.connection)
382 387
             # Set oracle date to ansi date format.  This only needs to execute
383 388
             # once when we create a new connection. We also set the Territory
17  docs/ref/databases.txt
@@ -585,6 +585,23 @@ your Oracle database configuration to True::
585 585
 
586 586
 Failure to do this may result in crashes and other odd behavior.
587 587
 
  588
+INSERT ... RETURNING INTO
  589
+-------------------------
  590
+
  591
+By default, the Oracle backend uses a ``RETURNING INTO`` clause to efficiently
  592
+retrieve the value of an ``AutoField`` when inserting new rows.  This behavior
  593
+may result in a ``DatabaseError`` in certain unusual setups, such as when
  594
+inserting into a remote table, or into a view with an ``INSTEAD OF`` trigger.
  595
+The ``RETURNING INTO`` clause can be disabled by setting the
  596
+``use_returning_into`` option of the database configuration to False::
  597
+
  598
+            'OPTIONS': {
  599
+                'use_returning_into': False,
  600
+            },
  601
+
  602
+In this case, the Oracle backend will use a separate ``SELECT`` query to
  603
+retrieve AutoField values.
  604
+
588 605
 Tablespace options
589 606
 ------------------
590 607
 

0 notes on commit 1f68dc4

Please sign in to comment.
Something went wrong with that request. Please try again.