By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

Data Types in Embedded C queries - problems

P: 2
I have very little experience with DB2, but am writing a simple C program, with
embedded SQL, that has among other things
[The original code compiles fine, any typing errors below are my fault in posting]

EXEC SQL BEGIN DECLARE SECTION;
double F;
/*...*/
EXEC SQL END DECLARE SECTION;
...

Then do a DECLARE a cursor, OPEN it and FETCH a "REAL" column
into this host variable F.

Printing it out (printf( ".. %7.2f .. "); does not yield the expected values (2.5, or such, which is returned by a straight DB2 query from the commandline)
but either 0.00, -0.00 or some some massive string of digits (100 or so).

It looks like I am reading the data types wrong, but can't see where.
The DB2 server instance is running on the same machine where the client
program is compiled and run. I have tested this on two separate machines,
with similar results.

I've written a similar program, that looks the same to me, for all intents and
puroses, but that one works. I would appreciate any pointers to the solution
from more experienced DB2 users.
Sep 27 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
Turns out this was my own clumsiness.

I had *two* variables with the same name, one EXEC SQL-declared as
an SQL short, in the embedded-SQL section, the other a normal C
array of type float**. Printing out the contents of this variable didn't
produce the expected results, reasonably so.
I didn't notice, because my program has a large number of variables,
and the compiler didn't complain either, I guess the compiler doesn't
'see' the variables declared inside the EXEC SQL section, and hence
couldn't complain. This was a useful thing to find out, if a little expensive.

So, my faith in the DB2 server is restored,
regards
Sep 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.