Data Types in Embedded C queries - problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • edwald
    New Member
    • Sep 2007
    • 2

    Data Types in Embedded C queries - problems

    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.
  • edwald
    New Member
    • Sep 2007
    • 2

    #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

    Comment

    Working...