Hello, this small patch allows using updatable cursors in plpgsql.
Regards Pavel Stehule
*** ./gram.y.orig 2007-06-11 10:43:09.000000000 +0200 --- ./gram.y 2007-06-11 11:48:03.000000000 +0200 *************** *** 44,49 **** --- 44,50 ---- static void plpgsql_sql_error_callback(void *arg); static void check_labels(const char *start_label, const char *end_label); + static void check_cursor_variable(void); %} *************** *** 155,160 **** --- 156,162 ---- %token K_CLOSE %token K_CONSTANT %token K_CONTINUE + %token K_CURRENTOF %token K_CURSOR %token K_DEBUG %token K_DECLARE *************** *** 1527,1543 **** cursor_variable : T_SCALAR { ! if (yylval.scalar->dtype != PLPGSQL_DTYPE_VAR) ! yyerror("cursor variable must be a simple variable"); ! ! if (((PLpgSQL_var *) yylval.scalar)->datatype->typoid != REFCURSOROID) ! { ! plpgsql_error_lineno = plpgsql_scanner_lineno(); ! ereport(ERROR, ! (errcode(ERRCODE_DATATYPE_MISMATCH), ! errmsg("\"%s\" must be of type cursor or refcursor", ! ((PLpgSQL_var *) yylval.scalar)->refname))); ! } $$ = (PLpgSQL_var *) yylval.scalar; } ; --- 1529,1535 ---- cursor_variable : T_SCALAR { ! check_cursor_variable(); $$ = (PLpgSQL_var *) yylval.scalar; } ; *************** *** 1923,1928 **** --- 1915,1937 ---- return result; } + + static void + check_cursor_variable(void) + { + if (yylval.scalar->dtype != PLPGSQL_DTYPE_VAR) + yyerror("cursor variable must be a simple variable"); + + if (((PLpgSQL_var *) yylval.scalar)->datatype->typoid != REFCURSOROID) + { + plpgsql_error_lineno = plpgsql_scanner_lineno(); + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("\"%s\" must be of type cursor or refcursor", + ((PLpgSQL_var *) yylval.scalar)->refname))); + } + } + static PLpgSQL_stmt * make_execsql_stmt(const char *sqlstart, int lineno) { *************** *** 1982,1987 **** --- 1991,2004 ---- params, &nparams)); plpgsql_dstring_append(&ds, buf); break; + + case K_CURRENTOF: + if (yylex() != T_SCALAR) + yyerror("missing cursor variable"); + check_cursor_variable(); + plpgsql_dstring_append(&ds, " CURRENT OF "); + plpgsql_dstring_append(&ds, yytext); + break; default: plpgsql_dstring_append(&ds, yytext); *** ./scan.l.orig 2007-06-11 10:43:05.000000000 +0200 --- ./scan.l 2007-06-11 11:48:40.000000000 +0200 *************** *** 119,124 **** --- 119,125 ---- constant { return K_CONSTANT; } continue { return K_CONTINUE; } cursor { return K_CURSOR; } + current{space}+of { return K_CURRENTOF; } debug { return K_DEBUG; } declare { return K_DECLARE; } default { return K_DEFAULT; }
---------------------------(end of broadcast)--------------------------- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate