Commit c99f8200 authored by Tom Lane's avatar Tom Lane

Tweak dblink functions to use int4 arguments instead of int2,

to avoid having to write explicit casts.  From Joe Conway.
parent 245b3d7d
......@@ -1002,6 +1002,9 @@ dblink_last_oid(PG_FUNCTION_ARGS)
}
#ifndef SHRT_MAX
#define SHRT_MAX (0x7FFF)
#endif
/*
* dblink_build_sql_insert
*
......@@ -1028,7 +1031,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
Oid relid;
text *relname_text;
int16 *pkattnums;
int16 pknumatts;
int pknumatts_tmp;
int16 pknumatts = 0;
char **src_pkattvals;
char **tgt_pkattvals;
ArrayType *src_pkattvals_arry;
......@@ -1057,7 +1061,11 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
elog(ERROR, "dblink_build_sql_insert: relation does not exist");
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts = PG_GETARG_INT16(2);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
/*
* There should be at least one key attribute
......@@ -1167,7 +1175,8 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
Oid relid;
text *relname_text;
int16 *pkattnums;
int16 pknumatts;
int pknumatts_tmp;
int16 pknumatts = 0;
char **tgt_pkattvals;
ArrayType *tgt_pkattvals_arry;
int tgt_ndim;
......@@ -1191,7 +1200,11 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
elog(ERROR, "dblink_build_sql_delete: relation does not exist");
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts = PG_GETARG_INT16(2);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
/*
* There should be at least one key attribute
......@@ -1274,7 +1287,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
Oid relid;
text *relname_text;
int16 *pkattnums;
int16 pknumatts;
int pknumatts_tmp;
int16 pknumatts = 0;
char **src_pkattvals;
char **tgt_pkattvals;
ArrayType *src_pkattvals_arry;
......@@ -1303,7 +1317,11 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
elog(ERROR, "dblink_build_sql_update: relation does not exist");
pkattnums = (int16 *) PG_GETARG_POINTER(1);
pknumatts = PG_GETARG_INT16(2);
pknumatts_tmp = PG_GETARG_INT32(2);
if (pknumatts_tmp <= SHRT_MAX)
pknumatts = pknumatts_tmp;
else
elog(ERROR, "Bad input value for pknumatts; too large");
/*
* There should be one source array key values for each key attnum
......
......@@ -57,15 +57,15 @@ CREATE OR REPLACE FUNCTION dblink_get_pkey (text) RETURNS setof dblink_pkey_resu
AS 'MODULE_PATHNAME','dblink_get_pkey' LANGUAGE 'c'
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_build_sql_insert (text, int2vector, int2, _text, _text) RETURNS text
CREATE OR REPLACE FUNCTION dblink_build_sql_insert (text, int2vector, int4, _text, _text) RETURNS text
AS 'MODULE_PATHNAME','dblink_build_sql_insert' LANGUAGE 'c'
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_build_sql_delete (text, int2vector, int2, _text) RETURNS text
CREATE OR REPLACE FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text) RETURNS text
AS 'MODULE_PATHNAME','dblink_build_sql_delete' LANGUAGE 'c'
WITH (isstrict);
CREATE OR REPLACE FUNCTION dblink_build_sql_update (text, int2vector, int2, _text, _text) RETURNS text
CREATE OR REPLACE FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text) RETURNS text
AS 'MODULE_PATHNAME','dblink_build_sql_update' LANGUAGE 'c'
WITH (isstrict);
......@@ -82,8 +82,8 @@ GRANT EXECUTE ON FUNCTION dblink (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_exec (text,text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_exec (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_get_pkey (text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_insert (text, int2vector, int2, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_delete (text, int2vector, int2, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_update (text, int2vector, int2, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_insert (text, int2vector, int4, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_delete (text, int2vector, int4, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_build_sql_update (text, int2vector, int4, _text, _text) TO PUBLIC;
GRANT EXECUTE ON FUNCTION dblink_current_query () TO PUBLIC;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment