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