Xref: alice comp.databases.oracle.misc:28494
From: tbarrie@ibm.net (Trevor Barrie)
Newsgroups: comp.databases.oracle.misc
Subject: Re: Problem with cursor in ProC (Oracle 8)
References: <37029f05@news1.us.ibm.net> <37076883.2807847@192.86.155.100>
User-Agent: slrn/0.9.5.3 (UNIX)
Message-ID: <3707e21a@news1.us.ibm.net>
Date: 4 Apr 1999 22:05:14 GMT
X-Trace: 4 Apr 1999 22:05:14 GMT, 129.37.170.66
Organization: IBM Global Services - Remote Access Mail & News Services
Lines: 41
X-Notice: Items posted that violate the IBM.NET Acceptable Use Policy
X-Notice: should be reported to postmaster@ibm.net
X-Complaints-To: postmaster@ibm.net
Path: alice!news-feed.fnsi.net!news.idt.net!news-peer.gip.net!news.gsl.net!gip.net!newsfeed2.us.ibm.net!ibm.net!news1.us.ibm.net!tbarrie

On Thu, 01 Apr 1999 13:32:12 GMT, Thomas Kyte <tkyte@us.oracle.com> wrote:

>I *believe* it just might be the line:
>
>   *Courses = (temporarytimetable_rec *) malloc(n*sizeof(simptemp_rec));
>
>I think it should be
>
>   *Courses = 
>     (temporarytimetable_rec *) malloc(n*sizeof(temporarytimetable_rec ));
>                                                ^^^^^^^^^^^^^^^^^^^^^
>
>that very well could be causing the problem.  

Seems to have done it. I knew it had to be something silly.

>Also, the logic in your loop for error handling is wrong.  You need to check
>the sqlca.sqlcode after each fetch, else you'll have a big risk of seg 
>faulting if the fetch fails, doesn't fill in the buffer and you attempt to 
>strcpy from it anyway.

Well, I'm using strncpy, not strcpy; I thought the worst that could happen
there is that I'd get gibberish in my destination string (which will never
be read anyway in case of a sql error).

>Note also that what you are doing is 'sort of bad'.  If there is any chance
>that someone might be inserting or deleting whilst you are doing this -- 
>the count(*) you get in the select count(*) *won't be* the number of records 
>you actually fetch.

I hadn't thought of that, but as it happens nobody else is going to be
modifying those tables while this app is running.

>I see you have a %c in your format below.  I would not suggest fetching into
>chars -- its going to want a null terminated string (2 bytes).  put it in a
>string.

The documentation seems to think it can fetch into a char, and I haven't
had problems in other modules where I do so.

Thanks for your help.
