Here is my problem with Blobs. I'm trying to read a blob field frm the DB in a cursor, using descriptors. Does'nt seem to work... FAisl with SQLCODE -450 , meaning locator is invalid..... It fails at the "FETCH".
Any help on this wud be really helpful.
Here is my code snippet:
-------------------------------
EXEC SQL BEGIN DECLARE SECTION;
int i;
int desc_count;
char demoquery[800];
char colname[19];
char result[ NAME_LEN + 1 ];
char queryvalue[4];
int ind;
loc_t blob_descr;
int fieldType;
EXEC SQL END DECLARE SECTION;
blob_descr.loc_loctype = LOCMEMORY;
blob_descr.loc_bufsize = -1;
blob_descr.loc_oflags = 0;
blob_descr.loc_mflags = 0;
sprintf(demoquery, "%s %s",
"select blobtestfield from test_table",
"where index = ? ");
EXEC SQL prepare demoid from :demoquery;
EXEC SQL declare democursor cursor for demoid;
EXEC SQL allocate descriptor 'demodesc';
strcpy( queryvalue, "tst7");
desc_count = 1;
if(desc_count > MAX_IDESC)
{
EXEC SQL deallocate descriptor 'demodesc';
EXEC SQL allocate descriptor 'demodesc' with max :desc_count;
}
printf("SQLSTATE after reallocate is %s\n", SQLSTATE);
/* number of parameters to be held in descriptor is 1 */
EXEC SQL set descriptor 'demodesc' COUNT = :desc_count;
/* Put the value of the parameter into the descriptor */
i = SQLCHAR;
EXEC SQL set descriptor 'demodesc' VALUE 1
TYPE = :i, LENGTH = 16, DATA = :queryvalue;
/* Associate the cursor with the parameter value */
EXEC SQL open democursor using sql descriptor 'demodesc';
/*Reuse the descriptor to determine the contents of the Select-list*/
EXEC SQL describe demoid using sql descriptor 'demodesc' ;
printf("SQLCODE:: DESCRIBE [%d] \n", SQLCODE);
EXEC SQL get descriptor 'demodesc' :desc_count = COUNT;
printf("There are %d returned columns:\n", desc_count);
/* Print out what DESCRIBE returns */
for (i = 1; i <= desc_count; i++)
prsysdesc(i);
printf("\n\n");
/*
EXEC SQL select blobtestfield
into :blob_descr from test_frame
where frame_index = 'tst7';
printf("From SELECT: %d %s==\n", blob_descr.loc_size, blob_descr.loc_buffer);
*/
for (;

{
EXEC SQL fetch democursor using sql descriptor 'demodesc' ;
[ HERE IS WHERE IT FAILS WITH SQLDODE -450 !!! ]
printf("SQLCODE:: FETCH [%d] \n", SQLCODE);
printf("Fetch done \n");
if (strncmp(SQLSTATE, "00", 2) != 0)
break;
/* Print out the returned values */
for (i = 1; i <= desc_count; i++)
{
EXEC SQL get descriptor 'demodesc' VALUE :i
:fieldType = TYPE;
printf("TYPE of the field is [%d] ...", fieldType );
if(fieldType == SQLTEXT)
{
printf("B4 proc the SQL \n");
EXEC SQL get descriptor 'demodesc' VALUE :i
:blob_descr = DATA;
printf("Column: %s\tValue: %s\n", colname, blob_descr.loc_buffer);
}
else
{
EXEC SQL get descriptor 'demodesc' VALUE :i
:colname = NAME, :ind = INDICATOR, :result = DATA;
printf("Column: %s\tValue: %s\n", colname, result);
}
}
printf("\n");
} /* End of outer for loop */
if (strncmp(SQLSTATE, "02", 2) != 0)
printf("SQLSTATE after fetch is %s\n", SQLSTATE);
EXEC SQL close democursor;
/* free resources for prepared statement and cursor */
EXEC SQL free demoid;
EXEC SQL free democursor;
/* free system-descriptor area */
EXEC SQL deallocate descriptor 'demodesc';