Hi there. I have a function that retrieve data from a database. The data retrieved here will be used for creating a xml type of message.The functions does what it is supposed to do. The problem here is when I try to test it for possible error, the functions seems not to exit from a certain code block ( exit ).
here is a sample of my log file
Tue Mar 21 17:07:27 2006 Inside getData
Tue Mar 21 17:07:27 2006 ==============================
Tue Mar 21 17:07:27 2006 SELECT Error: SQL return code of -1024.
Tue Mar 21 17:07:27 2006 SELECT : SQL Error message='SQL1024N A database connection does not exist. SQLSTATE=08003
'.
Tue Mar 21 17:07:27 2006 ==============================
Tue Mar 21 17:07:27 2006 SELECT Error: SQL return code of -1024.
Tue Mar 21 17:07:27 2006 SELECT : SQL Error message='SQL1024N A database connection does not exist. SQLSTATE=08003
'.
Tue Mar 21 17:07:27 2006 ==============================
Tue Mar 21 17:07:27 2006 SELECT Error: SQL return code of -1024.
Tue Mar 21 17:07:27 2006 SELECT : SQL Error message='SQL1024N A database connection does not exist. SQLSTATE=08003
'.
Tue Mar 21 17:07:27 2006 ==============================
Tue Mar 21 17:07:27 2006 SELECT Error: SQL return code of -1024.
Tue Mar 21 17:07:27 2006 SELECT : SQL Error message='SQL1024N A database connection does not exist. SQLSTATE=08003
'.
..........
and so on........
I have no idea how to fix this, can anyone help me or atleast give some insight on what is happening here.
BTW: I'm using MVC6 , win2k and my database is DB2. The test I've made here is removing my logon to database function, so when I try to access the function there should be an error log.
here is the code
Code:
int getData()
{
int error = 0;
WriteToLog("Inside getData");
EXEC SQL WHENEVER NOT FOUND GO TO nodata;
EXEC SQL WHENEVER SQLERROR GO TO exit;
EXEC SQL DECLARE cur1 CURSOR FOR
SELECT
DESK,
SYMBOL,
RM_TIME,
PRODUCT,
RM_DATE
FROM QPNL.TABLE_MANAGEMENT
where RM_DATE = (current date) ;
EXEC SQL OPEN cur1;
do {
EXEC SQL FETCH cur1 INTO
:desk,
:symbol,
:sql_time,
:product,
:sql_date;
setData(); // set the retreive data into string/character
if (buildAndSendMsg() == 1)
{
goto exit;
}
} while (1);
nodata:
WriteToLog("CURSOR HAS REACHED END OF TABLE.");
EXEC SQL CLOSE cur1;
return 0;
exit://the function does not exit on this part....it will only continue to print/write to log the ff details.
WriteToLog("============================"); // use for log tracking....
SQLError("SELECT",SQLCODE,&sqlca) ;
EXEC SQL CLOSE cur1;
return 1; //
}
SQLError...
Code:
int SQLError( char *Function, int err, struct sqlca *capointer )
{
//char buf[ 32 ] ;
char sqlState[ 1024 ] ;
char errorMsg[ 1024 ] ;
short rc ;
char temp[500];
if( err ) {
if (!(strcmp("SELECT",Function)==0 && err == 100)){
sprintf( temp,"%s Error: SQL return code of %d.", Function, err ) ;
WriteToLog(temp);
if ( err != -803 ) {
rc = sqlogstt( sqlState, sizeof(sqlState), 80, capointer->sqlstate ) ;
if( sqlaintp( errorMsg, sizeof( errorMsg ), 80, capointer ) > 0 ) {
sprintf(temp,"%s : SQL Error message='%s'.",Function,errorMsg ) ;
WriteToLog(temp);
}
if( !rc ) {
sprintf( temp,"%sSQL State='%s'.",Function,sqlState ) ;
WriteToLog(temp);
}
}
}
}else {
if(memcmp(Function, "UPDATE", 6)==0){
CommitDB();
//WriteToLog("UPDATE of data is successful.");
}
if(memcmp(Function, "INSERT", 6)==0){
CommitDB();
WriteToLog("INSERTION of data is successful.");
}
if(memcmp(Function, "DELETE", 6)==0){
CommitDB();
WriteToLog("DELETION of data is successful.");
}
if(memcmp(Function, "CONNECT",7)==0){
WriteToLog("Connection to database has been established.");
}
}
return( err ) ;
}
I appologize if my english seems bad, it's not my native language.
Regards,
jaro