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 > how to get full sql code in script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-15-09, 15:50
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
how to get full sql code in script

DB2 v8.2 ESE on AIX v5.3 / DB2 v9.5.1 ESE on AIX v6.1
anyone please - how can we get full sql code in the script? Like in example below we are using this logic to process sql errors:
--------------------------------------------------------------
function check_SQL
{
mSQLCode=$?
if [ $mSQLCode -ne 0 ]; then
echo "\nSCRIPT FAILED!!! SQL error: $1\n " | tee -a $mLogFile
exit 1
fi
}

db2 -v connect to $mdbName >> $mLogFile
check_SQL "Connect to database failed!"
-------------------------------------------------------------
output (in file):
connect to
SQL0104N An unexpected token "END-OF-STATEMENT" was found following "TO".
Expected tokens may include: "<identifier>". SQLSTATE=42601
-------------------------------------------------------------

So in function we get and process only sqlcode 0 or 'not 0'. In this case above mSQLCode=4 but we would like to have 'SQL0104N'.

Thanks in advance
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #2 (permalink)  
Old 09-15-09, 17:05
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You can use option '-a' for the DB2 CLP and parse the SQLCODE from the dumped SQLCA.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 09-15-09, 19:43
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by stolze
You can use option '-a' for the DB2 CLP and parse the SQLCODE from the dumped SQLCA.
the problem is that results and sql erros go to the same output. does this way separate them? would you happen to have an example, Knut?
thanks in advance
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #4 (permalink)  
Old 09-16-09, 04:38
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You are right on that the SQLCA is written to standard output - like the results. So you would have to parse the output. But that is really simple and straight-forward with a regexp (Perl style) like:
Code:
/sqlcaid\s*:\s*SQLCA\s*sqlcabc:\s*\d+\s*sqlcode:\s*(\d+)/
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 09-16-09, 09:34
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
Quote:
Originally Posted by stolze
You are right on that the SQLCA is written to standard output - like the results. So you would have to parse the output. But that is really simple and straight-forward with a regexp (Perl style) like:
Code:
/sqlcaid\s*:\s*SQLCA\s*sqlcabc:\s*\d+\s*sqlcode:\s*(\d+)/
I think I can do the same with standard error message (SQL0104N An unexpected token "END-OF-STATEMENT"...). Just need to output it somewhere else...
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
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