Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: does not break out the fetch of the cursor

Re: does not break out the fetch of the cursor

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Thu, 23 Dec 1999 07:32:10 -0500
Message-ID: <m1546s07nmotfjekumt6069eukrcc7tr3d@4ax.com>


A copy of this was sent to Wim Derweduwe <kalimero_at_ace.ulyssis.student.kuleuven.ac.be> (if that email address didn't require changing) On Thu, 23 Dec 1999 09:12:48 +0100, you wrote:

>
>The following code goes in an eternal loop when fetching the region codes.
>It does not break out of the loop and just keeps going on forever
>repeating always the last one that it teched.
>
>Anyone any idea I putted even many breaks, to make sure it wasn't on the
>wrong place but it didn't help.
>
>

I just ran your code verbaitim (after cutting out the database_login.h and region.h includes that i did not have and did not need...)

It worked the first time around. I created:

bsg_station ( country varchar2(2), region varchar(2) )

and filled it with:

begin

   for i in 1 .. 99 loop

       insert into bsg_station values ( to_char(i,'fm00'), to_char(i,'fm00') );    end loop;
   commit;
end;

ran your progam and it produced:

$ ./t
Starting initialise the regions.
Starting to log into the database.
Logged into the database.
Logged in for the Regions.
Starting to read the regions from the database. Found region.
country=|01|-|01|, region=|01|-|01|
Found region.
country=|02|-|02|, region=|02|-|02|
.....
country=|98|-|98|, region=|98|-|98|
Found region.
country=|99|-|99|, region=|99|-|99|
Read the Regions and put them in the structure. The regions are read in a structure

You don't have the table structure posted -- if either region or country can be
>2 bytes in the datbase -- beware of strncpy without putting a NULL terminator.
for example, you've coded:

                strncpy (p->country, region_data.country, 3);
                strncpy (p->region, region_data.region, 3);
                p->next = NULL;

if (debug) fprintf (stderr, "country=|%s|-|%s|, region=|%s|-|%s|\n", region_data.country, p->country,
region_data.region, p->region);

but strncpy doesn't have to null terminate (so the fprintf is questionable).... you should:

strncpy( p->country, region_data.country, sizeof(p->country) ); p->country[ sizeof(p->country)-1 ] = 0;

to copy at most sizeof() bytes and NULL terminate the string.

Can you post the create for the table and the smallest amount of sample data to reproduce?

>
>

--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Thu Dec 23 1999 - 06:32:10 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US