Skip to content

Oracle reflection does not set the name of Primary key constraints #1868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sqlalchemy-bot opened this issue Aug 6, 2010 · 7 comments
Closed
Labels
bug Something isn't working oracle
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Anonymous

My patch:

--- lib/sqlalchemy/dialects/oracle/base.py      2010-08-03 07:18:07.000000000 -0400
+++ /home/rarch/site-packages/SQLAlchemy-0.6.1.4-py2.6-linux-x86_64.egg/sqlalchemy/dialects/oracle/base.py      2010-08-03 11:39:54.000000000 -0400
@@ -929,43 +929,58 @@
     @reflection.cache
     def get_primary_keys(self, connection, table_name, schema=None, **kw):
         """

         kw arguments can be:

             oracle_resolve_synonyms

             dblink

         """
+        return self._get_primary_keys(connection, table_name, schema=None, **kw)[0](0)

+    @reflection.cache
+    def _get_primary_keys(self, connection, table_name, schema=None, **kw):
         resolve_synonyms = kw.get('oracle_resolve_synonyms', False)
         dblink = kw.get('dblink', '')
         info_cache = kw.get('info_cache')

         (table_name, schema, dblink, synonym) = \
             self._prepare_reflection_args(connection, table_name, schema,
                                           resolve_synonyms, dblink,
                                           info_cache=info_cache)
         pkeys = [       constraint_name = None
         constraint_data = self._get_constraint_data(connection, table_name,
                                         schema, dblink,
                                         info_cache=kw.get('info_cache'))

         for row in constraint_data:
             #print "ROW:" , row
             (cons_name, cons_type, local_column, remote_table, remote_column, remote_owner) = \
                 row[0:2](]
+) + tuple([for x in row[2:6](self.normalize_name(x))])
             if cons_type == 'P':
+                if constraint_name is None:
+                    constraint_name = self.normalize_name(cons_name)
                 pkeys.append(local_column)
-        return pkeys
+        return pkeys, constraint_name
+
+    @reflection.cache
+    def get_pk_constraint(self, connection, table_name, schema=None, **kw):
+        cols, name = self._get_primary_keys(connection, table_name, schema=schema, **kw)
+
+        return {
+            'constrained_columns':cols,
+            'name':name
+        }

     @reflection.cache
     def get_foreign_keys(self, connection, table_name, schema=None, **kw):
         """

         kw arguments can be:

             oracle_resolve_synonyms

             dblink

Note

You may consider removing @reflection.cache from get_primary_keys() (and get_pk_constraint()) and keep it only on _get_primary_keys()

The attached file's output
before patch

type: PrimaryKeyConstraint()
name: None
columns: [u'id_b'](u'id_a',)
(u'SYS_C0048811', u'P', u'ID_A', None, None, None, Decimal('1'), None)
(u'SYS_C0048811', u'P', u'ID_B', None, None, None, Decimal('2'), None)

after patch

type: PrimaryKeyConstraint()
name: sys_c0048811
columns: [u'id_b'](u'id_a',)
(u'SYS_C0048811', u'P', u'ID_A', None, None, None, Decimal('1'), None)
(u'SYS_C0048811', u'P', u'ID_B', None, None, None, Decimal('2'), None)

Thanks,

Kent


Attachments: oraclereflect.py

@sqlalchemy-bot
Copy link
Collaborator Author

Anonymous wrote:

OracleReflectionPrimaryKeyConstraintName

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Anonymous:

  • attached file oraclereflect.py

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

these 0.6.4 milestones are tentative

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.6.4"

@sqlalchemy-bot
Copy link
Collaborator Author

Anonymous wrote:

Cumulative patch presented in #1867

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

perfect ! 36fa246.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added oracle bug Something isn't working labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.6.4 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working oracle
Projects
None yet
Development

No branches or pull requests

1 participant