Re: Passing a descriptor to a function in ESQL/C?
Posted in 1994
}From: wd@infodn.rmi.de (Walter Doerr) }Subject: Passing a descriptor to a function in ESQL/C? }Date: 19 Apr 94 14:15:42 GMT }X-Informix-List-Id: <news.6398> } }Hello! } }I am trying to write a function in ESQL/C 5.00 that accepts/returns }a cursor and/or a descriptor, so that this function can be used to }work with several tables/databases within a program. }Unfortunately, I can't get it to work. } }Here is what I have tried: } }/* --- Example --- */ }main() }{ } struct sqlda *desc; } $char cursor[19]; } ... } sql_func(cursor, desc); } ... }} } }int }sql_func(cursor, desc) }$PARAMETER char *cursor; }struct sqlda *desc; }{ } ... } $SET DESCRIPTOR desc COUNT = 1; } ... }} }/* ---------------- */ } }esql complains with the message } Error -33040: Object 'desc' was not declared. } }When I use $PARAMETER struct *sqlda; in the above example I get: } Error -33200: Invalid statement on symbol 'sqlda'. } Error -33006: Type of 'desc' is not appropriate for this use. } }What am I doing wrong? It must be either something very stupid or what }I am trying to do is not possible in ESQL/C. (unlikely) } }Also, do I have to $ALLOCATE DESCRIPTOR before calling sql_func()? }(tried it, but also got an error message at compile time.) If you received a good answer to this question, then please ignore me. If not, and if you think this info is helpful enough, then please post it to comp.databases.informix for me. I'm working off the 6.00 ESQL/C Manual, but I don't think this has changed much... If you note the description in ALLOCATE DESCRIPTOR, then you'll see that the desc is either a string, a string variable, or a plain name. Therefore, you could write your code: main() { ... sql_func(cursor, "descname"); ... } int sql_func(cursor, desc) $PARAMETER char *cursor; $PARAMETER char *desc; { ... $SET DESCRIPTOR $desc COUNT = 1; ... } However, note that if you write the descriptor out as a fixed name not in quotes, then you are continually referring to the same descriptor. $ ALLOCATE DESCRIPTOR xyz ...; $ SET DESCRIPTOR xyz ...; $ GET DESCRIPTOR xyz ...; $ DEALLOCATE DESCRIPTOR xyz ...; It is necessary to do an ALLOCATE DESCRIPTOR before trying to use it with SET DESCRIPTOR. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>