Fix compatibility with SQLite prior to 3.16.0

pragma_index_info() and pragma_index_list() were introduced in 3.16.0 but the
version of SQLite running in Travis CI is earlier than that, hence the test
failures:

https://travis-ci.com/simonw/sqlite-utils/jobs/137617744
This commit is contained in:
Simon Willison 2018-08-01 08:29:53 -07:00
commit 0aa28293ad

View file

@ -125,13 +125,13 @@ class Table:
@property
def indexes(self):
sql = "select * from pragma_index_list(?)"
sql = 'PRAGMA index_list("{}")'.format(self.name)
indexes = []
for row in list(self.db.conn.execute(sql, (self.name,)).fetchall()):
column_sql = "select name from pragma_index_info(?) order by seqno"
columns = [
r[0] for r in self.db.conn.execute(column_sql, (row[1],)).fetchall()
]
for row in list(self.db.conn.execute(sql).fetchall()):
column_sql = 'PRAGMA index_info("{}")'.format(row[1])
columns = []
for seqno, cid, name in self.db.conn.execute(column_sql).fetchall():
columns.append(name)
indexes.append(Index(*(row + (columns,))))
return indexes