Move handling of missing table outside of do_query

This is more consistent with other DB migration code and reduces indent
level in the meat of the query.

Change-Id: I536a8425f7e9f3dd95eacad783e1b7d7905b2b8d
This commit is contained in:
Tim Burke 2018-05-22 12:58:39 -07:00
parent 53f418f919
commit f68dd3bf10

View File

@ -1627,7 +1627,6 @@ class ContainerBroker(DatabaseBroker):
included_states.add(states)
def do_query(conn):
try:
condition = ''
conditions = []
params = []
@ -1648,21 +1647,21 @@ class ContainerBroker(DatabaseBroker):
sql = '''
SELECT %s
FROM %s%s;
''' % (', '.join(SHARD_RANGE_KEYS), SHARD_RANGE_TABLE,
condition)
''' % (', '.join(SHARD_RANGE_KEYS), SHARD_RANGE_TABLE, condition)
data = conn.execute(sql, params)
data.row_factory = None
return [row for row in data]
except sqlite3.OperationalError as err:
if ('no such table: %s' % SHARD_RANGE_TABLE) not in str(err):
raise
return []
try:
if connection:
return do_query(connection)
else:
with self.get() as conn:
return do_query(conn)
except sqlite3.OperationalError as err:
if ('no such table: %s' % SHARD_RANGE_TABLE) not in str(err):
raise
return []
@classmethod
def resolve_shard_range_states(cls, states):