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.
This commit is contained in:
Joris Vink 2021-09-06 15:39:38 +02:00
parent 0ac54eb48d
commit 599835e7fd
1 changed files with 15 additions and 7 deletions

View File

@ -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;