!23 rework: 解决uint数据类型查询报错
Merge pull request !23 from zcl/rework#bug#1
This commit is contained in:
@ -1332,7 +1332,7 @@ register_type_uint(connectionObject *self, PyThreadState **tstate)
|
|||||||
_typecast_INTEGER_types = (long int*)malloc((size+1)*sizeof(long int));
|
_typecast_INTEGER_types = (long int*)malloc((size+1)*sizeof(long int));
|
||||||
|
|
||||||
for (int i=0; i< size; i++) {
|
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;
|
_typecast_INTEGER_types[i] = (long int)uint_val;
|
||||||
}
|
}
|
||||||
typecastObject_initlist _typecast_builtins[] = {
|
typecastObject_initlist _typecast_builtins[] = {
|
||||||
|
|||||||
@ -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
|
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];
|
char query[256];
|
||||||
int size;
|
int size;
|
||||||
unsigned int rv = 0;
|
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)) {
|
if (size < 0 || (size_t)size >= sizeof(query)) {
|
||||||
conn_set_error(conn, "query too large");
|
conn_set_error(conn, "query too large");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -631,7 +632,7 @@ pq_get_custom_type_oid(connectionObject *conn, const char *param, PyThreadState
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!conn->pgres) {
|
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);
|
PyEval_RestoreThread(*tstate);
|
||||||
if (!PyErr_Occurred()) {
|
if (!PyErr_Occurred()) {
|
||||||
conn_set_error(conn, PQerrorMessage(conn->pgconn));
|
conn_set_error(conn, PQerrorMessage(conn->pgconn));
|
||||||
@ -640,7 +641,7 @@ pq_get_custom_type_oid(connectionObject *conn, const char *param, PyThreadState
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (PQresultStatus(conn->pgres) != PGRES_TUPLES_OK) {
|
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)));
|
PQresStatus(PQresultStatus(conn->pgres)));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user