Added function to split an assignment expression
In the UI, a common pattern was to check if a query was prefixed by an assignment and in that case, assign the result to the given name. This function puts this in a common place, so it can be used from all the parts where it is needed.
This commit is contained in:
parent
53b158d25e
commit
e3877a4682
@ -162,6 +162,23 @@ class UserInterface (object):
|
|||||||
self.relations[relname] = result
|
self.relations[relname] = result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def split_query(query, default_name='last_'):
|
||||||
|
'''
|
||||||
|
Accepts a query which might have an initial value
|
||||||
|
assignment
|
||||||
|
a = query
|
||||||
|
|
||||||
|
Returns a tuple with
|
||||||
|
|
||||||
|
result_name, query
|
||||||
|
'''
|
||||||
|
sq = query.split('=', 1)
|
||||||
|
if len(sq) == 2 and is_valid_relation_name(sq[0].strip()):
|
||||||
|
default_name = sq[0].strip()
|
||||||
|
query = sq[1].strip()
|
||||||
|
return default_name, query
|
||||||
|
|
||||||
def multi_execute(self, query):
|
def multi_execute(self, query):
|
||||||
'''Executes multiple queries, separated by \n
|
'''Executes multiple queries, separated by \n
|
||||||
|
|
||||||
@ -174,12 +191,8 @@ class UserInterface (object):
|
|||||||
for query in queries:
|
for query in queries:
|
||||||
if query.strip() == '':
|
if query.strip() == '':
|
||||||
continue
|
continue
|
||||||
parts = query.split('=', 1)
|
|
||||||
parts[0] = parts[0].strip()
|
relname, query = self.split_query(query)
|
||||||
if len(parts) > 1 and is_valid_relation_name(parts[0]):
|
|
||||||
relname, query = parts
|
|
||||||
else:
|
|
||||||
relname = 'last_'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = self.execute(query, relname)
|
r = self.execute(query, relname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user