Author: mboersma
Date: 2008-08-24 15:16:56 -0500 (Sun, 24 Aug 2008)
New Revision: 8522

Modified:
   django/trunk/django/db/backends/oracle/base.py
Log:
Fixed #7628 -- Oracle backend won't try to recreate existing sequences during 
syncdb.  Thanks, cmarshal.

Modified: django/trunk/django/db/backends/oracle/base.py
===================================================================
--- django/trunk/django/db/backends/oracle/base.py      2008-08-24 17:54:51 UTC 
(rev 8521)
+++ django/trunk/django/db/backends/oracle/base.py      2008-08-24 20:16:56 UTC 
(rev 8522)
@@ -26,12 +26,14 @@
 DatabaseError = Database.Error
 IntegrityError = Database.IntegrityError
 
+
 class DatabaseFeatures(BaseDatabaseFeatures):
     empty_fetchmany_value = ()
     needs_datetime_string_cast = False
     uses_custom_query_class = True
     interprets_empty_strings_as_nulls = True
 
+
 class DatabaseOperations(BaseDatabaseOperations):
     def autoinc_sql(self, table, column):
         # To simulate auto-incrementing primary keys in Oracle, we have to
@@ -40,7 +42,17 @@
         tr_name = get_trigger_name(table)
         tbl_name = self.quote_name(table)
         col_name = self.quote_name(column)
-        sequence_sql = 'CREATE SEQUENCE %s;' % sq_name
+        sequence_sql = """
+            DECLARE
+                i INTEGER;
+            BEGIN
+                SELECT COUNT(*) INTO i FROM USER_CATALOG
+                    WHERE TABLE_NAME = '%(sq_name)s' AND TABLE_TYPE = 
'SEQUENCE';
+                IF i = 0 THEN
+                    EXECUTE IMMEDIATE 'CREATE SEQUENCE %(sq_name)s';
+                END IF;
+            END;
+            /""" % locals()
         trigger_sql = """
             CREATE OR REPLACE TRIGGER %(tr_name)s
             BEFORE INSERT ON %(tbl_name)s
@@ -195,7 +207,7 @@
 
 
 class DatabaseWrapper(BaseDatabaseWrapper):
-    
+
     operators = {
         'exact': '= %s',
         'iexact': '= UPPER(%s)',
@@ -212,7 +224,7 @@
     }
     oracle_version = None
 
-    def __init__(self, *args, **kwargs):        
+    def __init__(self, *args, **kwargs):
         super(DatabaseWrapper, self).__init__(*args, **kwargs)
 
         self.features = DatabaseFeatures()
@@ -265,6 +277,7 @@
         cursor.arraysize = 100
         return cursor
 
+
 class OracleParam(object):
     """
     Wrapper object for formatting parameters for Oracle. If the string
@@ -285,6 +298,7 @@
         else:
             self.input_size = None
 
+
 class FormatStylePlaceholderCursor(Database.Cursor):
     """
     Django uses "format" (e.g. '%s') style placeholders, but Oracle uses ":var"


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to