From 02b4744efa7625c225b7b67aa66a3fd30f0f1d48 Mon Sep 17 00:00:00 2001 From: Jonathan Willitts Date: Fri, 21 Jun 2024 20:22:38 +0100 Subject: [PATCH] Add support for '#' and '-- ' comments in sql files --- edc_qareports/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/edc_qareports/utils.py b/edc_qareports/utils.py index 1f5adc4..f7f5d0e 100644 --- a/edc_qareports/utils.py +++ b/edc_qareports/utils.py @@ -10,6 +10,15 @@ def read_unmanaged_model_sql( ) -> str: if not fullpath: fullpath = Path(settings.BASE_DIR) / app_name / "models" / "unmanaged" / filename + + parsed_sql = [] with fullpath.open("r") as f: - sql = f.read() - return sql.replace("\n", " ") + for line in f: + line = line.split("#", maxsplit=1)[0] + line = line.split("-- ", maxsplit=1)[0] + line = line.replace("\n", "") + line = line.strip() + if line: + parsed_sql.append(line) + + return " ".join(parsed_sql)