Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdabde32

Browse files
committed
Back out SQLSTATE and SQLERRM support.
1 parent4c862b1 commitdabde32

File tree

6 files changed

+18
-135
lines changed

6 files changed

+18
-135
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.68 2005/05/2600:16:31 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.69 2005/05/2604:08:31 momjian Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -2007,13 +2007,12 @@ END LOOP;
20072007
</indexterm>
20082008

20092009
<para>
2010-
Any error occurring in <application>PL/pgSQL</> sets variables
2011-
<varname>SQLSTATE</> and <varname>SQLERRM</>, and, by default,
2012-
aborts execution of the function, and indeed of the surrounding
2013-
transaction as well. You can trap errors and recover from them by
2014-
using a <command>BEGIN</> block with an <literal>EXCEPTION</>
2015-
clause. The syntax is an extension of the normal syntax for a
2016-
<command>BEGIN</> block:
2010+
By default, any error occurring in a <application>PL/pgSQL</>
2011+
function aborts execution of the function, and indeed of the
2012+
surrounding transaction as well. You can trap errors and recover
2013+
from them by using a <command>BEGIN</> block with an
2014+
<literal>EXCEPTION</> clause. The syntax is an extension of the
2015+
normal syntax for a <command>BEGIN</> block:
20172016

20182017
<synopsis>
20192018
<optional> &lt;&lt;<replaceable>label</replaceable>&gt;&gt; </optional>

‎src/pl/plpgsql/src/gram.y

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* procedural language
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.71 2005/05/2603:18:53 neilc Exp $
7+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.72 2005/05/2604:08:31 momjian Exp $
88
*
99
* This software is copyrighted by Jan Wieck - Hamburg.
1010
*
@@ -80,11 +80,6 @@ staticvoid plpgsql_sql_error_callback(void *arg);
8080
int n_initvars;
8181
int *initvarnos;
8282
}declhdr;
83-
struct
84-
{
85-
int sqlstate_varno;
86-
int sqlerrm_varno;
87-
}fict_vars;
8883
List*list;
8984
PLpgSQL_type*dtype;
9085
PLpgSQL_datum*scalar;/* a VAR, RECFIELD, or TRIGARG*/
@@ -101,7 +96,6 @@ staticvoid plpgsql_sql_error_callback(void *arg);
10196
PLpgSQL_diag_item*diagitem;
10297
}
10398

104-
%type<fict_vars>fict_vars_sect
10599
%type<declhdr>decl_sect
106100
%type<varname>decl_varname
107101
%type<str>decl_renname
@@ -250,43 +244,26 @@ opt_semi:
250244
|';'
251245
;
252246

253-
pl_block:decl_sectfict_vars_sectK_BEGINlnoproc_sectexception_sectK_END
247+
pl_block:decl_sectK_BEGINlnoproc_sectexception_sectK_END
254248
{
255249
PLpgSQL_stmt_block *new;
256250

257251
new = palloc0(sizeof(PLpgSQL_stmt_block));
258252

259253
new->cmd_type= PLPGSQL_STMT_BLOCK;
260-
new->lineno=$4;
254+
new->lineno=$3;
261255
new->label=$1.label;
262256
new->n_initvars =$1.n_initvars;
263257
new->initvarnos =$1.initvarnos;
264-
new->body=$5;
265-
new->exceptions=$6;
266-
267-
new->sqlstate_varno =$2.sqlstate_varno;
268-
new->sqlerrm_varno =$2.sqlerrm_varno;
258+
new->body=$4;
259+
new->exceptions=$5;
269260

270261
plpgsql_ns_pop();
271262

272263
$$ = (PLpgSQL_stmt *)new;
273264
}
274265
;
275266

276-
fict_vars_sect:
277-
{
278-
PLpgSQL_variable*var;
279-
280-
plpgsql_ns_setlocal(false);
281-
var = plpgsql_build_variable("sqlstate",0,
282-
plpgsql_build_datatype(TEXTOID, -1), true);
283-
$$.sqlstate_varno = var->dno;
284-
var = plpgsql_build_variable("sqlerrm",0,
285-
plpgsql_build_datatype(TEXTOID, -1), true);
286-
$$.sqlerrm_varno = var->dno;
287-
plpgsql_add_initdatums(NULL);
288-
}
289-
;
290267

291268
decl_sect:opt_label
292269
{

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.140 2005/05/2603:18:53 neilc Exp $
6+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.141 2005/05/2604:08:31 momjian Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -180,7 +180,6 @@ static Datum exec_simple_cast_value(Datum value, Oid valtype,
180180
staticvoidexec_init_tuple_store(PLpgSQL_execstate*estate);
181181
staticboolcompatible_tupdesc(TupleDesctd1,TupleDesctd2);
182182
staticvoidexec_set_found(PLpgSQL_execstate*estate,boolstate);
183-
staticchar*unpack_sql_state(intssval);
184183

185184

186185
/* ----------
@@ -748,20 +747,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
748747
inti;
749748
intn;
750749

751-
752-
/* setup SQLSTATE and SQLERRM */
753-
PLpgSQL_var*var;
754-
755-
var= (PLpgSQL_var*) (estate->datums[block->sqlstate_varno]);
756-
var->isnull= false;
757-
var->freeval= true;
758-
var->value=DirectFunctionCall1(textin,CStringGetDatum("00000"));
759-
760-
var= (PLpgSQL_var*) (estate->datums[block->sqlerrm_varno]);
761-
var->isnull= false;
762-
var->freeval= true;
763-
var->value=DirectFunctionCall1(textin,CStringGetDatum("Successful completion"));
764-
765750
/*
766751
* First initialize all variables declared in this block
767752
*/
@@ -777,7 +762,7 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
777762

778763
if (var->freeval)
779764
{
780-
pfree(DatumGetPointer(var->value));
765+
pfree((void*)(var->value));
781766
var->freeval= false;
782767
}
783768

@@ -870,15 +855,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
870855
RollbackAndReleaseCurrentSubTransaction();
871856
MemoryContextSwitchTo(oldcontext);
872857
CurrentResourceOwner=oldowner;
873-
874-
/* set SQLSTATE and SQLERRM variables */
875-
var= (PLpgSQL_var*) (estate->datums[block->sqlstate_varno]);
876-
pfree(DatumGetPointer(var->value));
877-
var->value=DirectFunctionCall1(textin,CStringGetDatum(unpack_sql_state(edata->sqlerrcode)));
878-
879-
var= (PLpgSQL_var*) (estate->datums[block->sqlerrm_varno]);
880-
pfree(DatumGetPointer(var->value));
881-
var->value=DirectFunctionCall1(textin,CStringGetDatum(edata->message));
882858

883859
/*
884860
* If AtEOSubXact_SPI() popped any SPI context of the subxact,
@@ -943,26 +919,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
943919
returnPLPGSQL_RC_OK;
944920
}
945921

946-
/*
947-
* unpack MAKE_SQLSTATE code
948-
* This code is copied from backend/utils/error/elog.c.
949-
*/
950-
staticchar*
951-
unpack_sql_state(intssval)
952-
{
953-
staticchartbuf[12];
954-
inti;
955-
956-
for (i=0;i<5;i++)
957-
{
958-
tbuf[i]=PGUNSIXBIT(ssval);
959-
ssval >>=6;
960-
}
961-
tbuf[i]='\0';
962-
returntbuf;
963-
}
964-
965-
966922

967923
/* ----------
968924
* exec_stmtsIterate over a list of statements

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.59 2005/05/2600:16:31 momjian Exp $
6+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.60 2005/05/2604:08:31 momjian Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -336,11 +336,9 @@ typedef struct
336336
intlineno;
337337
char*label;
338338
List*body;/* List of statements */
339-
List*exceptions;/* List of WHEN clauses */
340-
intn_initvars;
341-
int*initvarnos;
342-
intsqlstate_varno;
343-
intsqlerrm_varno;
339+
List*exceptions;/* List of WHEN clauses */
340+
intn_initvars;
341+
int*initvarnos;
344342
}PLpgSQL_stmt_block;
345343

346344

‎src/test/regress/expected/plpgsql.out

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,29 +2380,3 @@ ERROR: control reached end of function without RETURN
23802380
CONTEXT: PL/pgSQL function "missing_return_expr"
23812381
drop function void_return_expr();
23822382
drop function missing_return_expr();
2383-
-- test SQLSTATE and SQLERRM
2384-
create function trap_exceptions() returns void as $_$
2385-
begin
2386-
begin
2387-
raise exception 'first exception';
2388-
exception when others then
2389-
raise notice '% %', SQLSTATE, SQLERRM;
2390-
end;
2391-
raise notice '% %', SQLSTATE, SQLERRM;
2392-
begin
2393-
raise exception 'last exception';
2394-
exception when others then
2395-
raise notice '% %', SQLSTATE, SQLERRM;
2396-
end;
2397-
return;
2398-
end; $_$ language plpgsql;
2399-
select trap_exceptions();
2400-
NOTICE: P0001 first exception
2401-
NOTICE: 00000 Successful completion
2402-
NOTICE: P0001 last exception
2403-
trap_exceptions
2404-
-----------------
2405-
2406-
(1 row)
2407-
2408-
drop function trap_exceptions();

‎src/test/regress/sql/plpgsql.sql

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,24 +2018,3 @@ select missing_return_expr();
20182018

20192019
dropfunction void_return_expr();
20202020
dropfunction missing_return_expr();
2021-
2022-
-- test SQLSTATE and SQLERRM
2023-
createfunctiontrap_exceptions() returns voidas $_$
2024-
begin
2025-
begin
2026-
raise exception'first exception';
2027-
exception when others then
2028-
raise notice'% %', SQLSTATE, SQLERRM;
2029-
end;
2030-
raise notice'% %', SQLSTATE, SQLERRM;
2031-
begin
2032-
raise exception'last exception';
2033-
exception when others then
2034-
raise notice'% %', SQLSTATE, SQLERRM;
2035-
end;
2036-
return;
2037-
end; $_$ language plpgsql;
2038-
2039-
select trap_exceptions();
2040-
2041-
dropfunction trap_exceptions();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp