Re: A little problem with sqlo_ocol_names and memory alloc size
My name is Ignacio Holgado. Apologies for my english ( I am spanish ).
I am developping an aplication server with oracle support in a multithreaded environment in a SuSe O.S.
I have developped a "cursor object" in order to allow the access to a generic database from the aplications dispatched by my aplication server.
The first implementation of this cursor object was implemented using the "easy interface" but now I need some functionalities from the advanced interface
and i have 2 litle problems:
1 - My first problem is that i can't obtain the column names from the advanced interface. It seams that it don't works with the "advanced interface". Maybe i am not using it propertly. I have made a bad solution and i would like to have a better solution.
I use it with the following code :
*cursor = sqlo_prepare ( *connection, sql_stmt ); // runs OK
status = SQLexecute(cursor,0); // runs OK ( this is a wrapper to sqlo_execute )
result->n_ocols = sqlo_ncols(*cursor, 0); // returns the number of columns OK !!
for (type = SQLgetColType(cursor,i+1); (type>=0) && (i<=result->n_ocols);type = SQLgetColType(cursor,(++i)+1))
if (SQLO_SUCCESS != (status = sqlo_define_by_pos(*cursor, i+1, type, result->data[2*i], size, result->data[2*i+1],&(result->length[i]),0)))
status = SQLexecute(cursor,0); // OK
status = SQLfetch(cursor,0); // OK
sqlo_loadNames(*cursor, result->n_ocols + 1); // This function is mine
result->ocol_names = sqlo_ocol_names(*cursor, &type); // returns an array of null pointers
The sqlo_loadNames function is a function that a have made to allow mi aplication to access the private function _define_ocol_by_pos
that is non available from my aplication.
In order to get the names I have put the following code inside the sqlora.c file.
// by ihm
// Ampliation to enable getNames from Advanced interface
int sqlo_loadNames(sqlo_stmt_handle_t sth, int num_cols)
register sqlo_stmt_ptr_t stp;
int status = SQLO_SUCCESS;
register unsigned int col_pos; /* The column position (1based) */
// ub4 num_cols; /* number of columns in the select list */
CHECK_STHANDLE(stp, sth, "sqlo_reopen", SQLO_INVALID_STMT_HANDLE);
/* define all columns */
for (col_pos = 1, colp = stp->ocolsv; col_pos <= (unsigned int) num_cols ;
_define_ocol_by_pos(stp, colp, col_pos);
I know that this is a bad solution but is the only one that i have.
2 - My second problem is that i don't know how much space allocate in a string when i call tho the sqlo_define_by_pos function.
Maybe a solution can be to implement a new sqlo_define_by_pos3 function with a double pointer to the data:
sqlo_define_by_pos3 ( stmt , pos, type, void **the_data, int *size, ...
And the sqlo_fetch, command allocates the memory and stores a pointer of the data inside the the_data double pointer when the true size of the data will be know:
*the_data = __malloc(...);
snprintf ( *the_data, the_size, ... ); // or some similar.
The followind problem is who frees the memory: the sqlora library or the user. But i thing this situation is the same that the situation of the
allocation of "alloc_lob" and "free_lob" with the lob's API.
Thanks in advance:
A little problem with sqlo_ocol_names... ( part II )
/* define all columns */
for (col_pos = 1, colp = stp->ocolsv; col_pos