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:
@@ -1627,42 +1627,41 @@ class ContainerBroker(DatabaseBroker):
|
|||||||
included_states.add(states)
|
included_states.add(states)
|
||||||
|
|
||||||
def do_query(conn):
|
def do_query(conn):
|
||||||
try:
|
condition = ''
|
||||||
condition = ''
|
conditions = []
|
||||||
conditions = []
|
params = []
|
||||||
params = []
|
if not include_deleted:
|
||||||
if not include_deleted:
|
conditions.append('deleted=0')
|
||||||
conditions.append('deleted=0')
|
if included_states:
|
||||||
if included_states:
|
conditions.append('state in (%s)' % ','.join(
|
||||||
conditions.append('state in (%s)' % ','.join(
|
'?' * len(included_states)))
|
||||||
'?' * len(included_states)))
|
params.extend(included_states)
|
||||||
params.extend(included_states)
|
if not include_own:
|
||||||
if not include_own:
|
conditions.append('name != ?')
|
||||||
conditions.append('name != ?')
|
params.append(self.path)
|
||||||
params.append(self.path)
|
if exclude_others:
|
||||||
if exclude_others:
|
conditions.append('name = ?')
|
||||||
conditions.append('name = ?')
|
params.append(self.path)
|
||||||
params.append(self.path)
|
if conditions:
|
||||||
if conditions:
|
condition = ' WHERE ' + ' AND '.join(conditions)
|
||||||
condition = ' WHERE ' + ' AND '.join(conditions)
|
sql = '''
|
||||||
sql = '''
|
SELECT %s
|
||||||
SELECT %s
|
FROM %s%s;
|
||||||
FROM %s%s;
|
''' % (', '.join(SHARD_RANGE_KEYS), SHARD_RANGE_TABLE, condition)
|
||||||
''' % (', '.join(SHARD_RANGE_KEYS), SHARD_RANGE_TABLE,
|
data = conn.execute(sql, params)
|
||||||
condition)
|
data.row_factory = None
|
||||||
data = conn.execute(sql, params)
|
return [row for row in data]
|
||||||
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 []
|
|
||||||
|
|
||||||
if connection:
|
try:
|
||||||
return do_query(connection)
|
if connection:
|
||||||
else:
|
return do_query(connection)
|
||||||
with self.get() as conn:
|
else:
|
||||||
return do_query(conn)
|
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
|
@classmethod
|
||||||
def resolve_shard_range_states(cls, states):
|
def resolve_shard_range_states(cls, states):
|
||||||
|
|||||||
Reference in New Issue
Block a user