Hi Support,

Need your help for one issue i am facing using c API in my C++ program.

Environment:
windows XP
fbclient.dll v2.5.0.26074

I have written two application one is win32 application and other one is MFC applicationWizard.

the application works fine win32 application.
when the same application i integrate in VC++ 6.0 i am getting an error message
SQLCODE:-104 Dynamic SQL Error.

code:
Query trying to execute:
Select * from tablName

isc_dsql_prepare(status, &trans, &stmt, 1, sel_str, 1, sqlda);

sqlda - structure is not getting populated in MFC Appwizard
but in win 32 application it's working fine.

only difference in project setting->C/C++ tab
under code generation category

In MFC appWizard
use run-time library- Debug MultiThreaded DLL
Structure Member alignment- 1 Byte

sqlda-ld is having value 0

in win32 console application
use run-time library- Debug MultiThreaded DLL
Structure Member alignment- 8 Byte*

sqlda-ld is having number of columns i-e 5 in my case

when i select the Structure Member alignment to 1 byte in win32 console application
i am getting the same error.


Code:
/////////////////////////////////////////////////////////////////////////////
//METHOD:
// PrepareQueryClass::GetColumnName
//DESCRIPTION:
// Use to retrieve the Database column name
//PARAMETERS:
// char *tblName -> Table name of database to retrieve column name
// isc_db_handle dbhandle -> using this handler Database is accessed
//RETURN:
// GetColumnName: False if failed
// TRUE if success
/////////////////////////////////////////////////////////////////////////////
bool PrepareQueryClass::GetColumnName(char *tblName,isc_db_handle dbhandle )
{
ISC_STATUS_ARRAY status;
isc_tr_handle trans = NULL; /* transaction handle */
int i;
isc_stmt_handle stmt = NULL;
XSQLDA *sqlda;

sqlda = (XSQLDA *) Heap.malloc(XSQLDA_LENGTH(3));
sqlda->sqln = 3;
sqlda->version = 1;

char *sel_str;

sel_str = (char *)malloc(MAXLEN);

sprintf(sel_str,"Select * from %s",tblName);
/* Allocate SQLDA of an arbitrary size. */

isc_start_transaction(status, &trans, 1, &dbhandle, 0, NULL);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

/* Allocate a statement. */
isc_dsql_allocate_statement(status, &dbhandle, &stmt);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

/* Prepare the statement. */
isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, SQL_DIALECT_V6, sqlda);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

/* Describe the statement. */
isc_dsql_describe(status, &stmt, 1, sqlda);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

/* This is a select statement, print more information about it. */

//printf("Query Type: SELECT\n\n");

numcols = sqlda->sqld;

//printf("Number of columns selected: %d\n", numcols);
/* Reallocate SQLDA if necessary. */
if (sqlda->sqln < sqlda->sqld)
{
if(sqlda)
free(sqlda);
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(numcols));
sqlda->sqln = numcols;
sqlda->version = 1;

/* Re-describe the statement. */
isc_dsql_describe(status, &stmt, 1, sqlda);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

numcols = sqlda->sqld;
}

/* List column names, types, and lengths. */
for (i = 0; i < numcols && i != MAX_DATA_COL; i++)
{
fieldname[i] = (char *)Heap.malloc(MAX_ITEM_COUNT);
strcpy(fieldname[i],sqlda->sqlvar[i].sqlname);
}

isc_dsql_free_statement(status, &stmt, DSQL_drop);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}

isc_commit_transaction(status, &trans);
if (status[0] == 1 && status[1])
{
printf("SQLCODE:%d\n", isc_sqlcode((ISC_STATUS *)status));
}
free(sel_str);
free(sqlda);
return true;
}