Subject Re: [ib-support] isc_dsql_exec_immed2()
Author C R Zamana
Paul Reeves wrote:
> C R Zamana wrote:
>
>> In the /opt/interbase/examples directory there
>>is only one example using the function stated in the
>>subject, but this example show the function been used
>>to pass arguments, not to retrieve them.
>>
>> So, please, anybody has any example using
>>isc_dsql_exec_immed2() to get results of a query like
>>"select count(*) from ..." for example?
>>
>>
>
> Can you show us a code snippet that reproduces what you
> are trying to do?

Of course.

This is a simplified one where I try to extract
the number of columns of table. The functions "api_"
are mine and calls those correspondent in the firebird api.
I know that they are working because they are being used
in other functions.

Thank you.
Best regards.



long sql_numcols( isc_db_handle *dbhandle, char *tablename ) {

int rc;
long cols;
char query[100];
isc_tr_handle trhandle;
XSQLDA *osqlda;
ISC_STATUS status_vectore[20];

/* building the query */
strcpy( query, "select count(*) from rdb$relation_fields ");
strcat( query, "where rdb$relation_name = '" );
/* uppercase assumed here */
strcat( query, tablename );
strcat( query, "'\0" );

/* allocating an osqlda */
osqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(1));
if ( osqlda == NULL ) {
return(0);
}
osqlda->version = SQLDA_VERSION1;
osqlda->sqln = 1;

/* allocating a transaction handle */
trhandle = NULL;
rc = api_start_tr( dbhandle, &trhandle );
if ( rc != 0 ) {
return(0);
}

/* executing */
isc_dsql_exec_immed2( status_vector, dbhandle, &trhandle, 0, query, 1,
NULL, osqlda );

printf("sqld: %d\n", osqlda->sqld); // -> 0
printf("sqllen: %d\n", osqlda->sqlvar[0].sqllen); // -> 0
printf("sqltype: %d\n", osqlda->sqlvar[0].sqltype); // -> 0
printf("numcols: %ld\n", *(long *)osqlda->sqlvar[0].sqldata); // -> 0

cols = *(long *)osqlda->sqlvar[0].sqldata;

api_commit( &trhandle );

return(cols);

}

--
------------------------------------------------------------------------
zamana@... | "Emacs is a nice OS - but it lacks a good text
zamana@... | editor. That's why I'm using Vim. Anonymous
http://www.inso.com.br | http://www.vim.org/quotes.html
------------------------------------------------------------------------