1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
exec sql begin declare section;
char indesc[]="input_descriptor";
char outdesc[]="output_descriptor";
int output_count;
int occurs, type, len, olen, slen;
char data[100][2100], name[100];
unsigned char data2[2100];
char oname[100], otype[100];
char stype[100];
char otype2[] = "child_s";
struct child_s { char cnmae[3]; };
typedef struct child_s child_s;
child_s sdata;
exec sql end declare section;
/* connection has been established */
exec sql prepare s from :sql_statement;
exec sql declare c cursor for s;
exec sql describe output s using descriptor global :outdesc;
exec sql get descriptor global :outdesc :output_count = count;
for (i = 0; i < output_count; i++)
{
occurs = i + 1;
exec sql get descriptor global :outdesc value :occurs :type = type, :name = name, :len = length,
:otype = user_defined_type_name, :olen = user_defined_type_name_length,
:stype = user_defined_type_schema, :slen = user_defined_type_schema_length;
if (type == 108) { /* handle object type oracle type code = 108 */
/* set the struct variable and error encountered */
exec sql set descriptor global :outdesc value :occurs user_defined_type_name = :otype2,
user_defined_type_name_length = :olen, data = :sdata;
}
else { /* handle non-object type and convert to char type - it works */
type = 5;
exec sql set descriptor global :outdesc value :occurs type = :type, ref data = :data[i];
}
}
exec sql whenever not found goto end_select_loop;
for (;;)
{
exec sql fetch c into descriptor global :outdesc;
printf("\nready to print data - ");
for (i = 0; i < output_count; i++)
{
occurs = i + 1;
if (type == 108)
{
printf("Object encountered");
}
else
{
printf("%d ", len);
printf("%-*.*s ", 9, 9, data[i]);
printf("%-*.*s ", 9, 9, sdata);
}
}
} |
Partager