get descriptor problem
Posted in 1998
All, I'm probably being deeply unwise, but I'm trying to use SQL descriptors. The following code fails on the fetch with an SQL error of -402: BOOLEAN i_list_line_fetch(ARLIST *list,int i2_line,int i4_set) { exec sql begin declare section; char *cursor_name; char *sql_desc; char result[81]; int field_count=0; int i4_sql_set; exec sql end declare section; /* Get the cursor and descriptor names from the list */ cursor_name = list->cursor_name_c18; sql_desc = list->sql_descriptor_c18; /* Set a host variable with the set no. */ i4_sql_set = i4_set; printf("Descriptor: %s\\n",sql_desc); printf("Curs Name : %s\\n",cursor_name); printf("Set : %d\\n",i4_sql_set); exec sql fetch absolute :i4_sql_set :cursor_name using sql descriptor :sql_desc; printf("Fetch SQLCODE is %d\\n",SQLCODE); while (field_count++ < list->i2_fields) { exec sql get descriptor :sql_desc value :field_count :result = data; printf("Field count is %d\\n",field_count); printf("SQLCODE is %d\\n",SQLCODE); strcpy(list->line[field_count]->ac80_line,result); printf("result is %s\\n",result); } LOGOUT("i_list_line_fetch"); return(TRUE); } The output is: Into function i_list_line_fetch Descriptor: popdes1 Curs Name : popcur1 Set : 1 Fetch SQLCODE is -402 Field count is 1 SQLCODE is -486 result is Field count is 2 SQLCODE is -486 result is Out of function i_list_line_fetch If I get rid of the 'using sql descriptor' bit, it works in that the fetch returns 0 as the sqlca.sqlcode, however the get descriptor then fails with -486 (uninitialised descriptor) - which is fair enough! I'm not to worried that the get descriptor is not working, it obviosly depends on the fetch, also, this is rough code so no comments about lack of comments etc. please (-; Any ideas? Kevin