If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Shell script DB2 return code trapping for AIX (UDB V8.1)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-04, 00:01
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
Shell script DB2 return code trapping for AIX (UDB V8.1)

Can someone out there tell me how to check the return codes from a database operation and execute the next step conditionally from within a shell script ?
e.g if I need to do a load and then execute another load after checking for successful completion of the first load how do I do it within a shell script ?
Reply With Quote
  #2 (permalink)  
Old 04-08-04, 00:08
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: Shell script DB2 return code trapping for AIX (UDB V8.1)

It's the same as with any other OS command:

Code:
#!/bin/sh

db2 load from ....
if [ $? != 0 ]; then 
   echo "Error!"
   exit
fi
db2 load from ...
You can find more details in Command Reference
Reply With Quote
  #3 (permalink)  
Old 04-08-04, 03:29
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Re: Shell script DB2 return code trapping for AIX (UDB V8.1)

Quote:
It's the same as with any other OS command:

Code:
#!/bin/sh

db2 load from ....
if [ $? != 0 ]; then 
   echo "Error!"
   exit
fi
db2 load from ...
You can find more details in Command Reference
... except that DB2 will return an exit status of 1 for warnings (e.g. updates where no rows found, loads/imports with warnings). For loads, these warnings may actually want to be treated as errors (particularly those which have involved data mutation). So the long and the short of it is that you are going to have to check the SQLSTATES returned in the stdout to determine if you have any warnings that should be treated as errors for your particular circumstances.

At least that's what I've done in the past (using awk/grep). If you come up with a better solution, please post it.

Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On