Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 23rd, 2011, 05:40 PM
vikas.sh1 vikas.sh1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 10 vikas.sh1 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 h 29 m 13 sec
Reputation Power: 0
SQLCODE:-104 Dynamic SQL Error.

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;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > SQLCODE:-104 Dynamic SQL Error.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap