From 599835e7fd7e07fe45bdec2ea11a13b251450528 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Mon, 6 Sep 2021 15:39:38 +0200 Subject: [PATCH] Python: Only use parameters if needed. We always called kore_pgsql_query_param_fields() regardless if the params keyword was specified or not, instead only use it if actual parameters have been given. Otherwise use the kore_pgsql_query() function directly to execute the query. --- src/python.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/python.c b/src/python.c index 8f5d270..6540693 100644 --- a/src/python.c +++ b/src/python.c @@ -5595,13 +5595,21 @@ pykore_pgsql_iternext(struct pykore_pgsql *pysql) } /* fallthrough */ case PYKORE_PGSQL_QUERY: - if (!kore_pgsql_query_param_fields(&pysql->sql, - pysql->query, pysql->binary, - pysql->param.count, pysql->param.values, - pysql->param.lengths, pysql->param.formats)) { - PyErr_Format(PyExc_RuntimeError, - "pgsql error: %s", pysql->sql.error); - return (NULL); + if (pysql->param.count > 0) { + if (!kore_pgsql_query_param_fields(&pysql->sql, + pysql->query, pysql->binary, + pysql->param.count, pysql->param.values, + pysql->param.lengths, pysql->param.formats)) { + PyErr_Format(PyExc_RuntimeError, + "pgsql error: %s", pysql->sql.error); + return (NULL); + } + } else { + if (!kore_pgsql_query(&pysql->sql, pysql->query)) { + PyErr_Format(PyExc_RuntimeError, + "pgsql error: %s", pysql->sql.error); + return (NULL); + } } pysql->state = PYKORE_PGSQL_WAIT; break;