version 1.25.4.6, 2008/01/03 21:28:55
|
version 1.25.4.7, 2010/02/03 23:02:27
|
Line 88 static Oid get_relid_from_relname(text *
|
Line 88 static Oid get_relid_from_relname(text *
|
static char *generate_relation_name(Oid relid); |
static char *generate_relation_name(Oid relid); |
static char *connstr_strip_password(const char *connstr); |
static char *connstr_strip_password(const char *connstr); |
static void dblink_security_check(PGconn *conn, remoteConn *rcon, const char *connstr); |
static void dblink_security_check(PGconn *conn, remoteConn *rcon, const char *connstr); |
|
static int get_nondropped_natts(Oid relid); |
|
|
/* Global */ |
/* Global */ |
List *res_id = NIL; |
List *res_id = NIL; |
Line 985 dblink_build_sql_insert(PG_FUNCTION_ARGS
|
Line 986 dblink_build_sql_insert(PG_FUNCTION_ARGS
|
int16 typlen; |
int16 typlen; |
bool typbyval; |
bool typbyval; |
char typalign; |
char typalign; |
|
int nondropped_natts; |
|
|
relname_text = PG_GETARG_TEXT_P(0); |
relname_text = PG_GETARG_TEXT_P(0); |
|
|
Line 1016 dblink_build_sql_insert(PG_FUNCTION_ARGS
|
Line 1018 dblink_build_sql_insert(PG_FUNCTION_ARGS
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
errmsg("number of key attributes must be > 0"))); |
errmsg("number of key attributes must be > 0"))); |
|
|
|
/* |
|
* ensure we don't ask for more pk attributes than we have |
|
* non-dropped columns |
|
*/ |
|
nondropped_natts = get_nondropped_natts(relid); |
|
if (pknumatts > nondropped_natts) |
|
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), |
|
errmsg("number of primary key fields exceeds number of specified relation attributes"))); |
|
|
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); |
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); |
|
|
Line 1132 dblink_build_sql_delete(PG_FUNCTION_ARGS
|
Line 1143 dblink_build_sql_delete(PG_FUNCTION_ARGS
|
int16 typlen; |
int16 typlen; |
bool typbyval; |
bool typbyval; |
char typalign; |
char typalign; |
|
int nondropped_natts; |
|
|
relname_text = PG_GETARG_TEXT_P(0); |
relname_text = PG_GETARG_TEXT_P(0); |
|
|
Line 1163 dblink_build_sql_delete(PG_FUNCTION_ARGS
|
Line 1175 dblink_build_sql_delete(PG_FUNCTION_ARGS
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
errmsg("number of key attributes must be > 0"))); |
errmsg("number of key attributes must be > 0"))); |
|
|
|
/* |
|
* ensure we don't ask for more pk attributes than we have |
|
* non-dropped columns |
|
*/ |
|
nondropped_natts = get_nondropped_natts(relid); |
|
if (pknumatts > nondropped_natts) |
|
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), |
|
errmsg("number of primary key fields exceeds number of specified relation attributes"))); |
|
|
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
|
|
/* |
/* |
Line 1254 dblink_build_sql_update(PG_FUNCTION_ARGS
|
Line 1275 dblink_build_sql_update(PG_FUNCTION_ARGS
|
int16 typlen; |
int16 typlen; |
bool typbyval; |
bool typbyval; |
char typalign; |
char typalign; |
|
int nondropped_natts; |
|
|
relname_text = PG_GETARG_TEXT_P(0); |
relname_text = PG_GETARG_TEXT_P(0); |
|
|
Line 1285 dblink_build_sql_update(PG_FUNCTION_ARGS
|
Line 1307 dblink_build_sql_update(PG_FUNCTION_ARGS
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
errmsg("number of key attributes must be > 0"))); |
errmsg("number of key attributes must be > 0"))); |
|
|
|
/* |
|
* ensure we don't ask for more pk attributes than we have |
|
* non-dropped columns |
|
*/ |
|
nondropped_natts = get_nondropped_natts(relid); |
|
if (pknumatts > nondropped_natts) |
|
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), |
|
errmsg("number of primary key fields exceeds number of specified relation attributes"))); |
|
|
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
src_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); |
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); |
tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); |
|
|
Line 2134 dblink_security_check(PGconn *conn, remo
|
Line 2165 dblink_security_check(PGconn *conn, remo
|
PQfinish(conn); |
PQfinish(conn); |
} |
} |
} |
} |
|
|
|
static int |
|
get_nondropped_natts(Oid relid) |
|
{ |
|
int nondropped_natts = 0; |
|
TupleDesc tupdesc; |
|
Relation rel; |
|
int natts; |
|
int i; |
|
|
|
rel = relation_open(relid, AccessShareLock); |
|
tupdesc = rel->rd_att; |
|
natts = tupdesc->natts; |
|
|
|
for (i = 0; i < natts; i++) |
|
{ |
|
if (tupdesc->attrs[i]->attisdropped) |
|
continue; |
|
nondropped_natts++; |
|
} |
|
|
|
relation_close(rel, AccessShareLock); |
|
return nondropped_natts; |
|
} |