~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/pl/plpgsql/src/pl_comp.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-06-14 09:53:29 UTC
  • mto: (6.1.1 sid) (10.1.1 oneiric-proposed) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20110614095329-71gfhjywyp2c27au
Tags: upstream-9.1~beta2
ImportĀ upstreamĀ versionĀ 9.1~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
                   PLpgSQL_func_hashkey *hashkey,
96
96
                   bool forValidator);
97
97
static void plpgsql_compile_error_callback(void *arg);
 
98
static void add_parameter_name(int itemtype, int itemno, const char *name);
98
99
static void add_dummy_return(PLpgSQL_function *function);
99
100
static Node *plpgsql_pre_column_ref(ParseState *pstate, ColumnRef *cref);
100
101
static Node *plpgsql_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var);
451
452
                                        out_arg_variables[num_out_args++] = argvariable;
452
453
 
453
454
                                /* Add to namespace under the $n name */
454
 
                                plpgsql_ns_additem(argitemtype, argvariable->dno, buf);
 
455
                                add_parameter_name(argitemtype, argvariable->dno, buf);
455
456
 
456
457
                                /* If there's a name for the argument, make an alias */
457
458
                                if (argnames && argnames[i][0] != '\0')
458
 
                                        plpgsql_ns_additem(argitemtype, argvariable->dno,
 
459
                                        add_parameter_name(argitemtype, argvariable->dno,
459
460
                                                                           argnames[i]);
460
461
                        }
461
462
 
914
915
 
915
916
 
916
917
/*
 
918
 * Add a name for a function parameter to the function's namespace
 
919
 */
 
920
static void
 
921
add_parameter_name(int itemtype, int itemno, const char *name)
 
922
{
 
923
        /*
 
924
         * Before adding the name, check for duplicates.  We need this even though
 
925
         * functioncmds.c has a similar check, because that code explicitly
 
926
         * doesn't complain about conflicting IN and OUT parameter names.  In
 
927
         * plpgsql, such names are in the same namespace, so there is no way to
 
928
         * disambiguate.
 
929
         */
 
930
        if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
 
931
                                                  name, NULL, NULL,
 
932
                                                  NULL) != NULL)
 
933
                ereport(ERROR,
 
934
                                (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
 
935
                                 errmsg("parameter name \"%s\" used more than once",
 
936
                                                name)));
 
937
 
 
938
        /* OK, add the name */
 
939
        plpgsql_ns_additem(itemtype, itemno, name);
 
940
}
 
941
 
 
942
/*
917
943
 * Add a dummy RETURN statement to the given function's body
918
944
 */
919
945
static void
1267
1293
        param = makeNode(Param);
1268
1294
        param->paramkind = PARAM_EXTERN;
1269
1295
        param->paramid = dno + 1;
1270
 
        param->paramtype = exec_get_datum_type(estate, datum);
1271
 
        param->paramtypmod = -1;
1272
 
        param->paramcollid = exec_get_datum_collation(estate, datum);
 
1296
        exec_get_datum_type_info(estate,
 
1297
                                                         datum,
 
1298
                                                         &param->paramtype,
 
1299
                                                         &param->paramtypmod,
 
1300
                                                         &param->paramcollid);
1273
1301
        param->location = location;
1274
1302
 
1275
1303
        return (Node *) param;