functions seems not to exit from a certain code block

This is a discussion on functions seems not to exit from a certain code block within the C Programming forums, part of the General Programming Boards category; Hi there. I have a function that retrieve data from a database. The data retrieved here will be used for ...

  1. #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
    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

  2. #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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 12:56 AM
  2. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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