C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-21-2006, 03:23 AM   #1
Registered User
 
jaro's Avatar
 
Join Date: Mar 2006
Location: In my Parent House
Posts: 34
functions seems not to exit from a certain code block

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
Quote:
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
jaro is offline   Reply With Quote
Old 03-21-2006, 07:52 AM   #2
Registered User
 
jaro's Avatar
 
Join Date: Mar 2006
Location: In my Parent House
Posts: 34
Hi again,

I've already found the solution to my problem.
I just made some modification.

here 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 (sqlca.sqlcode == 0);


		EXEC SQL WHENEVER SQLERROR CONTINUE; ///

		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;
			EXEC SQL WHENEVER SQLERROR CONTINUE; ///
			return 1; // 
}
although I'm not quite sure if this solution is the best out there, but for now IWFM.

Regards,
Jaro
jaro is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Odd memory leaks Bubba C++ Programming 11 05-25-2006 12:56 AM
Dynamic array of pointers csisz3r C Programming 8 09-25-2005 02:06 PM
HUGE fps jump DavidP Game Programming 23 07-01-2004 10:36 AM
<< !! Posting Code? Read this First !! >> kermi3 Game Programming 0 10-14-2002 01:27 PM
Who will map the scan code (inserted by VKD_Force_keys) to virtual key code? Unregistered Windows Programming 0 02-21-2002 06:05 PM


All times are GMT -6. The time now is 10:40 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22