You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This worklog implements support for stacked diagnostic areas and the
GET STACKED DIAGNOSTICS statement.
Each connection has it's own stack of diagnostic areas. The diagnostic area on
top of the stack is called the first diagnostic area. The diagnostic area just
below is the second diagnostic area. There can be more than just two diagnostic
areas, but only the top two are accessible.
Normally all interaction happens with the first diagnostic area. This is where
conditions (errors, warnings, notes) that are raised, are entered. The contents
of the first diagnostic area can be queried by the existing GET [CURRENT]
DIAGNOSTICS statement, while the contents of the second diagnostic area can be
queried by the new GET STACKED DIAGNOSTICS statement.
A new diagnostic area is pushed to the diagnostic area stack when a stored
routine handler is activated. Initially, this new area contains a copy of the
contents of the second diagnostic area (i.e. the first diagnostic area before
the push). This allows GET STACKED DIAGNOSTICS to be used throughout the handler
to inspect the conditions that triggered the handler, regardless of what happens
with the first diagnostic area.
This worklog also fixes
Bug#14342913 SP HANDLER DOES NOT PRESERVE CURRENT DIAGNOSTICS AREA
If a stored routine handler exits with RESIGNAL, the first diagnostic area now
contains all conditions present when the handler was activated + the condition
added by RESIGNAL. Before this fix, only the first condition present at handler
activation was preserved.
The worklog also contains serveral refactorings of the error handling API.
Copy file name to clipboardExpand all lines: mysql-test/r/get_diagnostics.result
+129
Original file line number
Diff line number
Diff line change
@@ -800,3 +800,132 @@ GET DIAGNOSTICS @var1 = NUMBER;
800
800
SHOW STATUS LIKE 'Com%get_diagnostics';
801
801
Variable_name Value
802
802
Com_get_diagnostics 1
803
+
#
804
+
# WL#6406 Stacked diagnostic areas
805
+
#
806
+
#
807
+
# Test non-reserved keywords: STACKED
808
+
CREATE TABLE t1 (stacked INT);
809
+
INSERT INTO t1 (stacked) values (1);
810
+
SELECT stacked FROM t1 WHERE stacked = 1;
811
+
stacked
812
+
1
813
+
SELECT `stacked` FROM t1 WHERE `stacked` = 1;
814
+
stacked
815
+
1
816
+
DROP TABLE t1;
817
+
CREATE PROCEDURE p1()
818
+
BEGIN
819
+
DECLARE stacked INT DEFAULT 1;
820
+
SELECT stacked;
821
+
END|
822
+
CALL p1();
823
+
stacked
824
+
1
825
+
DROP PROCEDURE p1;
826
+
#
827
+
# Test GET STACKED DIAGNOSTICS syntax
828
+
GET STACKED;
829
+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
830
+
GET STACKED DIAGNOSTICS;
831
+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
832
+
#
833
+
# Error if used without active HANDLER
834
+
GET STACKED DIAGNOSTICS @var1 = NUMBER;
835
+
ERROR 0Z002: GET STACKED DIAGNOSTICS when handler not active
836
+
CREATE PROCEDURE p1() GET STACKED DIAGNOSTICS @var1 = NUMBER;
837
+
CALL p1();
838
+
ERROR 0Z002: GET STACKED DIAGNOSTICS when handler not active
839
+
DROP PROCEDURE p1;
840
+
CREATE FUNCTION f1() RETURNS INT
841
+
BEGIN
842
+
GET STACKED DIAGNOSTICS @var1 = NUMBER;
843
+
RETURN 1;
844
+
END|
845
+
SELECT f1();
846
+
ERROR 0Z002: GET STACKED DIAGNOSTICS when handler not active
847
+
DROP FUNCTION f1;
848
+
#
849
+
# GET CURRENT DIAGNOSTICS = GET STACKED DIAGNOSTICS
850
+
# when handler is first activated
851
+
# GET STACKED DIAGNOSTICS doesn't change during handler
852
+
CREATE TABLE t1(a INT);
853
+
CREATE PROCEDURE p1()
854
+
BEGIN
855
+
DECLARE EXIT HANDLER FOR SQLEXCEPTION
856
+
BEGIN
857
+
DECLARE msg1 TEXT;
858
+
DECLARE errno1 INT;
859
+
DECLARE msg2 TEXT;
860
+
DECLARE errno2 INT;
861
+
DECLARE msg4 TEXT;
862
+
DECLARE errno4 INT;
863
+
# Should be identical
864
+
GET CURRENT DIAGNOSTICS CONDITION 1 msg1 = MESSAGE_TEXT, errno1 = MYSQL_ERRNO;
0 commit comments