Format to match standard conventions
This commit is contained in:
parent
b54073ea4c
commit
4ea081e94f
@ -4,7 +4,7 @@
|
|||||||
* procedural language
|
* procedural language
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.14 2001/02/10 22:42:01 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/gram.y,v 1.15 2001/02/10 22:53:40 momjian Exp $
|
||||||
*
|
*
|
||||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||||
*
|
*
|
||||||
@ -54,20 +54,24 @@ static PLpgSQL_expr *make_tupret_expr(PLpgSQL_row *row);
|
|||||||
%union {
|
%union {
|
||||||
int32 ival;
|
int32 ival;
|
||||||
char *str;
|
char *str;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int lineno;
|
int lineno;
|
||||||
} varname;
|
} varname;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
int nalloc;
|
int nalloc;
|
||||||
int nused;
|
int nused;
|
||||||
int *dtnums;
|
int *dtnums;
|
||||||
} dtlist;
|
} dtlist;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
int reverse;
|
int reverse;
|
||||||
PLpgSQL_expr *expr;
|
PLpgSQL_expr *expr;
|
||||||
} forilow;
|
} forilow;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
char *label;
|
char *label;
|
||||||
int n_initvars;
|
int n_initvars;
|
||||||
int *initvarnos;
|
int *initvarnos;
|
||||||
@ -256,11 +260,10 @@ decl_sect : opt_label
|
|||||||
| opt_label decl_start decl_stmts
|
| opt_label decl_start decl_stmts
|
||||||
{
|
{
|
||||||
plpgsql_ns_setlocal(false);
|
plpgsql_ns_setlocal(false);
|
||||||
if ($3 != NULL) {
|
if ($3 != NULL)
|
||||||
$$.label = $3;
|
$$.label = $3;
|
||||||
} else {
|
else
|
||||||
$$.label = $1;
|
$$.label = $1;
|
||||||
}
|
|
||||||
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
|
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -272,27 +275,17 @@ decl_start : K_DECLARE
|
|||||||
;
|
;
|
||||||
|
|
||||||
decl_stmts : decl_stmts decl_stmt
|
decl_stmts : decl_stmts decl_stmt
|
||||||
{
|
{ $$ = $2; }
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
| decl_stmt
|
| decl_stmt
|
||||||
{
|
{ $$ = $1; }
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
decl_stmt : '<' '<' opt_lblname '>' '>'
|
decl_stmt : '<' '<' opt_lblname '>' '>'
|
||||||
{
|
{ $$ = $3; }
|
||||||
$$ = $3;
|
|
||||||
}
|
|
||||||
| K_DECLARE
|
| K_DECLARE
|
||||||
{
|
{ $$ = NULL; }
|
||||||
$$ = NULL;
|
|
||||||
}
|
|
||||||
| decl_statement
|
| decl_statement
|
||||||
{
|
{ $$ = NULL; }
|
||||||
$$ = NULL;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval
|
decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval
|
||||||
@ -356,13 +349,11 @@ decl_aliasitem : T_WORD
|
|||||||
|
|
||||||
plpgsql_ns_setlocal(false);
|
plpgsql_ns_setlocal(false);
|
||||||
name = plpgsql_tolower(yytext);
|
name = plpgsql_tolower(yytext);
|
||||||
if (name[0] != '$') {
|
if (name[0] != '$')
|
||||||
elog(ERROR, "can only alias positional parameters");
|
elog(ERROR, "can only alias positional parameters");
|
||||||
}
|
|
||||||
nsi = plpgsql_ns_lookup(name, NULL);
|
nsi = plpgsql_ns_lookup(name, NULL);
|
||||||
if (nsi == NULL) {
|
if (nsi == NULL)
|
||||||
elog(ERROR, "function has no parameter %s", name);
|
elog(ERROR, "function has no parameter %s", name);
|
||||||
}
|
|
||||||
|
|
||||||
plpgsql_ns_setlocal(true);
|
plpgsql_ns_setlocal(true);
|
||||||
|
|
||||||
@ -398,21 +389,19 @@ decl_const :
|
|||||||
;
|
;
|
||||||
|
|
||||||
decl_datatype : decl_dtypename
|
decl_datatype : decl_dtypename
|
||||||
{
|
{ $$ = $1; }
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
decl_dtypename : T_DTYPE
|
decl_dtypename : T_DTYPE
|
||||||
{
|
{ $$ = yylval.dtype; }
|
||||||
$$ = yylval.dtype;
|
|
||||||
}
|
|
||||||
| T_CHAR decl_atttypmod
|
| T_CHAR decl_atttypmod
|
||||||
{
|
{
|
||||||
if ($2 < 0) {
|
if ($2 < 0)
|
||||||
|
{
|
||||||
plpgsql_parse_word("char");
|
plpgsql_parse_word("char");
|
||||||
$$ = yylval.dtype;
|
$$ = yylval.dtype;
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
plpgsql_parse_word("bpchar");
|
plpgsql_parse_word("bpchar");
|
||||||
$$ = yylval.dtype;
|
$$ = yylval.dtype;
|
||||||
$$->atttypmod = $2;
|
$$->atttypmod = $2;
|
||||||
@ -433,13 +422,9 @@ decl_dtypename : T_DTYPE
|
|||||||
;
|
;
|
||||||
|
|
||||||
decl_atttypmod :
|
decl_atttypmod :
|
||||||
{
|
{ $$ = -1; }
|
||||||
$$ = -1;
|
|
||||||
}
|
|
||||||
| '(' decl_atttypmodval ')'
|
| '(' decl_atttypmodval ')'
|
||||||
{
|
{ $$ = $2; }
|
||||||
$$ = $2;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
decl_atttypmodval : T_NUMBER
|
decl_atttypmodval : T_NUMBER
|
||||||
@ -473,13 +458,15 @@ decl_defval : ';'
|
|||||||
expr->nparams = 0;
|
expr->nparams = 0;
|
||||||
|
|
||||||
tok = yylex();
|
tok = yylex();
|
||||||
switch (tok) {
|
switch (tok)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
plpgsql_error_lineno = lno;
|
plpgsql_error_lineno = lno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "unexpected end of file");
|
elog(ERROR, "unexpected end of file");
|
||||||
case K_NULL:
|
case K_NULL:
|
||||||
if (yylex() != ';') {
|
if (yylex() != ';')
|
||||||
|
{
|
||||||
plpgsql_error_lineno = lno;
|
plpgsql_error_lineno = lno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "expectec ; after NULL");
|
elog(ERROR, "expectec ; after NULL");
|
||||||
@ -492,15 +479,16 @@ decl_defval : ';'
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
plpgsql_dstring_append(&ds, yytext);
|
plpgsql_dstring_append(&ds, yytext);
|
||||||
while ((tok = yylex()) != ';') {
|
while ((tok = yylex()) != ';')
|
||||||
if (tok == 0) {
|
{
|
||||||
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = lno;
|
plpgsql_error_lineno = lno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "unterminated default value");
|
elog(ERROR, "unterminated default value");
|
||||||
}
|
}
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
|
||||||
plpgsql_dstring_append(&ds, yytext);
|
plpgsql_dstring_append(&ds, yytext);
|
||||||
}
|
}
|
||||||
expr->query = strdup(plpgsql_dstring_get(&ds));
|
expr->query = strdup(plpgsql_dstring_get(&ds));
|
||||||
@ -524,9 +512,7 @@ proc_sect :
|
|||||||
$$ = new;
|
$$ = new;
|
||||||
}
|
}
|
||||||
| proc_stmts
|
| proc_stmts
|
||||||
{
|
{ $$ = $1; }
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
proc_stmts : proc_stmts proc_stmt
|
proc_stmts : proc_stmts proc_stmt
|
||||||
@ -637,7 +623,8 @@ stmt_getdiag : K_GET K_DIAGNOSTICS lno K_SELECT getdiag_items K_INTO getdiag_tar
|
|||||||
memcpy(new->items, $5.dtnums, sizeof(int) * $5.nused);
|
memcpy(new->items, $5.dtnums, sizeof(int) * $5.nused);
|
||||||
memcpy(new->targets, $7.dtnums, sizeof(int) * $7.nused);
|
memcpy(new->targets, $7.dtnums, sizeof(int) * $7.nused);
|
||||||
|
|
||||||
if (new->nitems != new->ntargets) {
|
if (new->nitems != new->ntargets)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = new->lineno;
|
plpgsql_error_lineno = new->lineno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "number of diagnostic items does not match target list");
|
elog(ERROR, "number of diagnostic items does not match target list");
|
||||||
@ -649,7 +636,8 @@ stmt_getdiag : K_GET K_DIAGNOSTICS lno K_SELECT getdiag_items K_INTO getdiag_tar
|
|||||||
|
|
||||||
getdiag_items : getdiag_items ',' getdiag_item
|
getdiag_items : getdiag_items ',' getdiag_item
|
||||||
{
|
{
|
||||||
if ($1.nused == $1.nalloc) {
|
if ($1.nused == $1.nalloc)
|
||||||
|
{
|
||||||
$1.nalloc *= 2;
|
$1.nalloc *= 2;
|
||||||
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
||||||
}
|
}
|
||||||
@ -680,7 +668,8 @@ getdiag_item : K_PROCESSED
|
|||||||
|
|
||||||
getdiag_targets : getdiag_targets ',' getdiag_target
|
getdiag_targets : getdiag_targets ',' getdiag_target
|
||||||
{
|
{
|
||||||
if ($1.nused == $1.nalloc) {
|
if ($1.nused == $1.nalloc)
|
||||||
|
{
|
||||||
$1.nalloc *= 2;
|
$1.nalloc *= 2;
|
||||||
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
||||||
}
|
}
|
||||||
@ -702,7 +691,8 @@ getdiag_targets : getdiag_targets ',' getdiag_target
|
|||||||
|
|
||||||
getdiag_target : T_VARIABLE
|
getdiag_target : T_VARIABLE
|
||||||
{
|
{
|
||||||
if (yylval.var->isconst) {
|
if (yylval.var->isconst)
|
||||||
|
{
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "%s is declared CONSTANT; can not receive diagnostics", yylval.var->refname);
|
elog(ERROR, "%s is declared CONSTANT; can not receive diagnostics", yylval.var->refname);
|
||||||
}
|
}
|
||||||
@ -717,7 +707,8 @@ getdiag_target : T_VARIABLE
|
|||||||
|
|
||||||
assign_var : T_VARIABLE
|
assign_var : T_VARIABLE
|
||||||
{
|
{
|
||||||
if (yylval.var->isconst) {
|
if (yylval.var->isconst)
|
||||||
|
{
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "%s is declared CONSTANT", yylval.var->refname);
|
elog(ERROR, "%s is declared CONSTANT", yylval.var->refname);
|
||||||
}
|
}
|
||||||
@ -872,19 +863,22 @@ fori_lower :
|
|||||||
plpgsql_dstring_append(&ds, "SELECT ");
|
plpgsql_dstring_append(&ds, "SELECT ");
|
||||||
|
|
||||||
$$.reverse = 0;
|
$$.reverse = 0;
|
||||||
while((tok = yylex()) != K_DOTDOT) {
|
while((tok = yylex()) != K_DOTDOT)
|
||||||
if (firsttok) {
|
{
|
||||||
|
if (firsttok)
|
||||||
|
{
|
||||||
firsttok = 0;
|
firsttok = 0;
|
||||||
if (tok == K_REVERSE) {
|
if (tok == K_REVERSE)
|
||||||
|
{
|
||||||
$$.reverse = 1;
|
$$.reverse = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tok == ';') break;
|
if (tok == ';') break;
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
switch (tok)
|
||||||
switch (tok) {
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
params[nparams] = yylval.var->varno;
|
params[nparams] = yylval.var->varno;
|
||||||
sprintf(buf, " $%d ", ++nparams);
|
sprintf(buf, " $%d ", ++nparams);
|
||||||
@ -904,7 +898,8 @@ fori_lower :
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (tok == 0) {
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = lno;
|
plpgsql_error_lineno = lno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "missing .. to terminate lower bound of for loop");
|
elog(ERROR, "missing .. to terminate lower bound of for loop");
|
||||||
@ -919,9 +914,8 @@ fori_lower :
|
|||||||
expr->query = strdup(plpgsql_dstring_get(&ds));
|
expr->query = strdup(plpgsql_dstring_get(&ds));
|
||||||
expr->plan = NULL;
|
expr->plan = NULL;
|
||||||
expr->nparams = nparams;
|
expr->nparams = nparams;
|
||||||
while(nparams-- > 0) {
|
while(nparams-- > 0)
|
||||||
expr->params[nparams] = params[nparams];
|
expr->params[nparams] = params[nparams];
|
||||||
}
|
|
||||||
plpgsql_dstring_free(&ds);
|
plpgsql_dstring_free(&ds);
|
||||||
$$.expr = expr;
|
$$.expr = expr;
|
||||||
}
|
}
|
||||||
@ -936,7 +930,8 @@ stmt_fors : opt_label K_FOR lno fors_target K_IN K_SELECT expr_until_loop loop_
|
|||||||
new->cmd_type = PLPGSQL_STMT_FORS;
|
new->cmd_type = PLPGSQL_STMT_FORS;
|
||||||
new->lineno = $3;
|
new->lineno = $3;
|
||||||
new->label = $1;
|
new->label = $1;
|
||||||
switch ($4->dtype) {
|
switch ($4->dtype)
|
||||||
|
{
|
||||||
case PLPGSQL_DTYPE_REC:
|
case PLPGSQL_DTYPE_REC:
|
||||||
new->rec = $4;
|
new->rec = $4;
|
||||||
break;
|
break;
|
||||||
@ -965,7 +960,8 @@ stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop lo
|
|||||||
new->cmd_type = PLPGSQL_STMT_DYNFORS;
|
new->cmd_type = PLPGSQL_STMT_DYNFORS;
|
||||||
new->lineno = $3;
|
new->lineno = $3;
|
||||||
new->label = $1;
|
new->label = $1;
|
||||||
switch ($4->dtype) {
|
switch ($4->dtype)
|
||||||
|
{
|
||||||
case PLPGSQL_DTYPE_REC:
|
case PLPGSQL_DTYPE_REC:
|
||||||
new->rec = $4;
|
new->rec = $4;
|
||||||
break;
|
break;
|
||||||
@ -985,9 +981,7 @@ stmt_dynfors : opt_label K_FOR lno fors_target K_IN K_EXECUTE expr_until_loop lo
|
|||||||
}
|
}
|
||||||
|
|
||||||
fors_target : T_RECORD
|
fors_target : T_RECORD
|
||||||
{
|
{ $$ = yylval.rec; }
|
||||||
$$ = yylval.rec;
|
|
||||||
}
|
|
||||||
| T_ROW
|
| T_ROW
|
||||||
{
|
{
|
||||||
$$ = (PLpgSQL_rec *)(yylval.row);
|
$$ = (PLpgSQL_rec *)(yylval.row);
|
||||||
@ -1026,10 +1020,12 @@ stmt_return : K_RETURN lno
|
|||||||
new = malloc(sizeof(PLpgSQL_stmt_return));
|
new = malloc(sizeof(PLpgSQL_stmt_return));
|
||||||
memset(new, 0, sizeof(PLpgSQL_stmt_return));
|
memset(new, 0, sizeof(PLpgSQL_stmt_return));
|
||||||
|
|
||||||
if (plpgsql_curr_compile->fn_retistuple) {
|
if (plpgsql_curr_compile->fn_retistuple)
|
||||||
|
{
|
||||||
new->retistuple = true;
|
new->retistuple = true;
|
||||||
new->retrecno = -1;
|
new->retrecno = -1;
|
||||||
switch (tok = yylex()) {
|
switch (tok = yylex())
|
||||||
|
{
|
||||||
case K_NULL:
|
case K_NULL:
|
||||||
expr = NULL;
|
expr = NULL;
|
||||||
break;
|
break;
|
||||||
@ -1047,9 +1043,8 @@ stmt_return : K_RETURN lno
|
|||||||
yyerror("return type mismatch in function returning table row");
|
yyerror("return type mismatch in function returning table row");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (yylex() != ';') {
|
if (yylex() != ';')
|
||||||
yyerror("expected ';'");
|
yyerror("expected ';'");
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
new->retistuple = false;
|
new->retistuple = false;
|
||||||
expr = plpgsql_read_expression(';', ";");
|
expr = plpgsql_read_expression(';', ";");
|
||||||
@ -1118,7 +1113,8 @@ raise_level : K_EXCEPTION
|
|||||||
|
|
||||||
raise_params : raise_params raise_param
|
raise_params : raise_params raise_param
|
||||||
{
|
{
|
||||||
if ($1.nused == $1.nalloc) {
|
if ($1.nused == $1.nalloc)
|
||||||
|
{
|
||||||
$1.nalloc *= 2;
|
$1.nalloc *= 2;
|
||||||
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
$1.dtnums = repalloc($1.dtnums, sizeof(int) * $1.nalloc);
|
||||||
}
|
}
|
||||||
@ -1263,12 +1259,13 @@ read_sqlstmt (int until, char *s, char *sqlstart)
|
|||||||
plpgsql_dstring_init(&ds);
|
plpgsql_dstring_init(&ds);
|
||||||
plpgsql_dstring_append(&ds, sqlstart);
|
plpgsql_dstring_append(&ds, sqlstart);
|
||||||
|
|
||||||
while((tok = yylex()) != until) {
|
while((tok = yylex()) != until)
|
||||||
|
{
|
||||||
if (tok == ';') break;
|
if (tok == ';') break;
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
switch (tok)
|
||||||
switch (tok) {
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
params[nparams] = yylval.var->varno;
|
params[nparams] = yylval.var->varno;
|
||||||
sprintf(buf, " $%d ", ++nparams);
|
sprintf(buf, " $%d ", ++nparams);
|
||||||
@ -1288,7 +1285,8 @@ read_sqlstmt (int until, char *s, char *sqlstart)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (tok == 0) {
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = lno;
|
plpgsql_error_lineno = lno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "missing %s at end of SQL statement", s);
|
elog(ERROR, "missing %s at end of SQL statement", s);
|
||||||
@ -1303,9 +1301,8 @@ read_sqlstmt (int until, char *s, char *sqlstart)
|
|||||||
expr->query = strdup(plpgsql_dstring_get(&ds));
|
expr->query = strdup(plpgsql_dstring_get(&ds));
|
||||||
expr->plan = NULL;
|
expr->plan = NULL;
|
||||||
expr->nparams = nparams;
|
expr->nparams = nparams;
|
||||||
while(nparams-- > 0) {
|
while(nparams-- > 0)
|
||||||
expr->params[nparams] = params[nparams];
|
expr->params[nparams] = params[nparams];
|
||||||
}
|
|
||||||
plpgsql_dstring_free(&ds);
|
plpgsql_dstring_free(&ds);
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
@ -1331,8 +1328,10 @@ make_select_stmt()
|
|||||||
plpgsql_dstring_init(&ds);
|
plpgsql_dstring_init(&ds);
|
||||||
plpgsql_dstring_append(&ds, "SELECT ");
|
plpgsql_dstring_append(&ds, "SELECT ");
|
||||||
|
|
||||||
while((tok = yylex()) != K_INTO) {
|
while((tok = yylex()) != K_INTO)
|
||||||
if (tok == ';') {
|
{
|
||||||
|
if (tok == ';')
|
||||||
|
{
|
||||||
PLpgSQL_stmt_execsql *execsql;
|
PLpgSQL_stmt_execsql *execsql;
|
||||||
|
|
||||||
expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - 1);
|
expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - 1);
|
||||||
@ -1340,9 +1339,8 @@ make_select_stmt()
|
|||||||
expr->query = strdup(plpgsql_dstring_get(&ds));
|
expr->query = strdup(plpgsql_dstring_get(&ds));
|
||||||
expr->plan = NULL;
|
expr->plan = NULL;
|
||||||
expr->nparams = nparams;
|
expr->nparams = nparams;
|
||||||
while(nparams-- > 0) {
|
while(nparams-- > 0)
|
||||||
expr->params[nparams] = params[nparams];
|
expr->params[nparams] = params[nparams];
|
||||||
}
|
|
||||||
plpgsql_dstring_free(&ds);
|
plpgsql_dstring_free(&ds);
|
||||||
|
|
||||||
execsql = malloc(sizeof(PLpgSQL_stmt_execsql));
|
execsql = malloc(sizeof(PLpgSQL_stmt_execsql));
|
||||||
@ -1352,10 +1350,10 @@ make_select_stmt()
|
|||||||
return (PLpgSQL_stmt *)execsql;
|
return (PLpgSQL_stmt *)execsql;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
switch (tok)
|
||||||
switch (tok) {
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
params[nparams] = yylval.var->varno;
|
params[nparams] = yylval.var->varno;
|
||||||
sprintf(buf, " $%d ", ++nparams);
|
sprintf(buf, " $%d ", ++nparams);
|
||||||
@ -1375,7 +1373,8 @@ make_select_stmt()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (tok == 0) {
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = yylineno;
|
plpgsql_error_lineno = yylineno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "unexpected end of file");
|
elog(ERROR, "unexpected end of file");
|
||||||
@ -1386,7 +1385,8 @@ make_select_stmt()
|
|||||||
}
|
}
|
||||||
|
|
||||||
tok = yylex();
|
tok = yylex();
|
||||||
switch (tok) {
|
switch (tok)
|
||||||
|
{
|
||||||
case T_ROW:
|
case T_ROW:
|
||||||
row = yylval.row;
|
row = yylval.row;
|
||||||
break;
|
break;
|
||||||
@ -1404,7 +1404,8 @@ make_select_stmt()
|
|||||||
char *fieldnames[1024];
|
char *fieldnames[1024];
|
||||||
int varnos[1024];
|
int varnos[1024];
|
||||||
|
|
||||||
switch (tok) {
|
switch (tok)
|
||||||
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
var = yylval.var;
|
var = yylval.var;
|
||||||
fieldnames[0] = strdup(yytext);
|
fieldnames[0] = strdup(yytext);
|
||||||
@ -1418,9 +1419,11 @@ make_select_stmt()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((tok = yylex()) == ',') {
|
while ((tok = yylex()) == ',')
|
||||||
|
{
|
||||||
tok = yylex();
|
tok = yylex();
|
||||||
switch(tok) {
|
switch(tok)
|
||||||
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
var = yylval.var;
|
var = yylval.var;
|
||||||
fieldnames[nfields] = strdup(yytext);
|
fieldnames[nfields] = strdup(yytext);
|
||||||
@ -1445,7 +1448,8 @@ make_select_stmt()
|
|||||||
row->nfields = nfields;
|
row->nfields = nfields;
|
||||||
row->fieldnames = malloc(sizeof(char *) * nfields);
|
row->fieldnames = malloc(sizeof(char *) * nfields);
|
||||||
row->varnos = malloc(sizeof(int) * nfields);
|
row->varnos = malloc(sizeof(int) * nfields);
|
||||||
while (--nfields >= 0) {
|
while (--nfields >= 0)
|
||||||
|
{
|
||||||
row->fieldnames[nfields] = fieldnames[nfields];
|
row->fieldnames[nfields] = fieldnames[nfields];
|
||||||
row->varnos[nfields] = varnos[nfields];
|
row->varnos[nfields] = varnos[nfields];
|
||||||
}
|
}
|
||||||
@ -1458,14 +1462,15 @@ make_select_stmt()
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
|
||||||
plpgsql_dstring_append(&ds, yytext);
|
plpgsql_dstring_append(&ds, yytext);
|
||||||
|
|
||||||
while(1) {
|
while(1)
|
||||||
|
{
|
||||||
tok = yylex();
|
tok = yylex();
|
||||||
if (tok == ';') {
|
if (tok == ';')
|
||||||
|
{
|
||||||
PLpgSQL_stmt_execsql *execsql;
|
PLpgSQL_stmt_execsql *execsql;
|
||||||
|
|
||||||
expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - 1);
|
expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - 1);
|
||||||
@ -1485,10 +1490,10 @@ make_select_stmt()
|
|||||||
return (PLpgSQL_stmt *)execsql;
|
return (PLpgSQL_stmt *)execsql;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
switch (tok)
|
||||||
switch (tok) {
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
params[nparams] = yylval.var->varno;
|
params[nparams] = yylval.var->varno;
|
||||||
sprintf(buf, " $%d ", ++nparams);
|
sprintf(buf, " $%d ", ++nparams);
|
||||||
@ -1508,7 +1513,8 @@ make_select_stmt()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (tok == 0) {
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = yylineno;
|
plpgsql_error_lineno = yylineno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "unexpected end of file");
|
elog(ERROR, "unexpected end of file");
|
||||||
@ -1523,7 +1529,8 @@ make_select_stmt()
|
|||||||
/************************************************************
|
/************************************************************
|
||||||
* Eat up the rest of the statement after the target fields
|
* Eat up the rest of the statement after the target fields
|
||||||
************************************************************/
|
************************************************************/
|
||||||
while(1) {
|
while(1)
|
||||||
|
{
|
||||||
if (!have_nexttok) {
|
if (!have_nexttok) {
|
||||||
tok = yylex();
|
tok = yylex();
|
||||||
}
|
}
|
||||||
@ -1532,10 +1539,10 @@ make_select_stmt()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plpgsql_SpaceScanned) {
|
if (plpgsql_SpaceScanned)
|
||||||
plpgsql_dstring_append(&ds, " ");
|
plpgsql_dstring_append(&ds, " ");
|
||||||
}
|
switch (tok)
|
||||||
switch (tok) {
|
{
|
||||||
case T_VARIABLE:
|
case T_VARIABLE:
|
||||||
params[nparams] = yylval.var->varno;
|
params[nparams] = yylval.var->varno;
|
||||||
sprintf(buf, " $%d ", ++nparams);
|
sprintf(buf, " $%d ", ++nparams);
|
||||||
@ -1555,7 +1562,8 @@ make_select_stmt()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (tok == 0) {
|
if (tok == 0)
|
||||||
|
{
|
||||||
plpgsql_error_lineno = yylineno;
|
plpgsql_error_lineno = yylineno;
|
||||||
plpgsql_comperrinfo();
|
plpgsql_comperrinfo();
|
||||||
elog(ERROR, "unexpected end of file");
|
elog(ERROR, "unexpected end of file");
|
||||||
@ -1570,9 +1578,8 @@ make_select_stmt()
|
|||||||
expr->query = strdup(plpgsql_dstring_get(&ds));
|
expr->query = strdup(plpgsql_dstring_get(&ds));
|
||||||
expr->plan = NULL;
|
expr->plan = NULL;
|
||||||
expr->nparams = nparams;
|
expr->nparams = nparams;
|
||||||
while(nparams-- > 0) {
|
while(nparams-- > 0)
|
||||||
expr->params[nparams] = params[nparams];
|
expr->params[nparams] = params[nparams];
|
||||||
}
|
|
||||||
plpgsql_dstring_free(&ds);
|
plpgsql_dstring_free(&ds);
|
||||||
|
|
||||||
select = malloc(sizeof(PLpgSQL_stmt_select));
|
select = malloc(sizeof(PLpgSQL_stmt_select));
|
||||||
@ -1600,7 +1607,8 @@ make_tupret_expr(PLpgSQL_row *row)
|
|||||||
plpgsql_dstring_init(&ds);
|
plpgsql_dstring_init(&ds);
|
||||||
plpgsql_dstring_append(&ds, "SELECT ");
|
plpgsql_dstring_append(&ds, "SELECT ");
|
||||||
|
|
||||||
for (i = 0; i < row->nfields; i++) {
|
for (i = 0; i < row->nfields; i++)
|
||||||
|
{
|
||||||
sprintf(buf, "%s$%d", (i > 0) ? "," : "", i + 1);
|
sprintf(buf, "%s$%d", (i > 0) ? "," : "", i + 1);
|
||||||
plpgsql_dstring_append(&ds, buf);
|
plpgsql_dstring_append(&ds, buf);
|
||||||
expr->params[i] = row->varnos[i];
|
expr->params[i] = row->varnos[i];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user