diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-11 15:52:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-14 01:18:06 -0400 |
| commit | 1a990ee33239aa275567cb926a5b421b2087294b (patch) | |
| tree | edc023629e1f82a2d66e2a5ab6320681a0e91810 /lib/sqlalchemy/dialects/oracle/base.py | |
| parent | e331da58a6d136aff824b43312424083090a7c90 (diff) | |
| download | sqlalchemy-1a990ee33239aa275567cb926a5b421b2087294b.tar.gz | |
Ensure Oracle index w/ col DESC etc. is reflected
Fixed bug where an index reflected under Oracle with an expression like
"column DESC" would not be returned, if the table also had no primary
key, as a result of logic that attempts to filter out the
index implicitly added by Oracle onto the primary key columns.
Reworked the "filter out the primary key index" logic in oracle
get_indexes() to be clearer.
This changeset also adds an internal check to ColumnCollection
to accomodate for the case of a column being added twice,
as well as adding a private _table argument to Index such that
reflection can specify the Table explicitly. The _table
argument can become part of public API in a later revision
or release if needed.
Change-Id: I745711e03b3e450b7f31185fc70e10d3823063fa
Fixes: #4042
Diffstat (limited to 'lib/sqlalchemy/dialects/oracle/base.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index d9fa80df1..9478f6531 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -1469,21 +1469,9 @@ class OracleDialect(default.DefaultDialect): oracle_sys_col = re.compile(r'SYS_NC\d+\$', re.IGNORECASE) - def upper_name_set(names): - return {i.upper() for i in names} - - pk_names = upper_name_set(pkeys) - - def remove_if_primary_key(index): - # don't include the primary key index - if index is not None and \ - upper_name_set(index['column_names']) == pk_names: - indexes.pop() - index = None for rset in rp: if rset.index_name != last_index_name: - remove_if_primary_key(index) index = dict(name=self.normalize_name(rset.index_name), column_names=[], dialect_options={}) indexes.append(index) @@ -1500,7 +1488,17 @@ class OracleDialect(default.DefaultDialect): index['column_names'].append( self.normalize_name(rset.column_name)) last_index_name = rset.index_name - remove_if_primary_key(index) + + def upper_name_set(names): + return {i.upper() for i in names} + + pk_names = upper_name_set(pkeys) + if pk_names: + def is_pk_index(index): + # don't include the primary key index + return upper_name_set(index['column_names']) == pk_names + indexes = [idx for idx in indexes if not is_pk_index(idx)] + return indexes @reflection.cache |
