mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
- Added Dave patch for Informix handling of numeric/int conversion.
- Changed all new datatypes to lowercase. - Fixed rounding bug in numerical types.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.16 2003/08/04 00:43:32 momjian Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.17 2003/09/09 10:46:37 meskes Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -115,10 +115,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
unsigned long ures;
|
||||
double dres;
|
||||
char *scan_length;
|
||||
Numeric *nres;
|
||||
Date ddres;
|
||||
Timestamp tres;
|
||||
Interval *ires;
|
||||
numeric *nres;
|
||||
date ddres;
|
||||
timestamp tres;
|
||||
interval *ires;
|
||||
|
||||
case ECPGt_short:
|
||||
case ECPGt_int:
|
||||
@@ -126,8 +126,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (pval)
|
||||
{
|
||||
res = strtol(pval, &scan_length, 10);
|
||||
/* INFORMIX allows for selecting a numeric into an int, the result is truncated */
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
@@ -160,7 +161,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
{
|
||||
ures = strtoul(pval, &scan_length, 10);
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
@@ -193,7 +194,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
{
|
||||
*((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
@@ -210,7 +211,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
{
|
||||
*((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!isarray && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
|| (!isarray && !(INFORMIX_MODE(compat) && *scan_length == '.') && *scan_length != '\0' && *scan_length != ' ')) /* Garbage left */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
@@ -403,9 +404,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
|
||||
|
||||
if (type == ECPGt_numeric)
|
||||
PGTYPESnumeric_copy(nres, (Numeric *) (var + offset * act_tuple));
|
||||
PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
|
||||
else
|
||||
PGTYPESnumeric_to_decimal(nres, (Decimal *) (var + offset * act_tuple));
|
||||
PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
|
||||
break;
|
||||
|
||||
case ECPGt_interval:
|
||||
@@ -429,7 +430,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
else
|
||||
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
|
||||
|
||||
PGTYPESinterval_copy(ires, (Interval *) (var + offset * act_tuple));
|
||||
PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
|
||||
break;
|
||||
case ECPGt_date:
|
||||
if (pval)
|
||||
@@ -449,7 +450,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
return (false);
|
||||
}
|
||||
|
||||
*((Date *) (var + offset * act_tuple)) = ddres;
|
||||
*((date *) (var + offset * act_tuple)) = ddres;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -471,7 +472,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
return (false);
|
||||
}
|
||||
|
||||
*((Timestamp *) (var + offset * act_tuple)) = tres;
|
||||
*((timestamp *) (var + offset * act_tuple)) = tres;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.23 2003/08/04 00:43:32 momjian Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.24 2003/09/09 10:46:37 meskes Exp $ */
|
||||
|
||||
/*
|
||||
* The aim is to get a simpler inteface to the database routines.
|
||||
@@ -846,16 +846,16 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
{
|
||||
char *str = NULL;
|
||||
int slen;
|
||||
Numeric *nval = PGTYPESnumeric_new();
|
||||
numeric *nval = PGTYPESnumeric_new();
|
||||
|
||||
if (var->arrsize > 1)
|
||||
{
|
||||
for (element = 0; element < var->arrsize; element++)
|
||||
{
|
||||
if (var->type == ECPGt_numeric)
|
||||
PGTYPESnumeric_copy((Numeric *) ((var + var->offset * element)->value), nval);
|
||||
PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
|
||||
else
|
||||
PGTYPESnumeric_from_decimal((Decimal *) ((var + var->offset * element)->value), nval);
|
||||
PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);
|
||||
|
||||
str = PGTYPESnumeric_to_asc(nval, 0);
|
||||
PGTYPESnumeric_free(nval);
|
||||
@@ -875,9 +875,9 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
else
|
||||
{
|
||||
if (var->type == ECPGt_numeric)
|
||||
PGTYPESnumeric_copy((Numeric *) (var->value), nval);
|
||||
PGTYPESnumeric_copy((numeric *) (var->value), nval);
|
||||
else
|
||||
PGTYPESnumeric_from_decimal((Decimal *) (var->value), nval);
|
||||
PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);
|
||||
|
||||
str = PGTYPESnumeric_to_asc(nval, 0);
|
||||
|
||||
@@ -906,7 +906,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
{
|
||||
for (element = 0; element < var->arrsize; element++)
|
||||
{
|
||||
str = quote_postgres(PGTYPESinterval_to_asc((Interval *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), stmt->lineno)))
|
||||
@@ -923,7 +923,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
}
|
||||
else
|
||||
{
|
||||
str = quote_postgres(PGTYPESinterval_to_asc((Interval *) (var->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, stmt->lineno)))
|
||||
@@ -949,7 +949,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
{
|
||||
for (element = 0; element < var->arrsize; element++)
|
||||
{
|
||||
str = quote_postgres(PGTYPESdate_to_asc(*(Date *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), stmt->lineno)))
|
||||
@@ -966,7 +966,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
}
|
||||
else
|
||||
{
|
||||
str = quote_postgres(PGTYPESdate_to_asc(*(Date *) (var->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, stmt->lineno)))
|
||||
@@ -992,7 +992,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
{
|
||||
for (element = 0; element < var->arrsize; element++)
|
||||
{
|
||||
str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), stmt->lineno)))
|
||||
@@ -1009,7 +1009,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
}
|
||||
else
|
||||
{
|
||||
str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) (var->value)), stmt->lineno);
|
||||
str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), stmt->lineno);
|
||||
slen = strlen(str);
|
||||
|
||||
if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, stmt->lineno)))
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.14 2003/08/08 13:17:58 petere Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.15 2003/09/09 10:46:37 meskes Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -294,18 +294,18 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr)
|
||||
*(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
|
||||
break;
|
||||
case ECPGt_decimal:
|
||||
memset((char *) ptr, 0, sizeof(Decimal));
|
||||
((Decimal *) ptr)->sign = NUMERIC_NAN;
|
||||
memset((char *) ptr, 0, sizeof(decimal));
|
||||
((decimal *) ptr)->sign = NUMERIC_NAN;
|
||||
break;
|
||||
case ECPGt_numeric:
|
||||
memset((char *) ptr, 0, sizeof(Numeric));
|
||||
((Numeric *) ptr)->sign = NUMERIC_NAN;
|
||||
memset((char *) ptr, 0, sizeof(numeric));
|
||||
((numeric *) ptr)->sign = NUMERIC_NAN;
|
||||
break;
|
||||
case ECPGt_interval:
|
||||
memset((char *) ptr, 0xff, sizeof(Interval));
|
||||
memset((char *) ptr, 0xff, sizeof(interval));
|
||||
break;
|
||||
case ECPGt_timestamp:
|
||||
memset((char *) ptr, 0xff, sizeof(Timestamp));
|
||||
memset((char *) ptr, 0xff, sizeof(timestamp));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -365,18 +365,18 @@ ECPGis_informix_null(enum ECPGttype type, void *ptr)
|
||||
return true;
|
||||
break;
|
||||
case ECPGt_decimal:
|
||||
if (((Decimal *) ptr)->sign == NUMERIC_NAN)
|
||||
if (((decimal *) ptr)->sign == NUMERIC_NAN)
|
||||
return true;
|
||||
break;
|
||||
case ECPGt_numeric:
|
||||
if (((Numeric *) ptr)->sign == NUMERIC_NAN)
|
||||
if (((numeric *) ptr)->sign == NUMERIC_NAN)
|
||||
return true;
|
||||
break;
|
||||
case ECPGt_interval:
|
||||
return (_check(ptr, sizeof(Interval)));
|
||||
return (_check(ptr, sizeof(interval)));
|
||||
break;
|
||||
case ECPGt_timestamp:
|
||||
return (_check(ptr, sizeof(Timestamp)));
|
||||
return (_check(ptr, sizeof(timestamp)));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.8 2003/07/01 12:40:51 meskes Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.9 2003/09/09 10:46:37 meskes Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -49,15 +49,15 @@ ECPGtype_name(enum ECPGttype typ)
|
||||
case ECPGt_char_variable:
|
||||
return "char";
|
||||
case ECPGt_decimal:
|
||||
return "Decimal";
|
||||
return "decimal";
|
||||
case ECPGt_numeric:
|
||||
return "Numeric";
|
||||
return "numeric";
|
||||
case ECPGt_date:
|
||||
return "Date";
|
||||
return "date";
|
||||
case ECPGt_timestamp:
|
||||
return "Timestamp";
|
||||
return "timestamp";
|
||||
case ECPGt_interval:
|
||||
return "Interval";
|
||||
return "interval";
|
||||
case ECPGt_const:
|
||||
return "Const";
|
||||
default:
|
||||
|
Reference in New Issue
Block a user