mirror of
https://github.com/postgres/postgres.git
synced 2026-05-28 04:35:45 -04:00
Be more careful about int vs. Oid in ecpglib.
Print an OID value inserted into a SQL query with %u not %d. The existing code accidentally fails to malfunction when given an OID above 2^31, but only accidentally; future changes to our SQL parser could perhaps break it. Declare the Oid values that ecpg_type_infocache_push() and ecpg_is_type_an_array() work with as "Oid" not "int". This doesn't have any functional effect, but it's clearer. At the moment I don't see a need to back-patch this. Bug: #19429 Author: fairyfar@msn.com Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/19429-aead3b1874be1a99@postgresql.org
This commit is contained in:
parent
c456e39113
commit
c675d80d72
2 changed files with 6 additions and 5 deletions
|
|
@ -52,7 +52,7 @@ struct ECPGgeneric_bytea
|
|||
struct ECPGtype_information_cache
|
||||
{
|
||||
struct ECPGtype_information_cache *next;
|
||||
int oid;
|
||||
Oid oid;
|
||||
enum ARRAY_TYPE isarray;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ next_insert(char *text, int pos, bool questionmarks, bool std_strings)
|
|||
}
|
||||
|
||||
static bool
|
||||
ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enum ARRAY_TYPE isarray, int lineno)
|
||||
ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, Oid oid, enum ARRAY_TYPE isarray, int lineno)
|
||||
{
|
||||
struct ECPGtype_information_cache *new_entry
|
||||
= (struct ECPGtype_information_cache *) ecpg_alloc(sizeof(struct ECPGtype_information_cache), lineno);
|
||||
|
|
@ -161,7 +161,7 @@ ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enu
|
|||
}
|
||||
|
||||
static enum ARRAY_TYPE
|
||||
ecpg_is_type_an_array(int type, const struct statement *stmt, const struct variable *var)
|
||||
ecpg_is_type_an_array(Oid type, const struct statement *stmt, const struct variable *var)
|
||||
{
|
||||
char *array_query;
|
||||
enum ARRAY_TYPE isarray = ECPG_ARRAY_NOT_SET;
|
||||
|
|
@ -267,7 +267,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
|
|||
if (array_query == NULL)
|
||||
return ECPG_ARRAY_ERROR;
|
||||
|
||||
sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type);
|
||||
sprintf(array_query, "select typlen from pg_type where oid=%u and typelem<>0", type);
|
||||
query = PQexec(stmt->connection->connection, array_query);
|
||||
ecpg_free(array_query);
|
||||
if (!ecpg_check_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
|
||||
|
|
@ -294,7 +294,8 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
|
|||
return ECPG_ARRAY_ERROR;
|
||||
|
||||
ecpg_type_infocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
|
||||
ecpg_log("ecpg_is_type_an_array on line %d: type (%d); C (%d); array (%s)\n", stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
|
||||
ecpg_log("ecpg_is_type_an_array on line %d: type (%u); C (%d); array (%s)\n",
|
||||
stmt->lineno, type, var->type, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
|
||||
return isarray;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue