Skip to content

Commit

Permalink
Support multiple values in SQL query (#12)
Browse files Browse the repository at this point in the history
This commit adds support for multiple values in the info_title field
which correspond to a list of columns that are returned by an info_sql
query. The length of the info_title list must match the number of
columns generated by the query.
  • Loading branch information
BenediktSeidlSWM authored Oct 14, 2024
1 parent e578e02 commit e26076c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 4 additions & 1 deletion schemas/qwc-mapinfo-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
},
"info_title": {
"description": "Display title",
"type": "string"
"type": ["string", "array"],
"items": {
"type": "string"
}
},
"info_where": {
"description": "Additional WHERE query",
Expand Down
19 changes: 8 additions & 11 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,16 @@ def get(self):

info_result = []

queries = config.get('queries')
if queries is not None:
for config in queries:
result = self.__process_query(config, pos, srid)
if result:
info_result.append(result)
else:
queries = config.get('queries') or [config]

for config in queries:
result = self.__process_query(config, pos, srid)
if result:
info_result.append(result)
info_result.extend(result)

return jsonify({"results": info_result})

def __process_query(self, config, pos, srid):

info_title = config.get('info_title')
if config.get('info_sql') is not None:
sql = sql_text(config.get('info_sql'))
Expand Down Expand Up @@ -123,9 +118,11 @@ def __process_query(self, config, pos, srid):
if row is None:
return_value = None
elif config.get('info_sql') is not None:
return_value = [info_title, row[list(result.keys())[0]]]
if not isinstance(info_title, list):
info_title = [info_title]
return_value = [list(t) for t in zip(info_title, row.values())]
else:
return_value = [info_title, row[info_display_col]]
return_value = [[info_title, row[info_display_col]]]

return return_value

Expand Down

0 comments on commit e26076c

Please sign in to comment.