1

It's simple - is there a way to use this lib to call stored procedure or function, that returns more than one result? I know about the ITRoutingManager, but it seems to return just one value..

In details, here's what I mean:

CREATE FUNCTION test_out1( pin INT )
    RETURNING INT;

    DEFINE param INT;
    LET param = 321;

    RETURN param;

END FUNCTION;

Returns 321, I can get the value with ITValue and ITConversions. So this is fine. But the following is not:

CREATE FUNCTION test_out2( pin INT )
    RETURNING INT, INT;

    DEFINE param INT;
    LET param = 321;

    DEFINE param2 INT;
    LET param2 = 123;

    RETURN param, param2;

END FUNCTION;

When I do routine.GetRoutine( "function test_out2( int )" ), it's bound fine, so no problem with that. But see this:

std::cout &lt&lt "Result type: " &lt&lt routine.ResultType()->Name() IsRow() ? "row, " : ", " )
        &lt&lt (routine.ResultType()->IsCollection() ? "collection, " : ", " )
        &lt&lt routine.ResultType()->Quality() &lt&lt "\n\n";

prints integer, , , null, note the integer.. Why is integer, not row, for example. And how to get the 2 values, returned by the function? Another interesting fact - the returned value is 0(when I convert it to int, using the ITConversions class), not 123, nor 321..

There have to be a way. This is a special library, written for Informix servers, by Informix developers and it would be strange, if this is not possible.

The same for functions, but I guess it's the same there.


NOTE: there's no such thing as out parameters in the common case, for informix procedures/functions (Informix: procedure with output parameters?)

Community
  • 1
  • 1
Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
  • You over-estimate the utility of the OIC++ package. It is written in archaic pre-standard C++ using macros instead of templates. It has not been seriously revised since it was written in about 1996 - it got some cleanup a few years ago so that it compiled with fewer complaints from the compiler. Note 'fewer complaints' - not 'no complaints'. I wouldn't recommend it for new code. – Jonathan Leffler Mar 31 '11 at 15:20
  • @Jonathan Leffler - the alternative for me is to use the ODBC driver, it works perfect with Informix server. I wanted to use the OIC++ package, as it's dedicated only to Informix, so I expected it to be faster (it for real-time system with very high load). But it appeared that it's **even slower**, except when using ITRoutineManager - then, through this class, the performance is **twice better**. But only then.. So, could you, please advise? I guess ODBC would be the better choice? Thanks a lot in advance! – Kiril Kirov Mar 31 '11 at 15:35
  • I'm talking about unixODBC, forgot to mention. I saw the description in you profile("Long-time Informix user and developer, experienced in C and Unix") and I will highly appreciate your opinion. – Kiril Kirov Mar 31 '11 at 15:37
  • I would recommend using ODBC over OIC++. The OIC++ interface is built on top of another library, DMI, which in turn is built on top of another library that accesses the DBMS - I forget whether it is ESQL/C or ODBC based, or one of the core libraries those are built on. Using unixODBC as your driver manager and an appropriate ODBC driver makes more sense to me than using OIC++. – Jonathan Leffler Mar 31 '11 at 15:49
  • Thanks a lot! Please add these things in your answer as suggestion and I'll accept it with pleasure (: – Kiril Kirov Mar 31 '11 at 17:11

1 Answers1

1

As you note, Informix does not have 'OUT' parameters really; it returns values.

In regular ESQL/C, you treat a list of output values symmetrically with a list of input values; I would expect to do the same with this code, therefore. Whatever technique you use to pass 2 arguments to the function is likely - but by no means guaranteed - to be how you get multiple returned values.

In case of doubt, treat it as you would treat a SELECT statement that returns multiple rows. That is, do the analogues of:

 PREPARE s FROM "EXECUTE PROCEDURE test_out2(?)";
 DECLARE c CURSOR FOR s;
 OPEN c USING :input_value;
 while (sqlca.sqlcode == 0)
 {
     FETCH c INTO :out_value1, :out_value2;
     if (sqlca.sqlcode != 0)
         break;
     ...use values...
 }
 CLOSE c;
 FREE c;
 FREE s;

I would recommend using ODBC over OIC++. The OIC++ interface is built on top of another library, DMI, which in turn is built on top of another library that accesses the DBMS - I forget whether it is ESQL/C or ODBC based, or one of the core libraries those are built on. Using unixODBC as your driver manager and an appropriate ODBC driver makes more sense to me than using OIC++.


I've no real idea how that looks in OIC++; I've never used it, but only done some cursory maintenance of it.

On the whole, you would be best advised not to use OIC++ for new work. Informix continues to distribute it for backwards compatibility rather than to encourage new use.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • yes, this works fine, but it is twice slower that using the `ITRoutineManager` class, and then it's really better to use ODBC. – Kiril Kirov Mar 31 '11 at 20:43
  • Now I can confirm, that ODBC is faster, and that OIC++ is built on the top of DMI, which is built on the top of ESQL/C (: – Kiril Kirov Apr 05 '11 at 10:00