Storing the result of a FETCH in an array (Pro*C)

This is a discussion on Storing the result of a FETCH in an array (Pro*C) within the C Programming forums, part of the General Programming Boards category; Hi, I'm trying, inside a for loop, in Pro*C, TO STORE the result of a fetch in an array, but ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    21

    Storing the result of a FETCH in an array (Pro*C)

    Hi,
    I'm trying, inside a for loop, in Pro*C,
    TO STORE the result of a fetch in an array,
    but I don't want any repeated result in my result array (tableau_stockage in the example)
    the following CODE doesnt WORK, a lot of identical data IS repeated.

    How do i do that ? thanks IN advance

    Code:
    int i, j;
    char v_period_name[1000]; 		
    CHAR tableau_stockage[MAX_TAB_PERIOD][20]; 
    
    /* initialisation */
            	for(i = 0; i < 1000; i++)
           		 {
    			v_period_name[i] = '\0';
            	}      
     
    
    EXEC SQL BEGIN DECLARE SECTION;	
    varchar 	v_period_name_l[1000][25];
    EXEC SQL END DECLARE SECTION;	
    
    EXEC SQL DECLARE cursor_1 CURSOR FOR
                       SELECT 
                               myvalue
                          FROM mytable;
                          
    EXEC SQL OPEN  cursor_1;              
    
    while (1) 
            {   EXEC SQL                                                              
                FETCH cursor_1                                               
                INTO  :v_period_name_l;
    
    for ( i = 0; i < Nb_Enr_Traites_Bloc; i++ )                                           
              {                       	          	    	
            
    	      strncpy(v_period_name, (char *) v_period_name_l[i].arr, 16);
    	      v_period_name[16] = '\0';	          	          
    	       	       		       	       	      
     	      for (j = 0; j < MAX_TAB_PERIOD; j++)  
    	            {	            	
    	               if (!(strcmp(tableau_stockage[j], v_period_name) == 0))                                    
    	                {	
    	                	
    	                if (tableau_stockage[j] == '\0'){
    			  strcpy(tableau_stockage[j], v_period_name); 						
                  		  tableau_stockage[j][16] = '\0';              		  		              	                      		  
                           }
                  		  break; 
                        	}              	                            	            
                        }     	    	
              }  /* end for */
    
     }/* End while */            
    
            EXEC SQL CLOSE cursor_1;
    Last edited by lonbgeach; 06-17-2003 at 11:25 AM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Try some logic like this:

    Code:
    Read new record into temp variable
    FoundIt = false
    For I = 0 to MAX_TAB_PERIOD
      if TableRow[I] equals newitem
      {
        FoundIt = true;
        break;
      }
    End For
    
    if (FoundIt == true)
    {
        Add newitem to the table
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User penney's Avatar
    Join Date
    Jan 2003
    Posts
    47
    The other thing that you can do is use the keyword DISTINCT in your SQL SELECT statement.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    21
    thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing values into a dynamic array
    By porsche911nfs in forum C++ Programming
    Replies: 5
    Last Post: 04-24-2009, 09:08 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM
  4. storing a manipulated array in a new array
    By axon in forum C++ Programming
    Replies: 7
    Last Post: 03-04-2003, 12:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

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