From 664baaa8c6bf77137d05c84584f1dff7c7cafc10 Mon Sep 17 00:00:00 2001 From: zhangting Date: Fri, 20 Dec 2024 17:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3sql=E9=87=8C=E6=9C=89?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D=E7=AC=A6=E5=8F=82=E6=95=B0=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BD=BF=E7=94=A8=E4=BA=86%=E8=BF=90?= =?UTF-8?q?=E7=AE=97=E7=AC=A6=E6=89=A7=E8=A1=8C=E6=8A=A5=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psycopg/bytes_format.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/psycopg/bytes_format.c b/psycopg/bytes_format.c index 0264a6d..c00db88 100644 --- a/psycopg/bytes_format.c +++ b/psycopg/bytes_format.c @@ -223,6 +223,20 @@ PyObject *Bytes_Format(PyObject *format, PyObject *args, char place_holder) { args_owned = 1; arglen = -1; // exists place holder as "%(name)s", set these arguments to invalid argidx = -2; + } else { + char c = *fmt; + if (!rescnt) { + rescnt += reslen; + reslen *= 2; + if ((result = resize_bytes(result, reslen)) == NULL) goto error; + res = Bytes_AS_STRING(result) + reslen - rescnt; + } + if (c == '%' || c == ' ') { // '%%' will be transfered to '%' + *res = '%'; + --rescnt; + ++res; + ++fmt; + } } } /* '%' */ } /* until end */ @@ -289,14 +303,14 @@ PyObject *Bytes_Format(PyObject *format, PyObject *args, char place_holder) { PyErr_SetString(PyExc_ValueError, "incomplete format"); goto error; } - else if (c == '%') { // '%%' will be transfered to '%' + else if (c == '%' || c == ' ') { // '%%' will be transfered to '%' if (!rescnt) { rescnt += reslen; reslen *= 2; if ((result = resize_bytes(result, reslen)) == NULL) goto error; res = Bytes_AS_STRING(result) + reslen - rescnt; } - *res = c; + *res = '%'; --rescnt; ++res; ++fmt; -- Gitee