double conversion with ESQL/C on Linux

double conversion with ESQL/C on Linux

Post by roman.mau.. » Sun, 31 Dec 1899 09:00:00



Hello!

We have experienced strange casting problem when storing doubles to
smallint on Informix/Linux.  Here is the ESQL/C program that
demonstrates the error.  It works OK on Sinix, but stores wrong
data on Linux.

Does anyone know where to obtain the patch for this bug?

       Pozdrav,
         Roman

- - -

/***********************************************************************
****
 * $Id: testdb.ec,v 1.2 1999/08/18 11:57:14 romanm Exp $
 *
 * DESCRIPTION: Test file for strange Informix behavior regarding
conversion
 *   of C types to database types.
 *   We expect no change of value when inserting an integer value stored
 *   in a double variable to smallint DB-type.
 *
 * OUR ENVIRONMENT:
 * - Linux guinness 2.2.5 #4 Tue Apr 13 16:51:36 MEST 1999 i686 unknown
 *    (SuSE 6.1),
 * - Informix DS v7_30_uc7_2, ESQL 9.14 (11/11/93, 07:43:13)
 * - GCC VERSION 2.7.2.3
 * - compile and execute commands: esql testdb.ec; ./a.out
 *
 * OUR OUTPUT:
 * ---->8----
 * Testing SELECT type casting for prog01
 * Expected value: 23, b_double=22.000000, b_int=23, delta:-1.000000
 * Expected value: 24, b_double=23.000000, b_int=24, delta:-1.000000
 * Expected value: 27, b_double=26.000000, b_int=27, delta:-1.000000
 * Expected value: 28, b_double=27.000000, b_int=28, delta:-1.000000
 * Expected value: 29, b_double=28.000000, b_int=29, delta:-1.000000
 *
 * Test is over.
 * ---->8----
************************************************************************
**/

#include <stdio.h>

EXEC SQL BEGIN DECLARE SECTION;
    int    a_int,    b_int;
    double a_double, b_double;
EXEC SQL END DECLARE SECTION;

#define MAXVALUE 30

void prinerror(char *);

void printerror(char *action)
{
  if (strncmp(SQLSTATE, "00", 2) != 0)
    {
      /* if (strncmp(SQLSTATE, "02", 2) != 0) */
      printf("SQLSTATE after %s is %s\n", action, SQLSTATE);
      printf("SQLCODE is %d\n", SQLCODE);
    }

Quote:}

int main(void)
{
    int value;

    printf( "Testing SELECT type casting for prog01\n");

    EXEC SQL CONNECT TO 'prog01';

    /* in case we have the table, we'll drop it */
    EXEC SQL DROP TABLE tmp_foo_table;

    EXEC SQL CREATE TABLE tmp_foo_table
      (
       x_int    SMALLINT NOT NULL,
       x_double SMALLINT NOT NULL
      );

   /* fill the table with values */
   for (value=1; value<MAXVALUE; value++)
     {
       a_int = a_double = value;
       EXEC SQL
         INSERT INTO tmp_foo_table VALUES(:a_int, :a_double);

       printerror("INSERT");
     }
   /* ERROR!! If we use dbaccess to view the contents of the
tmp_foo_table,
    * there are already wrong values of x_double in it. */

   /* read from table */
   for (value=1; value<MAXVALUE; value++)
     {
       a_int = a_double = value;

       EXEC SQL SELECT x_int, x_double
         INTO :b_int, :b_double
         FROM tmp_foo_table
         WHERE x_int=:a_int;

       if (b_double != b_int)
       /* ERROR!! Sometimes this actually happens! */
         printf("Expected value: %d, b_double=%f, b_int=%d, delta:%f\n",
              value, b_double, b_int, b_double-b_int);

       printerror("SELECT");
     }

   /* EXEC SQL DROP TABLE tmp_foo_table; */

   EXEC SQL DISCONNECT CURRENT;
   printf("\nTest is over.\n");

   return 0;

Quote:}

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.