mirror of
https://github.com/postgres/postgres.git
synced 2025-08-14 02:22:38 +03:00
Infrastructure for deducing Param types from context, in the same way
that the types of untyped string-literal constants are deduced (ie, when coerce_type is applied to 'em, that's what the type must be). Remove the ancient hack of storing the input Param-types array as a global variable, and put the info into ParseState instead. This touches a lot of files because of adjustment of routine parameter lists, but it's really not a large patch. Note: PREPARE statement still insists on exact specification of parameter types, but that could easily be relaxed now, if we wanted to do so.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.56 2003/04/27 20:09:44 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.57 2003/04/29 22:13:10 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -30,32 +30,27 @@
|
||||
|
||||
List *parsetree; /* result of parsing is left here */
|
||||
|
||||
static Oid *param_type_info; /* state for param_type() */
|
||||
static int param_count;
|
||||
|
||||
static int lookahead_token; /* one-token lookahead */
|
||||
static bool have_lookahead; /* lookahead_token set? */
|
||||
|
||||
|
||||
/*
|
||||
* parser
|
||||
* Given a query in string form, and optionally info about
|
||||
* parameter types, do lexical and syntactic analysis.
|
||||
* raw_parser
|
||||
* Given a query in string form, do lexical and grammatical analysis.
|
||||
*
|
||||
* Returns a list of raw (un-analyzed) parse trees.
|
||||
*/
|
||||
List *
|
||||
parser(const char *str, Oid *typev, int nargs)
|
||||
raw_parser(const char *str)
|
||||
{
|
||||
int yyresult;
|
||||
|
||||
parsetree = NIL; /* in case parser forgets to set it */
|
||||
parsetree = NIL; /* in case grammar forgets to set it */
|
||||
have_lookahead = false;
|
||||
|
||||
scanner_init(str);
|
||||
parser_init();
|
||||
parse_expr_init();
|
||||
parser_param_set(typev, nargs);
|
||||
|
||||
yyresult = yyparse();
|
||||
|
||||
@@ -69,35 +64,6 @@ parser(const char *str, Oid *typev, int nargs)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Save information needed to fill out the type of Param references ($n)
|
||||
*
|
||||
* This is used for SQL functions, PREPARE statements, etc. It's split
|
||||
* out from parser() setup because PREPARE needs to change the info after
|
||||
* the grammar runs and before parse analysis is done on the preparable
|
||||
* query.
|
||||
*/
|
||||
void
|
||||
parser_param_set(Oid *typev, int nargs)
|
||||
{
|
||||
param_type_info = typev;
|
||||
param_count = nargs;
|
||||
}
|
||||
|
||||
/*
|
||||
* param_type()
|
||||
*
|
||||
* Fetch a parameter type previously passed to parser_param_set
|
||||
*/
|
||||
Oid
|
||||
param_type(int t)
|
||||
{
|
||||
if (t > param_count || t <= 0)
|
||||
return InvalidOid;
|
||||
return param_type_info[t - 1];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Intermediate filter between parser and base lexer (base_yylex in scan.l).
|
||||
*
|
||||
|
Reference in New Issue
Block a user