Commits

Mike Bayer committed 8db5f17

updates to oracle
added more ordering to schema collections for better predictability

Comments (0)

Files changed (5)

lib/sqlalchemy/databases/oracle.py

 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-import sys, StringIO, string
+import sys, StringIO, string, re
 
 import sqlalchemy.util as util
 import sqlalchemy.sql as sql
             elif coltype=='CHAR' or coltype=='VARCHAR2':
                 coltype = ischema_names.get(coltype, OracleString)(length)
             else:
-                coltype = ischema_names.get(coltype)
+                coltype = re.sub(r'\(\d+\)', '', coltype)
+                try:
+                    coltype = ischema_names[coltype]
+                except KeyError:
+                    raise exceptions.AssertionError("Cant get coltype for type '%s'" % coltype)
                
             colargs = []
             if default is not None:

lib/sqlalchemy/schema.py

         self.autoincrement = kwargs.pop('autoincrement', True)
         self.constraints = util.Set()
         self.__originating_column = self
-        self._foreign_keys = util.Set()
+        self._foreign_keys = util.OrderedSet()
         if len(kwargs):
             raise exceptions.ArgumentError("Unknown arguments passed to Column: " + repr(kwargs.keys()))
 
         super(ForeignKeyConstraint, self).__init__(name)
         self.__colnames = columns
         self.__refcolnames = refcolumns
-        self.elements = util.Set()
+        self.elements = util.OrderedSet()
         self.onupdate = onupdate
         self.ondelete = ondelete
         if self.name is None and use_alter:

lib/sqlalchemy/sql.py

         super(TableClause, self).__init__(name)
         self.name = self.fullname = name
         self._columns = ColumnCollection()
-        self._foreign_keys = util.Set()
-        self._primary_key = util.Set()
+        self._foreign_keys = util.OrderedSet()
+        self._primary_key = ColumnCollection()
         for c in columns:
             self.append_column(c)
         self._oid_column = _ColumnClause('oid', self, _is_oid=True)

test/orm/cycles.py

         global t1, t2, metadata
         metadata = BoundMetaData(testbase.db)
         t1 = Table('t1', metadata, 
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True),
             Column('parent_c1', Integer, ForeignKey('t1.c1')),
             Column('data', String(20))
         )
         t2 = Table('t2', metadata,
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t2c1_id_seq', optional=True), primary_key=True),
             Column('c1id', Integer, ForeignKey('t1.c1')),
             Column('data', String(20))
         )
         global t1, t2, metadata
         metadata = BoundMetaData(testbase.db)
         t1 = Table('t1', metadata, 
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True),
             Column('c2', Integer, ForeignKey('t2.c1'))
         )
         t2 = Table('t2', metadata,
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t2c1_id_seq', optional=True), primary_key=True),
             Column('c2', Integer)
         )
         metadata.create_all()
         global t1, t2, t3, metadata
         metadata = BoundMetaData(testbase.db)
         t1 = Table('t1', metadata, 
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t1c1_id_seq', optional=True), primary_key=True),
             Column('c2', Integer, ForeignKey('t2.c1')),
         )
         t2 = Table('t2', metadata,
-            Column('c1', Integer, primary_key=True),
-            Column('c2', Integer),
+            Column('c1', Integer, Sequence('t2c1_id_seq', optional=True), primary_key=True),
+            Column('c2', Integer, ForeignKey('t1.c1', use_alter=True, name='t1c1_fq')),
         )
-        t2.create()
-        t1.create()
-        t2.c.c2.append_foreign_key(ForeignKey('t1.c1'))
         t3 = Table('t1_data', metadata, 
-            Column('c1', Integer, primary_key=True),
+            Column('c1', Integer, Sequence('t1dc1_id_seq', optional=True), primary_key=True),
             Column('t1id', Integer, ForeignKey('t1.c1')),
             Column('data', String(20)))
-        t3.create()
+        metadata.create_all()
         
     def tearDown(self):
         clear_mappers()
 
     def tearDownAll(self):
-        t3.drop()
-        t1.drop()
-        t2.drop()
+        metadata.drop_all()
         
     def testcycle(self):
         class C1(object):pass
         global metadata, node_table
         metadata = BoundMetaData(testbase.db)
         node_table = Table('node', metadata,
-            Column('id', Integer, primary_key=True),
+            Column('id', Integer, Sequence('nodeid_id_seq', optional=True), primary_key=True),
             Column('path', String(50), nullable=False),
             Column('parent_id', Integer, ForeignKey('node.id'), nullable=True),
             Column('prev_sibling_id', Integer, ForeignKey('node.id'), nullable=True),

test/orm/polymorph.py

         
         # a table to store companies
         companies = Table('companies', metadata, 
-           Column('company_id', Integer, primary_key=True),
+           Column('company_id', Integer, Sequence('company_id_seq', optional=True), primary_key=True),
            Column('name', String(50)))
 
         # we will define an inheritance relationship between the table "people" and "engineers",
         # and a second inheritance relationship between the table "people" and "managers"
         people = Table('people', metadata, 
-           Column('person_id', Integer, primary_key=True),
+           Column('person_id', Integer, Sequence('person_id_seq', optional=True), primary_key=True),
            Column('company_id', Integer, ForeignKey('companies.company_id')),
            Column('name', String(50)),
            Column('type', String(30)))