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

Home -> Community -> Usenet -> c.d.o.tools -> Re: Pro*C/C++ - How do I OPEN CURSOR and FETCH in different fucntions

Re: Pro*C/C++ - How do I OPEN CURSOR and FETCH in different fucntions

From: Mike Coldewey <No_Spam4m_coldewey_at_hotmail.com>
Date: 2000/05/04
Message-ID: <39117822.0@news.kivex.com>#1/1

Cursors don't have to be fetched in the same function that they are declared or opened. It's possible to have the following structure: (kinda pseudocode):

int returnCode;
DeclareMyCursor();
OpenMyCursor();
returnCode = FetchMyCursor();
while (!returnCode)
{

   DoSomethingWithTheData()
   returnCode = FetchMyCursor();
}
CloseMyCursor;

void DeclareMyCursor()
{
exec SQL DECLARE MYCURSOR AS ...
}
void OpenMyCursor()
{
exec SQL OPEN MYCURSOR...
}
int FetchMyCursor()
{
exec SQL Fetch MYCURSOR into <the variables>, etc. return <error from the fetch>
}
void CloseMyCursor()
{
exec SQL CLOSE MYCURSOR...
}

A cursor, not being a C/C++ variable, doesn't have to obey the same scoping rules of a variable. It's part of the SQL session, as I understand it. I don't think that there's a way to declare a cursor globally as a member of the class for the same reason.

Mike
Don Chambers <dchamber_at_mindspring.com> wrote in message news:2kgtgsg93dq2g3884ep69ngatfjm1jfcf5_at_4ax.com...
> I am using Pro*C/C++ and need to have a function that sets up a cursor
> and opens it but I do not need to fetch at this time. I need to fetch
> from another function. How do I fetch in one function using a cursor
> declared and opened in another function?
> Is in possible to declare a cursor globally or as a member of a class?
>
> This is what I am trying to do. If you have a better idea let me
> know.
> I am creating a class for other developers in which they issue a
> select statement and then move through the rows with a MoveNext
> function which sets variables to the data selected. I currently have
> the open and fetch in the same function and I load up a linked list
> with all the data. My MoveNext function iterates through the list and
> sets variables to the current items in the list. On the next MoveNext
> call I move to the next element in the list. This causes two
> problems:
> 1) My Select fucntion is huge and hard to follow becasue all the
> descriptor information (for dynamic SQL), the cursor logic, and the
> linked list logic. If I keep this method I would at least like to
> break it into multiple functions but am having problems becasue the
> cursor can only be fetched in the function in which it is declared.
> 2) On selects with many columns and rows the linked list grows
> huge and consumes much memory. As the user iterates thorugh the list
> and stores the values in other ways (an Array, Container, or their own
> list) this doubles the amount of memory used.
>
>
> Thanks,
> Don
> chambers_at_inquiregroup.com
>
Received on Thu May 04 2000 - 00:00:00 CDT

Original text of this message

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