~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/nodes/params.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * params.c
 
4
 *        Support functions for plan parameter lists.
 
5
 *
 
6
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 * IDENTIFICATION
 
10
 *        $PostgreSQL: pgsql/src/backend/nodes/params.c,v 1.4 2004-12-31 21:59:55 pgsql Exp $
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
 
 
15
#include "postgres.h"
 
16
 
 
17
#include "nodes/params.h"
 
18
#include "utils/datum.h"
 
19
#include "utils/lsyscache.h"
 
20
 
 
21
 
 
22
/*
 
23
 * Copy a ParamList.
 
24
 *
 
25
 * The result is allocated in CurrentMemoryContext.
 
26
 */
 
27
ParamListInfo
 
28
copyParamList(ParamListInfo from)
 
29
{
 
30
        ParamListInfo retval;
 
31
        int                     i,
 
32
                                size;
 
33
 
 
34
        if (from == NULL)
 
35
                return NULL;
 
36
 
 
37
        size = 0;
 
38
        while (from[size].kind != PARAM_INVALID)
 
39
                size++;
 
40
 
 
41
        retval = (ParamListInfo) palloc0((size + 1) * sizeof(ParamListInfoData));
 
42
 
 
43
        for (i = 0; i < size; i++)
 
44
        {
 
45
                /* copy metadata */
 
46
                retval[i].kind = from[i].kind;
 
47
                if (from[i].kind == PARAM_NAMED)
 
48
                        retval[i].name = pstrdup(from[i].name);
 
49
                retval[i].id = from[i].id;
 
50
                retval[i].ptype = from[i].ptype;
 
51
 
 
52
                /* copy value */
 
53
                retval[i].isnull = from[i].isnull;
 
54
                if (from[i].isnull)
 
55
                {
 
56
                        retval[i].value = from[i].value;        /* nulls just copy */
 
57
                }
 
58
                else
 
59
                {
 
60
                        int16           typLen;
 
61
                        bool            typByVal;
 
62
 
 
63
                        get_typlenbyval(from[i].ptype, &typLen, &typByVal);
 
64
                        retval[i].value = datumCopy(from[i].value, typByVal, typLen);
 
65
                }
 
66
        }
 
67
 
 
68
        retval[size].kind = PARAM_INVALID;
 
69
 
 
70
        return retval;
 
71
}
 
72
 
 
73
/*
 
74
 * Search a ParamList for a given parameter.
 
75
 *
 
76
 * On success, returns a pointer to the parameter's entry.
 
77
 * On failure, returns NULL if noError is true, else ereports the error.
 
78
 */
 
79
ParamListInfo
 
80
lookupParam(ParamListInfo paramList, int thisParamKind,
 
81
                        const char *thisParamName, AttrNumber thisParamId,
 
82
                        bool noError)
 
83
{
 
84
        if (paramList != NULL)
 
85
        {
 
86
                while (paramList->kind != PARAM_INVALID)
 
87
                {
 
88
                        if (thisParamKind == paramList->kind)
 
89
                        {
 
90
                                switch (thisParamKind)
 
91
                                {
 
92
                                        case PARAM_NAMED:
 
93
                                                if (strcmp(paramList->name, thisParamName) == 0)
 
94
                                                        return paramList;
 
95
                                                break;
 
96
                                        case PARAM_NUM:
 
97
                                                if (paramList->id == thisParamId)
 
98
                                                        return paramList;
 
99
                                                break;
 
100
                                        default:
 
101
                                                elog(ERROR, "unrecognized paramkind: %d",
 
102
                                                         thisParamKind);
 
103
                                }
 
104
                        }
 
105
                        paramList++;
 
106
                }
 
107
        }
 
108
 
 
109
        if (!noError)
 
110
        {
 
111
                if (thisParamKind == PARAM_NAMED)
 
112
                        ereport(ERROR,
 
113
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
 
114
                                         errmsg("no value found for parameter \"%s\"",
 
115
                                                        thisParamName)));
 
116
                else
 
117
                        ereport(ERROR,
 
118
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
 
119
                                         errmsg("no value found for parameter %d",
 
120
                                                        thisParamId)));
 
121
        }
 
122
 
 
123
        return NULL;
 
124
}