pragma = "PRAGMA %s." % quote(schema)
else:
pragma = "PRAGMA "
+ include_auto_indexes = kw.pop('include_auto_indexes', False)
qtable = quote(table_name)
c = _pragma_cursor(connection.execute("%sindex_list(%s)" % (pragma, qtable)))
indexes = []
row = c.fetchone()
if row is None:
break
+ # ignore implicit primary key index.
+ # http://www.mail-archive.com/sqlite-users@sqlite.org/msg30517.html
+ elif not include_auto_indexes and row[1].startswith('sqlite_autoindex'):
+ continue
+
indexes.append(dict(name=row[1], column_names=[], unique=row[2]))
# loop thru unique indexes to get the column names.
for idx in indexes:
key = (
fn.__name__,
tuple(a for a in args if isinstance(a, basestring)),
- tuple((k, v) for k, v in kw.iteritems() if isinstance(v, basestring))
+ tuple((k, v) for k, v in kw.iteritems() if isinstance(v, (basestring, int, float)))
)
ret = info_cache.get(key)
if ret is None:
referred_columns
a list of column names in the referred table that correspond to
constrained_columns
+
+ \**kw
+ other options passed to the dialect's get_foreign_keys() method.
+
"""
fk_defs = self.dialect.get_foreign_keys(self.conn, table_name, schema,
**kw)
return fk_defs
- def get_indexes(self, table_name, schema=None):
+ def get_indexes(self, table_name, schema=None, **kw):
"""Return information about indexes in `table_name`.
Given a string `table_name` and an optional string `schema`, return
unique
boolean
+
+ \**kw
+ other options passed to the dialect's get_indexes() method.
"""
indexes = self.dialect.get_indexes(self.conn, table_name,
schema,
- info_cache=self.info_cache)
+ info_cache=self.info_cache, **kw)
return indexes
def reflecttable(self, table, include_columns):
except exc.DBAPIError:
pass
raise
-
+
+
+ def test_dont_reflect_autoindex(self):
+ meta = MetaData(testing.db)
+ t = Table('foo', meta, Column('bar', String, primary_key=True))
+ meta.create_all()
+
+ from sqlalchemy.engine.reflection import Inspector
+ try:
+ inspector = Inspector(testing.db)
+ eq_(inspector.get_indexes('foo'), [])
+ eq_(
+ inspector.get_indexes('foo', include_auto_indexes=True),
+ [{'unique': 1, 'name': u'sqlite_autoindex_foo_1', 'column_names': [u'bar']}]
+ )
+ finally:
+ meta.drop_all()
+
+
def test_set_isolation_level(self):
"""Test setting the read uncommitted/serializable levels"""
eng = create_engine(testing.db.url)