Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how retrieve several values returned by a function

Status
Not open for further replies.

JeanVal

Programmer
Dec 17, 2004
2
0
0
US
Hi all-

I am using the informix objects interface for c++ and I can't figure how to retrieve several values returned by a function.

Let's say that I have a function that returns 5 variables: (RETURN h_time, d_time, w_time, m_time, y_time;)

but the command:
ITRoutineManager routine(conn);
ITvalue val2;
val2 = routine.ExecForValue();
allows to retreive only 1 value.

Do I am missing something?

Thanks for your help,

Manu


===============================
Piece of code that I am using:

ITRoutineManager routine(conn);
ITBool bret = routine.GetRoutine("function get_time(int,int)"); //RETURN h_time, d_time, w_time, m_time, y_time;

ITValue *val, *val1, *val2;
val = routine.Param(0);
ITRoutineManager routine(conn);

ITBool bret = routine.GetRoutine("function get_time(int,int)");


ITValue *val, *val1, *val2;
val = routine.Param(0); //
val->FromPrintable("1");
val->Release();
//
val1 = routine.Param(1);
val1->FromPrintable("2");
val1->Release();

val2 = routine.ExecForValue();

cout << "Type of get_time return value is " << (routine.ResultType())->Name()<<":" <<(routine.ResultType())->ColumnCount()<< endl;
//output=> Type of get_time return value is integer:-1



=============================
piece of code from the function:

CREATE FUNCTION get_time(w_last smallint, perf smallint)
DEFINE p_sql_err integer;
DEFINE h_time_id integer;
DEFINE w_time_id integer;
DEFINE d_time_id integer;
DEFINE m_time_id integer;
DEFINE y_time_id integer;
[...]
RETURN h_time_id, d_time_id, w_time_id, m_time_id, y_time_id;

END FUNCTION
 
Have you tried concatenating the variables, delimiting them with a unique character (|,*), and then passing one variable between the function and main program?
 
In fact, I don't want to modify the code of the function. I am sure there is a trick with the C++ objects, but I can't figure it out...
 
Hi, I'm new to the list but thought I'd take a pot at answering your question.

The short answer is, you can't. At least I've not come across a way of passing back multiple values to a 'c' function. In fact, the only way to do it in 'c' itself is to use pointers. There no point going down that path, you're just going to complicate things....

However, I have a suggestion, its not perfect but will probably do you for now.

Why not, in your 4gl module, define h_time, d_time, w_time, m_time, y_time all as MODULAR variables?
Then, for each one write a seperate funtion that will just return each value.
i.e.

function get_htime()
return h_time
end function

function get_dtime()
return d_time
end function

etc

Then, within the 'c' code you call your main function first that will set all the valuse, then for each value call its function in the 4gl?

Its not perfect, but it'll work. And to be honest, I'm not sure there is another way to do it easily.

Cheers

Jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top