Help On Dynamic SQL Using ESQL/C
Posted in 1994
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Platform-Specific Issues
We are running Informix SE on a HP 9000/715 with HP-UX A.09.01 and are
using dynamic SQL descriptor capability. We are getting a -410 error on
'DESCRIBE...USING SQL DESCRIPTOR...' statement. The same code works
fine using the SUN version of Informix.
Has anyone encountered a similar situation? If so, what's the solution?
I have included a small test program with the schema information at the
end of this message.
Hwa Shen
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Table schema & Data:
====================
create table SS_Object (identifier integer);
insert into SS_Object values (7101001);
insert into SS_Object values (7102000);
ESQL/C code:
============
#define MAX_CHAR 18
$char stmt7_buffer[512], err_condition[60], db_name[60];
$int ret_count, identifier;
int alloc7;
void err_processing();
main(argc, argv)
int argc;
char *argv[];
{
int db_name_length;
$WHENEVER SQLERROR CALL err_processing;
alloc7 = 0;
identifier = 7101001;
strcpy(db_name, "nanticoke");
while (--argc > 0)
{
if (argv[argc][0] == '-')
{
switch (argv[argc][1])
{
case 'd':
case 'D':
db_name_length = strlen(argv[argc+1]);
db_name_length = (db_name_length > (MAX_CHAR - 1)) ?
(MAX_CHAR - 1) : db_name_length;
strncpy(db_name, argv[argc+1], db_name_length);
db_name[db_name_length] = '\\0';
break;
default:
printf("\\nUnknown command argument: %s\\n", argv[argc]);
exit(0);
}
}
}
strcpy(err_condition, "main - Open Database");
$DATABASE :db_name;
strcpy(stmt7_buffer, "select distinct identifier FROM SS_Object WHERE ");
strcat(stmt7_buffer, "identifier = ?");
strcpy(err_condition, "class_proc - Prepare s7");
$PREPARE s7 FROM :stmt7_buffer;
strcpy(err_condition, "class_proc - Declare c7");
$DECLARE c7 CURSOR FOR s7;
if (!alloc7)
{
strcpy(err_condition, "class_proc - Allocate 'c7desc'");
$ALLOCATE DESCRIPTOR 'c7desc' WITH MAX 30;
alloc7++;
}
strcpy(err_condition, "class_proc - Open c7");
$OPEN c7 USING :identifier;
strcpy(err_condition, "class_proc - Describe 'c7desc'");
$DESCRIBE c7 USING SQL DESCRIPTOR 'c7desc';
strcpy(err_condition, "class_proc - Get Descriptor 'c7desc'");
$GET DESCRIPTOR 'c7desc' $ret_count = count;
}
void err_processing()
{
char errmsg[400], errmsg_out[512];
printf("\\nSQL ERROR <%d> in %s\\n", SQLCODE, err_condition);
rgetmsg(SQLCODE, errmsg, sizeof(errmsg));
if (sqlca.sqlerrm)
{
sprintf(errmsg_out, errmsg, sqlca.sqlerrm);
}
else
{
strcpy(errmsg_out, errmsg);
}
printf(" %s\\n", errmsg_out);
exit(0);
}