Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Problem with cursor in ProC (Oracle 8)
On Thu, 01 Apr 1999 13:32:12 GMT, Thomas Kyte <tkyte_at_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. Received on Sun Apr 04 1999 - 17:05:14 CDT