473,469 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

About Exit Handler

Hi All
I have one STATES table with two fields (STATECODE, NAME).
I had written following stored procedure on this table

CREATE PROCEDURE ESCRIP.STATES_GETALL(OUT @ERRORCODE INT, OUT
@ERRORDESCRIPTION VARCHAR(200))
LANGUAGE SQL
READS SQL DATA
DYNAMIC RESULT SETS 1
------------------------------------------------------------------------
-- This stored procedure return all rows from STATE table
-- Created by Suresh
-- Created Date 05/17/2006
-- Version 1.0
------------------------------------------------------------------------
P1: BEGIN
DECLARE SQLCODE INT DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE CURSTATE CURSOR WITH RETURN TO CALLER FOR SELECT STATECODE,
NAME FROM ESCRIP.STATES ORDER BY STATECODE WITH CS;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SET @ERRORDESCRIPTION=SQLSTATE;
SET @ERRORCODE = SQLCODE;
END;
OPEN CURSTATE;
SET @ERRORCODE = SQLCODE;
END P1

This stored procedure retuens me CURSOR .
But when STATES table is in 'check pending state' this stored procedure
gives me SQLTATE error though i had written exit handler for the stored
procedure.
As per my expectation it should return me SQLCODE and SQLSATE in output
parameter.
So please explain me what is problem in this stored procedure.

Thanks
Suresh

May 22 '06 #1
8 10966
Suresh,

The problem is simple. SQLSTATE and SQLCODE variables are set EACH TIME
SQL instruction is executed.

[1] SET @ERRORDESCRIPTION=SQLSTATE;
[2] SET @ERRORCODE = SQLCODE;

Line [1] sets proper error state and finishes successfully.
Line [2] sets sqlcode to zero because line [1] was successful !

Get the values using single SQL statement:
values (SQLSTATE, SQLCODE) into var1, var2 ;

-- Artur Wronski

May 22 '06 #2
As table is in check pending state it does execute line one also.
means its not getting value for SQLSTATE also.

After OPEN CURSTATE
it gives folowing error message ....

ESCRIP.STATES_GETALL - Debug started.
STATES_GETALL - Exception occurred while debugging:
A database manager error occurred.[IBM][CLI Driver][DB2/LINUX] SQL0668N
Operation not allowed for reason code "1" on table "ESCRIP.STATES".
SQLSTATE=57016

STATES_GETALL - Roll back completed successfully.
ESCRIP.STATES_GETALL - Debug failed.
Can any one suggest me why this is happening

May 23 '06 #3
For me it is a bug (for 8.1.11, Viper C1)

SQLSTATE '57016' is not passed to handler. If you raise the exception
using SIGNAL statement, handler code is activated (the same problem is
if tablespace is quiesced).

Call tech support and tell them to reporduce it on database SAMPLE:

CREATE PROCEDURE S57016(OUT P_SQLSTATE CHAR(5))
DYNAMIC RESULT SETS 1

P1: BEGIN
DECLARE SQLCODE INT DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE CUR1 CURSOR WITH RETURN TO CALLER FOR SELECT EMPNO FROM
EMPLOYEE;

DECLARE EXIT HANDLER FOR SQLSTATE '57016'
BEGIN
SET P_SQLSTATE= '57016';
END;

--SIGNAL SQLSTATE '57016';
OPEN CUR1;

END P1

set integrity for employee off

call s57016(?)

-- Artur Wronski

May 23 '06 #4
> For me it is a bug (for 8.1.11, Viper C1)
SQLSTATE '57016' is not passed to handler. If you raise the exception
using SIGNAL statement, handler code is activated (the same problem is
if tablespace is quiesced).


This is not a bug in the exit handler implementation. The reason that
the handler is not triggered is that the OPEN call does not raise the
57016 condition.

The 57016 is raised by the first fetch from the cursor.

May 24 '06 #5
Josh,

you are right !
I was too quick with the conclusion :-)

Suresh,

You have to handle the error in program that receives the result set.
The procedure below fetch first row within the procedure body, and the
handler is activated.

CREATE PROCEDURE S57016(OUT P_SQLSTATE CHAR(5))
DYNAMIC RESULT SETS 1

P1: BEGIN
DECLARE SQLCODE INT DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE V_EMPNO CHAR(6);
DECLARE CUR1 CURSOR WITH RETURN TO CALLER FOR SELECT EMPNO FROM
EMPLOYEE;

DECLARE EXIT HANDLER FOR SQLSTATE '57016'
BEGIN
SET P_SQLSTATE= '57016';
END;
OPEN CUR1;
FETCH FROM CUR1 INTO V_EMPNO;

END P1

-- Artur Wronski

May 24 '06 #6
> You have to handle the error in program that receives the result set.
The procedure below fetch first row within the procedure body, and the
handler is activated.


Be careful. As coded, that procedure will consume the first row of the
result set - which will not be returned back to the calling
application. There's no way to push back a row into the result set, so
you'll have to either

a) declare another cursor for the express purpose of checking for the
57016 state.
b) return the value you just fetched in an OUT parameter, and have the
calling application be aware of that.

Personally, I'd be more likely to scrap all that, and have the calling
application test for the 57016 condition.

May 24 '06 #7
The "fetch from ..." was only to prove that you are right,

that the first fetch is raising the error (not opening the cursor).

-- Artur

May 24 '06 #8
To check if a table is in check pending state you can also query
SYSCAT.TABLES:

SELECT ACCESS_MODE, STATUS, TABNAME
FROM SYSCAT.TABLES WHERE STATUS = 'C'

http://publib.boulder.ibm.com/infoce...n/r0001063.htm

-- Artur

May 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew Athan | last post by:
I have a python program (snippet below) which does not want to seem to die when I issue a sys.exit() inside the SIGTERM handler. The output below is generated as the result of sending several...
2
by: Ishwar Rattan | last post by:
Here is a piece code (according to blurb on os.wait, the lower order 7 bits of exit status of process should contain the signal number of signal that terminated the process..) and signal number...
0
by: szehau | last post by:
Hi all, I have a program written in C with embeded SQL. Following are the configuration: DB2/LINUX 8.1.5 Thread model: posix gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) My problems...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
2
by: GGerard | last post by:
Hello Is there a way to exit all running procedures with one command? Sometimes a procedure(1) will call another procedure(2) which could call a third procedure(3) and what I would like to...
2
by: Kool-Aide | last post by:
Alright, here goes...When I put a menu strip on the windows form I can double click the exit button to go to the source page and it takes me to the on click exit blah blah blah and you would put...
11
by: vicky | last post by:
hi all, please tell me with example, how the *argv point to the the no of strings.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.