From 88e051bd31c491ffead08d4d4951945063835ab6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 16 Oct 2023 14:43:33 +0300 Subject: Fix bug: parsing fields from query. --- scripts/insert_data.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/insert_data.py b/scripts/insert_data.py index 7bf20f1..f273c3a 100644 --- a/scripts/insert_data.py +++ b/scripts/insert_data.py @@ -114,12 +114,11 @@ def __format_query__(query, params): def __param_str__(param): return "', '".join(str(elt) for elt in param) idx = query.find("VALUES") + idx = query.find("%") fields = tuple( - elt.strip().replace("%(", "").replace(")s", "") - for elt in query[idx + 7:-1].split(",")) - values = ( - tuple(param[field] for field in fields) - for param in params) + elt.replace("%(", "").replace(")s", "").replace(")", "").strip() + for elt in query[idx:-1].split(",")) + values = (tuple(param[field] for field in fields) for param in params) values_str = ", ".join( f"('{__param_str__(value_tup)}')" for value_tup in values) insert_str = query[:idx].replace( -- cgit v1.2.3