17
17
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
18
18
* Portions Copyright (c) 1994, Regents of the University of California
19
19
*
20
- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.395 2009/10/28 14:55:43 tgl Exp $
20
+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.396 2009/10/31 01:41:31 tgl Exp $
21
21
*
22
22
*-------------------------------------------------------------------------
23
23
*/
35
35
#include "parser/parse_coerce.h"
36
36
#include "parser/parse_cte.h"
37
37
#include "parser/parse_oper.h"
38
+ #include "parser/parse_param.h"
38
39
#include "parser/parse_relation.h"
39
40
#include "parser/parse_target.h"
40
41
#include "parser/parsetree.h"
@@ -62,7 +63,6 @@ static Query *transformExplainStmt(ParseState *pstate,
62
63
ExplainStmt * stmt );
63
64
static void transformLockingClause (ParseState * pstate , Query * qry ,
64
65
LockingClause * lc , bool pushedDown );
65
- static bool check_parameter_resolution_walker (Node * node , ParseState * pstate );
66
66
67
67
68
68
/*
@@ -86,9 +86,9 @@ parse_analyze(Node *parseTree, const char *sourceText,
86
86
Assert (sourceText != NULL ); /* required as of 8.4 */
87
87
88
88
pstate -> p_sourcetext = sourceText ;
89
- pstate -> p_paramtypes = paramTypes ;
90
- pstate -> p_numparams = numParams ;
91
- pstate -> p_variableparams = false ;
89
+
90
+ if ( numParams > 0 )
91
+ parse_fixed_parameters ( pstate , paramTypes , numParams ) ;
92
92
93
93
query = transformStmt (pstate , parseTree );
94
94
@@ -114,18 +114,13 @@ parse_analyze_varparams(Node *parseTree, const char *sourceText,
114
114
Assert (sourceText != NULL ); /* required as of 8.4 */
115
115
116
116
pstate -> p_sourcetext = sourceText ;
117
- pstate -> p_paramtypes = * paramTypes ;
118
- pstate -> p_numparams = * numParams ;
119
- pstate -> p_variableparams = true;
117
+
118
+ parse_variable_parameters (pstate , paramTypes , numParams );
120
119
121
120
query = transformStmt (pstate , parseTree );
122
121
123
122
/* make sure all is well with parameter types */
124
- if (pstate -> p_numparams > 0 )
125
- check_parameter_resolution_walker ((Node * ) query , pstate );
126
-
127
- * paramTypes = pstate -> p_paramtypes ;
128
- * numParams = pstate -> p_numparams ;
123
+ check_variable_parameters (pstate , query );
129
124
130
125
free_parsestate (pstate );
131
126
@@ -1982,7 +1977,7 @@ transformDeclareCursorStmt(ParseState *pstate, DeclareCursorStmt *stmt)
1982
1977
*
1983
1978
* EXPLAIN is just like other utility statements in that we emit it as a
1984
1979
* CMD_UTILITY Query node with no transformation of the raw parse tree.
1985
- * However, if p_variableparams is set, it could be that the client is
1980
+ * However, if p_coerce_param_hook is set, it could be that the client is
1986
1981
* expecting us to resolve parameter types in something like
1987
1982
* EXPLAIN SELECT * FROM tab WHERE col = $1
1988
1983
* To deal with such cases, we run parse analysis and throw away the result;
@@ -1996,7 +1991,7 @@ transformExplainStmt(ParseState *pstate, ExplainStmt *stmt)
1996
1991
{
1997
1992
Query * result ;
1998
1993
1999
- if (pstate -> p_variableparams )
1994
+ if (pstate -> p_coerce_param_hook != NULL )
2000
1995
{
2001
1996
/* Since parse analysis scribbles on its input, copy the tree first! */
2002
1997
(void ) transformStmt (pstate , copyObject (stmt -> query ));
@@ -2239,50 +2234,3 @@ applyLockingClause(Query *qry, Index rtindex,
2239
2234
rc -> pushedDown = pushedDown ;
2240
2235
qry -> rowMarks = lappend (qry -> rowMarks , rc );
2241
2236
}
2242
-
2243
-
2244
- /*
2245
- * Traverse a fully-analyzed tree to verify that parameter symbols
2246
- * match their types. We need this because some Params might still
2247
- * be UNKNOWN, if there wasn't anything to force their coercion,
2248
- * and yet other instances seen later might have gotten coerced.
2249
- */
2250
- static bool
2251
- check_parameter_resolution_walker (Node * node , ParseState * pstate )
2252
- {
2253
- if (node == NULL )
2254
- return false;
2255
- if (IsA (node , Param ))
2256
- {
2257
- Param * param = (Param * ) node ;
2258
-
2259
- if (param -> paramkind == PARAM_EXTERN )
2260
- {
2261
- int paramno = param -> paramid ;
2262
-
2263
- if (paramno <= 0 || /* shouldn't happen, but... */
2264
- paramno > pstate -> p_numparams )
2265
- ereport (ERROR ,
2266
- (errcode (ERRCODE_UNDEFINED_PARAMETER ),
2267
- errmsg ("there is no parameter $%d" , paramno ),
2268
- parser_errposition (pstate , param -> location )));
2269
-
2270
- if (param -> paramtype != pstate -> p_paramtypes [paramno - 1 ])
2271
- ereport (ERROR ,
2272
- (errcode (ERRCODE_AMBIGUOUS_PARAMETER ),
2273
- errmsg ("could not determine data type of parameter $%d" ,
2274
- paramno ),
2275
- parser_errposition (pstate , param -> location )));
2276
- }
2277
- return false;
2278
- }
2279
- if (IsA (node , Query ))
2280
- {
2281
- /* Recurse into RTE subquery or not-yet-planned sublink subquery */
2282
- return query_tree_walker ((Query * ) node ,
2283
- check_parameter_resolution_walker ,
2284
- (void * ) pstate , 0 );
2285
- }
2286
- return expression_tree_walker (node , check_parameter_resolution_walker ,
2287
- (void * ) pstate );
2288
- }
0 commit comments