Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
dabde323
Commit
dabde323
authored
May 26, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Back out SQLSTATE and SQLERRM support.
parent
4c862b18
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
135 deletions
+18
-135
doc/src/sgml/plpgsql.sgml
doc/src/sgml/plpgsql.sgml
+7
-8
src/pl/plpgsql/src/gram.y
src/pl/plpgsql/src/gram.y
+5
-28
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_exec.c
+2
-46
src/pl/plpgsql/src/plpgsql.h
src/pl/plpgsql/src/plpgsql.h
+4
-6
src/test/regress/expected/plpgsql.out
src/test/regress/expected/plpgsql.out
+0
-26
src/test/regress/sql/plpgsql.sql
src/test/regress/sql/plpgsql.sql
+0
-21
No files found.
doc/src/sgml/plpgsql.sgml
View file @
dabde323
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.6
8 2005/05/26 00:16
:31 momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.6
9 2005/05/26 04:08
:31 momjian Exp $
-->
-->
<chapter id="plpgsql">
<chapter id="plpgsql">
...
@@ -2007,13 +2007,12 @@ END LOOP;
...
@@ -2007,13 +2007,12 @@ END LOOP;
</indexterm>
</indexterm>
<para>
<para>
Any error occurring in <application>PL/pgSQL</> sets variables
By default, any error occurring in a <application>PL/pgSQL</>
<varname>SQLSTATE</> and <varname>SQLERRM</>, and, by default,
function aborts execution of the function, and indeed of the
aborts execution of the function, and indeed of the surrounding
surrounding transaction as well. You can trap errors and recover
transaction as well. You can trap errors and recover from them by
from them by using a <command>BEGIN</> block with an
using a <command>BEGIN</> block with an <literal>EXCEPTION</>
<literal>EXCEPTION</> clause. The syntax is an extension of the
clause. The syntax is an extension of the normal syntax for a
normal syntax for a <command>BEGIN</> block:
<command>BEGIN</> block:
<synopsis>
<synopsis>
<optional> <<<replaceable>label</replaceable>>> </optional>
<optional> <<<replaceable>label</replaceable>>> </optional>
...
...
src/pl/plpgsql/src/gram.y
View file @
dabde323
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* procedural language
* procedural language
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.7
1 2005/05/26 03:18:53 neilc
Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.7
2 2005/05/26 04:08:31 momjian
Exp $
*
*
* This software is copyrighted by Jan Wieck - Hamburg.
* This software is copyrighted by Jan Wieck - Hamburg.
*
*
...
@@ -80,11 +80,6 @@ static void plpgsql_sql_error_callback(void *arg);
...
@@ -80,11 +80,6 @@ static void plpgsql_sql_error_callback(void *arg);
int n_initvars;
int n_initvars;
int *initvarnos;
int *initvarnos;
} declhdr;
} declhdr;
struct
{
int sqlstate_varno;
int sqlerrm_varno;
} fict_vars;
List *list;
List *list;
PLpgSQL_type *dtype;
PLpgSQL_type *dtype;
PLpgSQL_datum *scalar; /* a VAR, RECFIELD, or TRIGARG */
PLpgSQL_datum *scalar; /* a VAR, RECFIELD, or TRIGARG */
...
@@ -101,7 +96,6 @@ static void plpgsql_sql_error_callback(void *arg);
...
@@ -101,7 +96,6 @@ static void plpgsql_sql_error_callback(void *arg);
PLpgSQL_diag_item *diagitem;
PLpgSQL_diag_item *diagitem;
}
}
%type <fict_vars> fict_vars_sect
%type <declhdr> decl_sect
%type <declhdr> decl_sect
%type <varname> decl_varname
%type <varname> decl_varname
%type <str> decl_renname
%type <str> decl_renname
...
@@ -250,22 +244,19 @@ opt_semi :
...
@@ -250,22 +244,19 @@ opt_semi :
| ';'
| ';'
;
;
pl_block : decl_sect
fict_vars_sect
K_BEGIN lno proc_sect exception_sect K_END
pl_block : decl_sect K_BEGIN lno proc_sect exception_sect K_END
{
{
PLpgSQL_stmt_block *new;
PLpgSQL_stmt_block *new;
new = palloc0(sizeof(PLpgSQL_stmt_block));
new = palloc0(sizeof(PLpgSQL_stmt_block));
new->cmd_type = PLPGSQL_STMT_BLOCK;
new->cmd_type = PLPGSQL_STMT_BLOCK;
new->lineno = $
4
;
new->lineno = $
3
;
new->label = $1.label;
new->label = $1.label;
new->n_initvars = $1.n_initvars;
new->n_initvars = $1.n_initvars;
new->initvarnos = $1.initvarnos;
new->initvarnos = $1.initvarnos;
new->body = $5;
new->body = $4;
new->exceptions = $6;
new->exceptions = $5;
new->sqlstate_varno = $2.sqlstate_varno;
new->sqlerrm_varno = $2.sqlerrm_varno;
plpgsql_ns_pop();
plpgsql_ns_pop();
...
@@ -273,20 +264,6 @@ pl_block : decl_sect fict_vars_sect K_BEGIN lno proc_sect exception_sect K_END
...
@@ -273,20 +264,6 @@ pl_block : decl_sect fict_vars_sect K_BEGIN lno proc_sect exception_sect K_END
}
}
;
;
fict_vars_sect :
{
PLpgSQL_variable *var;
plpgsql_ns_setlocal(false);
var = plpgsql_build_variable("sqlstate", 0,
plpgsql_build_datatype(TEXTOID, -1), true);
$$.sqlstate_varno = var->dno;
var = plpgsql_build_variable("sqlerrm", 0,
plpgsql_build_datatype(TEXTOID, -1), true);
$$.sqlerrm_varno = var->dno;
plpgsql_add_initdatums(NULL);
}
;
decl_sect : opt_label
decl_sect : opt_label
{
{
...
...
src/pl/plpgsql/src/pl_exec.c
View file @
dabde323
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* procedural language
* procedural language
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.14
0 2005/05/26 03:18:53 neilc
Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.14
1 2005/05/26 04:08:31 momjian
Exp $
*
*
* This software is copyrighted by Jan Wieck - Hamburg.
* This software is copyrighted by Jan Wieck - Hamburg.
*
*
...
@@ -180,7 +180,6 @@ static Datum exec_simple_cast_value(Datum value, Oid valtype,
...
@@ -180,7 +180,6 @@ static Datum exec_simple_cast_value(Datum value, Oid valtype,
static
void
exec_init_tuple_store
(
PLpgSQL_execstate
*
estate
);
static
void
exec_init_tuple_store
(
PLpgSQL_execstate
*
estate
);
static
bool
compatible_tupdesc
(
TupleDesc
td1
,
TupleDesc
td2
);
static
bool
compatible_tupdesc
(
TupleDesc
td1
,
TupleDesc
td2
);
static
void
exec_set_found
(
PLpgSQL_execstate
*
estate
,
bool
state
);
static
void
exec_set_found
(
PLpgSQL_execstate
*
estate
,
bool
state
);
static
char
*
unpack_sql_state
(
int
ssval
);
/* ----------
/* ----------
...
@@ -748,20 +747,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
...
@@ -748,20 +747,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
int
i
;
int
i
;
int
n
;
int
n
;
/* setup SQLSTATE and SQLERRM */
PLpgSQL_var
*
var
;
var
=
(
PLpgSQL_var
*
)
(
estate
->
datums
[
block
->
sqlstate_varno
]);
var
->
isnull
=
false
;
var
->
freeval
=
true
;
var
->
value
=
DirectFunctionCall1
(
textin
,
CStringGetDatum
(
"00000"
));
var
=
(
PLpgSQL_var
*
)
(
estate
->
datums
[
block
->
sqlerrm_varno
]);
var
->
isnull
=
false
;
var
->
freeval
=
true
;
var
->
value
=
DirectFunctionCall1
(
textin
,
CStringGetDatum
(
"Successful completion"
));
/*
/*
* First initialize all variables declared in this block
* First initialize all variables declared in this block
*/
*/
...
@@ -777,7 +762,7 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
...
@@ -777,7 +762,7 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
if
(
var
->
freeval
)
if
(
var
->
freeval
)
{
{
pfree
(
DatumGetPointer
(
var
->
value
));
pfree
(
(
void
*
)
(
var
->
value
));
var
->
freeval
=
false
;
var
->
freeval
=
false
;
}
}
...
@@ -870,15 +855,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
...
@@ -870,15 +855,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
RollbackAndReleaseCurrentSubTransaction
();
RollbackAndReleaseCurrentSubTransaction
();
MemoryContextSwitchTo
(
oldcontext
);
MemoryContextSwitchTo
(
oldcontext
);
CurrentResourceOwner
=
oldowner
;
CurrentResourceOwner
=
oldowner
;
/* set SQLSTATE and SQLERRM variables */
var
=
(
PLpgSQL_var
*
)
(
estate
->
datums
[
block
->
sqlstate_varno
]);
pfree
(
DatumGetPointer
(
var
->
value
));
var
->
value
=
DirectFunctionCall1
(
textin
,
CStringGetDatum
(
unpack_sql_state
(
edata
->
sqlerrcode
)));
var
=
(
PLpgSQL_var
*
)
(
estate
->
datums
[
block
->
sqlerrm_varno
]);
pfree
(
DatumGetPointer
(
var
->
value
));
var
->
value
=
DirectFunctionCall1
(
textin
,
CStringGetDatum
(
edata
->
message
));
/*
/*
* If AtEOSubXact_SPI() popped any SPI context of the subxact,
* If AtEOSubXact_SPI() popped any SPI context of the subxact,
...
@@ -943,26 +919,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
...
@@ -943,26 +919,6 @@ exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
return
PLPGSQL_RC_OK
;
return
PLPGSQL_RC_OK
;
}
}
/*
* unpack MAKE_SQLSTATE code
* This code is copied from backend/utils/error/elog.c.
*/
static
char
*
unpack_sql_state
(
int
ssval
)
{
static
char
tbuf
[
12
];
int
i
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
tbuf
[
i
]
=
PGUNSIXBIT
(
ssval
);
ssval
>>=
6
;
}
tbuf
[
i
]
=
'\0'
;
return
tbuf
;
}
/* ----------
/* ----------
* exec_stmts Iterate over a list of statements
* exec_stmts Iterate over a list of statements
...
...
src/pl/plpgsql/src/plpgsql.h
View file @
dabde323
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* procedural language
* procedural language
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.
59 2005/05/26 00:16
:31 momjian Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.
60 2005/05/26 04:08
:31 momjian Exp $
*
*
* This software is copyrighted by Jan Wieck - Hamburg.
* This software is copyrighted by Jan Wieck - Hamburg.
*
*
...
@@ -336,11 +336,9 @@ typedef struct
...
@@ -336,11 +336,9 @@ typedef struct
int
lineno
;
int
lineno
;
char
*
label
;
char
*
label
;
List
*
body
;
/* List of statements */
List
*
body
;
/* List of statements */
List
*
exceptions
;
/* List of WHEN clauses */
List
*
exceptions
;
/* List of WHEN clauses */
int
n_initvars
;
int
n_initvars
;
int
*
initvarnos
;
int
*
initvarnos
;
int
sqlstate_varno
;
int
sqlerrm_varno
;
}
PLpgSQL_stmt_block
;
}
PLpgSQL_stmt_block
;
...
...
src/test/regress/expected/plpgsql.out
View file @
dabde323
...
@@ -2380,29 +2380,3 @@ ERROR: control reached end of function without RETURN
...
@@ -2380,29 +2380,3 @@ ERROR: control reached end of function without RETURN
CONTEXT: PL/pgSQL function "missing_return_expr"
CONTEXT: PL/pgSQL function "missing_return_expr"
drop function void_return_expr();
drop function void_return_expr();
drop function missing_return_expr();
drop function missing_return_expr();
-- test SQLSTATE and SQLERRM
create function trap_exceptions() returns void as $_$
begin
begin
raise exception 'first exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
raise notice '% %', SQLSTATE, SQLERRM;
begin
raise exception 'last exception';
exception when others then
raise notice '% %', SQLSTATE, SQLERRM;
end;
return;
end; $_$ language plpgsql;
select trap_exceptions();
NOTICE: P0001 first exception
NOTICE: 00000 Successful completion
NOTICE: P0001 last exception
trap_exceptions
-----------------
(1 row)
drop function trap_exceptions();
src/test/regress/sql/plpgsql.sql
View file @
dabde323
...
@@ -2018,24 +2018,3 @@ select missing_return_expr();
...
@@ -2018,24 +2018,3 @@ select missing_return_expr();
drop
function
void_return_expr
();
drop
function
void_return_expr
();
drop
function
missing_return_expr
();
drop
function
missing_return_expr
();
-- test SQLSTATE and SQLERRM
create
function
trap_exceptions
()
returns
void
as
$
_
$
begin
begin
raise
exception
'first exception'
;
exception
when
others
then
raise
notice
'% %'
,
SQLSTATE
,
SQLERRM
;
end
;
raise
notice
'% %'
,
SQLSTATE
,
SQLERRM
;
begin
raise
exception
'last exception'
;
exception
when
others
then
raise
notice
'% %'
,
SQLSTATE
,
SQLERRM
;
end
;
return
;
end
;
$
_
$
language
plpgsql
;
select
trap_exceptions
();
drop
function
trap_exceptions
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment