From e26076cc61fb183fa7c478377b7dcf775d1f1717 Mon Sep 17 00:00:00 2001 From: BenediktSeidlSWM Date: Mon, 14 Oct 2024 10:52:36 +0200 Subject: [PATCH] Support multiple values in SQL query (#12) 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. --- schemas/qwc-mapinfo-service.json | 5 ++++- src/server.py | 19 ++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/schemas/qwc-mapinfo-service.json b/schemas/qwc-mapinfo-service.json index bac7edc..166416d 100644 --- a/schemas/qwc-mapinfo-service.json +++ b/schemas/qwc-mapinfo-service.json @@ -38,7 +38,10 @@ }, "info_title": { "description": "Display title", - "type": "string" + "type": ["string", "array"], + "items": { + "type": "string" + } }, "info_where": { "description": "Additional WHERE query", diff --git a/src/server.py b/src/server.py index 948a086..d4cea30 100644 --- a/src/server.py +++ b/src/server.py @@ -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')) @@ -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