commit 599835e7fd7e07fe45bdec2ea11a13b251450528
parent 0ac54eb48d9be1be815df2e66cc163be776b15eb
Author: Joris Vink <joris@coders.se>
Date: Mon, 6 Sep 2021 15:39:38 +0200
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.
Diffstat:
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git 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;