summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/execute.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2010-02-02 16:09:12 +0000
committerMichael Meskes <meskes@postgresql.org>2010-02-02 16:09:12 +0000
commitcedae130173c8a023cbc2bad39e2301b24aeb027 (patch)
treed116d1d0282cb041f5293ae836313221e8be1bc4 /src/interfaces/ecpg/ecpglib/execute.c
parent63f9282f6e7a4afed8826437cea6e92d9e4b0869 (diff)
Fixed NaN/Infinity problems in ECPG for float/double/numeric/decimal by making it OS independant.
Patch done by Zoltán Böszörményi.
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/execute.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 71b32a8128c..48b38dab1e4 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.90 2010/01/29 15:57:01 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.91 2010/02/02 16:09:11 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -17,6 +17,7 @@
#include "postgres_fe.h"
#include <locale.h>
+#include <math.h>
#include "pg_type.h"
@@ -463,6 +464,38 @@ ecpg_store_result(const PGresult *results, int act_field,
return status;
}
+static void
+sprintf_double_value(char *ptr, double value, const char *delim)
+{
+ if (isinf(value))
+ {
+ if (value < 0)
+ sprintf(ptr, "%s%s", "-Infinity", delim);
+ else
+ sprintf(ptr, "%s%s", "Infinity", delim);
+ }
+ else if (isnan(value))
+ sprintf(ptr, "%s%s", "NaN", delim);
+ else
+ sprintf(ptr, "%.14g%s", value, delim);
+}
+
+static void
+sprintf_float_value(char *ptr, float value, const char *delim)
+{
+ if (isinf(value))
+ {
+ if (value < 0)
+ sprintf(ptr, "%s%s", "-Infinity", delim);
+ else
+ sprintf(ptr, "%s%s", "Infinity", delim);
+ }
+ else if (isnan(value))
+ sprintf(ptr, "%s%s", "NaN", delim);
+ else
+ sprintf(ptr, "%.14g%s", value, delim);
+}
+
bool
ecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var,
char **tobeinserted_p, bool quote)
@@ -693,12 +726,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
strcpy(mallocedval, "array [");
for (element = 0; element < asize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
+ sprintf_float_value(mallocedval + strlen(mallocedval), ((float *) var->value)[element], ",");
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
- sprintf(mallocedval, "%.14g", *((float *) var->value));
+ sprintf_float_value(mallocedval, *((float *) var->value), "");
*tobeinserted_p = mallocedval;
break;
@@ -712,12 +745,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
strcpy(mallocedval, "array [");
for (element = 0; element < asize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
+ sprintf_double_value(mallocedval + strlen(mallocedval), ((double *) var->value)[element], ",");
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
- sprintf(mallocedval, "%.14g", *((double *) var->value));
+ sprintf_double_value(mallocedval, *((double *) var->value), "");
*tobeinserted_p = mallocedval;
break;