From f3a182e1bb118467a1ffc23336b2262090af4bca Mon Sep 17 00:00:00 2001 From: zcl Date: Wed, 27 Mar 2024 16:03:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A=E5=92=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改查询oid的值的sql语句 --- psycopg/connection_type.c | 2 +- psycopg/pqpath.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 33f4adc..1672c99 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -1332,7 +1332,7 @@ register_type_uint(connectionObject *self, PyThreadState **tstate) _typecast_INTEGER_types = (long int*)malloc((size+1)*sizeof(long int)); for (int i=0; i< size; i++) { - unsigned int uint_val = pq_get_custom_type_oid(self, uint_arr[i], tstate); + unsigned int uint_val = pq_get_pg_catalog_custom_type_oid(self, uint_arr[i], tstate); _typecast_INTEGER_types[i] = (long int)uint_val; } typecastObject_initlist _typecast_builtins[] = { diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 723ee6f..03fc0c0 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -608,15 +608,16 @@ cleanup: } +/* Get the oid of uint type created by the dolphin plugin, which is only in the pg_catalog by default */ unsigned int -pq_get_custom_type_oid(connectionObject *conn, const char *param, PyThreadState **tstate) +pq_get_pg_catalog_custom_type_oid(connectionObject *conn, const char *param, PyThreadState **tstate) { char query[256]; int size; unsigned int rv = 0; - size = PyOS_snprintf(query, sizeof(query), "select oid from pg_type where typname= %s", param); + size = PyOS_snprintf(query, sizeof(query), "select oid from pg_type where typnamespace = 11 and typname= %s", param); if (size < 0 || (size_t)size >= sizeof(query)) { conn_set_error(conn, "query too large"); goto cleanup; @@ -631,7 +632,7 @@ pq_get_custom_type_oid(connectionObject *conn, const char *param, PyThreadState } if (!conn->pgres) { - Dprintf("pq_get_custom_type_oid: PQexec returned NULL"); + Dprintf("pq_get_pg_catalog_custom_type_oid: PQexec returned NULL"); PyEval_RestoreThread(*tstate); if (!PyErr_Occurred()) { conn_set_error(conn, PQerrorMessage(conn->pgconn)); @@ -640,7 +641,7 @@ pq_get_custom_type_oid(connectionObject *conn, const char *param, PyThreadState goto cleanup; } if (PQresultStatus(conn->pgres) != PGRES_TUPLES_OK) { - Dprintf("pq_get_custom_type_oid: result was not TUPLES_OK (%s)", + Dprintf("pq_get_pg_catalog_custom_type_oid: result was not TUPLES_OK (%s)", PQresStatus(PQresultStatus(conn->pgres))); goto cleanup; }