GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Mar-2006, 02:20
jaro's Avatar
jaro jaro is offline
Junior Member
 
Join Date: Nov 2005
Location: somewhere in souteast asia
Posts: 54
jaro will become famous soon enough

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 by removing my logon to database function, so when I try to access the function there should be an error log.


here is the code
CPP / C++ / C 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...
CPP / C++ / C 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
__________________
Action.....reAction
  #2  
Old 21-Mar-2006, 06:49
jaro's Avatar
jaro jaro is offline
Junior Member
 
Join Date: Nov 2005
Location: somewhere in souteast asia
Posts: 54
jaro will become famous soon enough

Re: functions seems not to exit from a certain code block


Hi again,

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

here the code.
CPP / C++ / C 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
__________________
Action.....reAction
  #3  
Old 21-Mar-2006, 13:07
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: functions seems not to exit from a certain code block


what language is that in getData???
  #4  
Old 21-Mar-2006, 23:08
jaro's Avatar
jaro jaro is offline
Junior Member
 
Join Date: Nov 2005
Location: somewhere in souteast asia
Posts: 54
jaro will become famous soon enough

Re: functions seems not to exit from a certain code block


Quote:
Originally Posted by ubergeek
what language is that in getData???

I'm writing an Embedded SQL in C.

stupid me, I forgot to mention this in my first post.
__________________
Action.....reAction
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange C++ code memory leakage problem gaoanyu CPP / C++ Forum 7 04-Nov-2005 08:09
Guidelines for posting requests for help - UPDATED! WaltP CPP / C++ Forum 0 21-Apr-2005 02:44
Problem with int mixed with char,... leitz CPP / C++ Forum 17 07-Dec-2004 20:56
Having a problem Chuckles Computer Hardware Forum 19 13-Sep-2004 12:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

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


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.