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 -> Problem with cursor in ProC (Oracle 8)

Problem with cursor in ProC (Oracle 8)

From: Trevor Barrie <tbarrie_at_ibm.net>
Date: 31 Mar 1999 22:17:41 GMT
Message-ID: <37029f05@news1.us.ibm.net>


Has anybody out there experienced an inexplicable error message 1001 (invalid cursor) when they attempt to close a cursor, followed by a program crash when they attempt to disconnect? My code is as follows:



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlcpr.h>
#include <sqlca.h>
#include "/users/students/tbarrie/cs480/dbmodules/include/bjreg.h"
/*This just defines the temporarytimetable_rec structure*/

/* Define constants for VARCHAR lengths. */
#define LOGIN_LEN 40

EXEC SQL INCLUDE "/users/students/tbarrie/cs480/dbmodules/include/connect.c";

int RetSectionsAtTime(int ST, int ET, int D, temporarytimetable_rec **Courses,

                      int *NumCourses)
{ int i;

   EXEC SQL Begin Declare Section;

     int n;
     temporarytimetable_rec Course;
     int StartTime;
     int EndTime;
     int Days;

   EXEC SQL End Declare Section;

   StartTime=ST;
   EndTime=ET;
   Days=D;

   EXEC SQL DECLARE sect_cursor CURSOR FOR

     SELECT *
     FROM gmcinnis.TemporaryTimetable
     WHERE StartTime=:StartTime and EndTime=:EndTime and Days=:Days;

   EXEC SQL SELECT count(*) INTO :n FROM gmcinnis.TemporaryTimeTable
     WHERE StartTime=:StartTime and EndTime=:EndTime and Days=:Days;

   printf("Error code after count: %d\n",sqlca.sqlcode);

   *NumCourses = n;

   *Courses = (temporarytimetable_rec *) malloc(n*sizeof(simptemp_rec));

   if (!sqlca.sqlcode)

      EXEC SQL OPEN sect_cursor;

   printf("Error code after cursor open: %d\n",sqlca.sqlcode);

   for(i=0;i<n && !sqlca.sqlcode;i++)
   {
     EXEC SQL FETCH sect_cursor INTO :Course;

     printf("Error code after fetch: %d\n",sqlca.sqlcode);

     strncpy((*Courses)[i].CourseCode,Course.CourseCode,6);
     (*Courses)[i].CourseNum = Course.CourseNum;
     (*Courses)[i].Section = Course.Section;
     strncpy((*Courses)[i].BuildCode,Course.BuildCode,5);
     (*Courses)[i].RoomNum = Course.RoomNum;
     (*Courses)[i].Days = Course.Days;
     (*Courses)[i].StartTime = Course.StartTime;
     (*Courses)[i].EndTime = Course.EndTime;
     strncpy((*Courses)[i].FacultyCode,Course.FacultyCode,6);
     (*Courses)[i].Requirements = Course.Requirements;
     (*Courses)[i].ExpectedSize = Course.ExpectedSize;
   }

   if (!sqlca.sqlcode)

      EXEC SQL CLOSE sect_cursor;

   return (sqlca.sqlcode);
}

/* main function for testing purposes */ void main(int argc,char **argv)
{ temporarytimetable_rec *results;

   int num,i;

   Connect("gmcinnis/jfish_at_osid");

   printf("Error code:%d\n",RetSectionsAtTime(830,945,2,&results,&num));    printf("%d records found\n",num);
   for (i=0;i<num;i++)

      printf("%s %d %c %s %d %d %d %d %s %d %d\n",results[i].CourseCode,
	     results[i].CourseNum, results[i].Section, results[i].BuildCode,
	     results[i].RoomNum, results[i].Days, results[i].StartTime,
	     results[i].EndTime, results[i].FacultyCode,
	     results[i].Requirements, results[i].ExpectedSize);

   Disconnect();

   free(results);
}


I've been over it a few times without seeing anything wrong. Am I missing something silly here?

(Oh, and apologies if this is the wrong part of the comp.databases.oracle.* hierarchy for questions of this nature; I couldn't find a FAQ for these groups and had to guess.) Received on Wed Mar 31 1999 - 16:17:41 CST

Original text of this message

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