Problems with (sort of) dynamic query
Posted in 1999
Hi, I am trying to select a large number of columns from a table (64 columns to be exact), and I was truing to write a program that would have the columns-to-be-selected in an array, using another char array to hold the selected results. Thus, the following partial code: ---Heres the list of columns #define COLUMNS 6 static char *query[]= {"cred_check_id","cred_check_date","cust_id","account_no","acquisition_type" ,"dealer_ranking"}; char buf[80][COLUMNS]; char slstmnt2[4096]; /*Build up string of column names*/ for(i = 0; i < COLUMNS;i++) { strcat(slstmnt2,query[i]); if(i != (COLUMNS-1)) { strcat(slstmnt2,","); } } sprintf(slstmnt,"select %s from cred_query where cred_check_id = ?", slstmnt2); EXEC SQL prepare slquery from :slstmnt; EXEC SQL execute slquery into :buf using :cred_id ; The problem here is using an array variable as the host variable, it doesn't seem to work. I have also tried using an "into :buf[1] ..." clause in the select, which seemed possible from the ESQL/C manual. I really don't want to get into using SQLDA structures here, as the statement is quite simple......, and it is of course possible by writing out the whole query in full in the source, but for maintenance reasons I dont want to do this. Is this possible using ESQL/C or am I just missing something simple? Cheers for any input! James Richardson