2010-02-02 17:09:12 +01:00
|
|
|
/* Processed by ecpg (regression mode) */
|
|
|
|
/* These include files are added by the preprocessor */
|
|
|
|
#include <ecpglib.h>
|
|
|
|
#include <ecpgerrno.h>
|
|
|
|
#include <sqlca.h>
|
|
|
|
/* End of automatic include section */
|
|
|
|
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
|
|
|
|
|
|
|
|
#line 1 "nan_test.pgc"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2010-02-04 12:23:29 +01:00
|
|
|
#include <float.h>
|
2010-02-27 22:56:16 +01:00
|
|
|
#include <math.h>
|
2010-02-02 17:09:12 +01:00
|
|
|
#include <pgtypes_numeric.h>
|
|
|
|
#include <decimal.h>
|
|
|
|
|
|
|
|
|
|
|
|
#line 1 "regression.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-04 12:23:29 +01:00
|
|
|
#line 8 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
/* exec sql begin declare section */
|
2019-01-24 22:46:55 +01:00
|
|
|
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 14 "nan_test.pgc"
|
2019-01-24 22:46:55 +01:00
|
|
|
int id , loopcount ;
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 15 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
double d ;
|
|
|
|
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 16 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
numeric * num ;
|
|
|
|
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 17 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
char val [ 16 ] ;
|
|
|
|
/* exec sql end declare section */
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 18 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
ECPGdebug(1, stderr);
|
|
|
|
/* exec sql whenever sqlerror do sqlprint ( ) ; */
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 21 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
2016-07-18 00:42:31 +02:00
|
|
|
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 23 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 23 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest1 ( id int4 , d float8 )", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 25 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 25 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2010-02-03 14:56:27 +01:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( 1 , 'nan' :: float8 ) , ( 2 , 'infinity' :: float8 ) , ( 3 , '-infinity' :: float8 )", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 26 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 26 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* declare cur cursor for select id , d , d from nantest1 */
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 28 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 29 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 29 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-01-24 22:46:55 +01:00
|
|
|
for (loopcount = 0; loopcount < 100; loopcount++)
|
2010-02-02 17:09:12 +01:00
|
|
|
{
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
|
2010-02-02 17:09:12 +01:00
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 32 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 32 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode)
|
|
|
|
break;
|
|
|
|
if (isnan(d))
|
|
|
|
printf("%d NaN '%s'\n", id, val);
|
2010-02-16 19:41:23 +01:00
|
|
|
else if (isinf(d))
|
|
|
|
printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 3 , $2 )",
|
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 40 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 40 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( $1 + 6 , $2 )",
|
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 41 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 41 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
}
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 43 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 43 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 45 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 45 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-01-24 22:46:55 +01:00
|
|
|
for (loopcount = 0; loopcount < 100; loopcount++)
|
2010-02-02 17:09:12 +01:00
|
|
|
{
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
|
2010-02-02 17:09:12 +01:00
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_double,&(d),(long)1,(long)1,sizeof(double),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 48 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 48 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode)
|
|
|
|
break;
|
|
|
|
if (isinf(d))
|
|
|
|
printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
|
|
|
|
if (isnan(d))
|
|
|
|
printf("%d NaN '%s'\n", id, val);
|
|
|
|
}
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 56 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 56 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
num = PGTYPESnumeric_new();
|
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest2 ( id int4 , d numeric )", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 60 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 60 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 4 , 'nan' :: numeric )", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 61 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 61 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select id , d , d from nantest2 where id = 4", ECPGt_EOIT,
|
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 63 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 63 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
|
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 5 , $1 )",
|
|
|
|
ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 67 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 67 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest2 ( id , d ) values ( 6 , $1 )",
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 68 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 68 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* declare cur1 cursor for select id , d , d from nantest2 */
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 70 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 71 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 71 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
2019-01-24 22:46:55 +01:00
|
|
|
for (loopcount = 0; loopcount < 100; loopcount++)
|
2010-02-02 17:09:12 +01:00
|
|
|
{
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
|
2010-02-02 17:09:12 +01:00
|
|
|
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
|
|
|
ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char),
|
|
|
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 74 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 74 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode)
|
|
|
|
break;
|
|
|
|
printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
|
|
|
|
}
|
2019-09-20 18:47:21 +02:00
|
|
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 79 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 79 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
2010-08-17 11:36:05 +02:00
|
|
|
PGTYPESnumeric_free(num);
|
|
|
|
|
2010-02-02 17:09:12 +01:00
|
|
|
{ ECPGtrans(__LINE__, NULL, "rollback");
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 83 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 83 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
{ ECPGdisconnect(__LINE__, "CURRENT");
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 84 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
if (sqlca.sqlcode < 0) sqlprint ( );}
|
2019-10-08 10:27:30 +02:00
|
|
|
#line 84 "nan_test.pgc"
|
2010-02-02 17:09:12 +01:00
|
|
|
|
|
|
|
|
2017-08-17 18:39:20 +02:00
|
|
|
return 0;
|
2010-02-02 17:09:12 +01:00
|
|
|
}
|