Subject Unknown Table on isc_dsql_prepare()
Author edcurren
Hello all,
I am running into an error (below) in my code (also below) when it
attempts to execute the isc_dsql_prepare function. When I connect to
the database via ISQL I am able to run the query without a problem.
Thank you all for any help you may be able to provide.

*** Error ***
Dynamic SQL Error
SQL error code = -204
Table unknown
ADDRESSES
At line 1, column 15.

*** Code ***
ISC_STATUS status_vector[20];
isc_db_handle db;
isc_tr_handle trans;
isc_stmt_handle stmt; /* Declare a statement handle. */
ISC_STATUS *pStatus = status_vector;

db = 0L;
trans = 0L;
stmt = NULL; /* Set handle to NULL before allocation. */

const char *username = "SYSDBA";
const char *password = "masterkey";

char dpb_buffer[256], *dpb;
short dpb_length;

/* Construct the database parameter buffer. */
dpb = dpb_buffer;
*dpb++ = isc_dpb_version1;
*dpb++ = isc_dpb_num_buffers;
*dpb++ = 1;
*dpb++ = 90;

// Set the db user name
*dpb++ = isc_dpb_user_name;
*dpb++ = strlen(username);
strcpy(dpb, username);
dpb += strlen(username);

// set the db password
*dpb++ = isc_dpb_password;
*dpb++ = strlen(password);
strcpy(dpb, password);
dpb += strlen(password);

dpb_length = dpb - dpb_buffer;

isc_attach_database(status_vector, strlen("db.fdb"), "db.fdb", &db,
dpb_length, dpb_buffer);
if (status_vector[0] == 1 && status_vector[1] > 0)
{
char outmsg[1024];
char msg[512];
isc_sql_interprete(isc_sqlcode(status_vector), msg, 512);
strcpy(outmsg, msg);
while( isc_interprete(msg, &pStatus) )
{
strcat(outmsg, msg);
strcat(outmsg, "\n");
}
}

char str[1024];
sprintf(str, "SELECT * FROM ADDRESSES");
XSQLDA *out_sqlda;

out_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(2));
out_sqlda->version = SQLDA_VERSION1;
out_sqlda->sqln = 2;

isc_dsql_allocate_statement(status_vector, &db, &stmt);
if (status_vector[0] == 1 && status_vector[1] > 0)
{
char outmsg[1024];
char msg[512];
isc_sql_interprete(isc_sqlcode(status_vector), msg, 512);
strcpy(outmsg, msg);
while( isc_interprete(msg, &pStatus) )
{
strcat(outmsg, msg);
strcat(outmsg, "\n");
}
}

isc_dsql_prepare(status_vector, &trans, &stmt, 0, str, 3, NULL);
if (status_vector[0] == 1 && status_vector[1] > 0)
{
char outmsg[1024];
char msg[512];
isc_sql_interprete(isc_sqlcode(status_vector), msg, 512);
strcpy(outmsg, msg);
strcpy(outmsg, "\n");
while( isc_interprete(msg, &pStatus) )
{
strcat(outmsg, msg);
strcat(outmsg, "\n");
}

FILE *f = fopen("C:\\Temp\\Dump.sql.out", "w+r");
fwrite(outmsg, 1, strlen(outmsg), f);
fclose(f);
}

isc_dsql_execute(status_vector, &trans, &stmt, 1, NULL);
if (status_vector[0] == 1 && status_vector[1] > 0)
{
long SQLCODE;
char msg[512];
SQLCODE = isc_sqlcode(status_vector);
isc_sql_interprete(SQLCODE, msg, 512);
}

isc_dsql_describe(status_vector, &stmt, 1, out_sqlda);
if (status_vector[0] == 1 && status_vector[1] > 0)
{
char outmsg[1024];
char msg[512];
isc_sql_interprete(isc_sqlcode(status_vector), msg, 512);
strcpy(outmsg, msg);
while( isc_interprete(msg, &pStatus) )
{
strcat(outmsg, msg);
strcat(outmsg, "\n");
}
}