Home » Developer & Programmer » Precompilers, OCI & OCCI » pro*c query : getting multiple string records from db
pro*c query : getting multiple string records from db [message #94021] Thu, 18 September 2003 01:52
Messages: 3
Registered: June 2001
Junior Member

I am writting a program to access oracle database through pro*c things are ok except unable to handle one situation.

I need to get record(of string type) from database matching some criteria, do not know how many will be return, obviously need to have dynamic allocation for host variable.

So what I am doing is first throw a query and get count of matching records. (the max length of record is known.)

allocate the memory for that much of count and then pass pointer in second query for featching records. it does not return proper values.

If suppose I pass statically allocate array of same size it works.

Proc accepts only one dimensional array(for char[[]][[]] it considers it as 1d array of strings)

following is sample code.
Supposing that I am to receive 46 string in return from query with each of max length 16
static allocation
char mem[[46]][[17]];
exec sql select name into :mem from table where address='INDIA';
////// This works fine and gives me 46 names //////

Now since I do not know count of record in return
char **mem;
int _count;
exec sql select count(*) into :_count form table where add='MUMBAI';
mem = (char**) malloc(_count*sizeof(char*));
for(i=; i<_count; i++)
mem[[i]] = (char*) malloc(17*sizeof(char));
exec sql select name into :mem from table where add='MUMBAI';
////// return null in all string /////////

memory allocation is proper its tested in other manner.

If it can be done in other way of what is problem in current code.

I would grateful if anyone would just help out.

thanks & regards,
Previous Topic: how to learn pro c give me links
Next Topic: query
Goto Forum:

Current Time: Fri Jul 01 03:14:10 CDT 2022