mirror of
https://github.com/postgres/postgres.git
synced 2025-05-28 00:03:23 -04:00
Some bugfixes for numerical library.
This commit is contained in:
parent
a6f00f3939
commit
6fad73ed45
@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.2 2003/03/18 10:46:39 meskes Exp $ */
|
||||
|
||||
/*
|
||||
* The aim is to get a simpler inteface to the database routines.
|
||||
@ -861,7 +861,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
||||
}
|
||||
else
|
||||
{
|
||||
*str = PGTYPESnumeric_ntoa((NumericVar *)(var->value));
|
||||
str = PGTYPESnumeric_ntoa((NumericVar *)(var->value));
|
||||
slen = strlen (str);
|
||||
|
||||
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
|
||||
|
5
src/interfaces/ecpg/include/decimal.h
Normal file
5
src/interfaces/ecpg/include/decimal.h
Normal file
@ -0,0 +1,5 @@
|
||||
#include <pgtypes_numeric.h>
|
||||
|
||||
#ifndef dec_t
|
||||
#define dec_t NumericVar
|
||||
#endif /* dec_t */
|
@ -1,3 +1,6 @@
|
||||
#define PGTYPES_OVERFLOW 201
|
||||
#define PGTYPES_BAD_NUMERIC 202
|
||||
#define PGTYPES_DIVIDE_ZERO 203
|
||||
|
||||
#define PGTYPES_BAD_DATE 300
|
||||
|
||||
|
@ -40,6 +40,7 @@ pgtypes_alloc(long size)
|
||||
return (new);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* ----------
|
||||
* apply_typmod() -
|
||||
*
|
||||
@ -119,6 +120,7 @@ apply_typmod(NumericVar *var, long typmod)
|
||||
var->dscale = scale;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------
|
||||
* alloc_var() -
|
||||
@ -387,7 +389,9 @@ PGTYPESnumeric_aton(char *str, char **endptr)
|
||||
{
|
||||
NumericVar *value = (NumericVar *)pgtypes_alloc(sizeof(NumericVar));
|
||||
int ret;
|
||||
#if 0
|
||||
long typmod = -1;
|
||||
#endif
|
||||
char *realptr;
|
||||
char **ptr = (endptr != NULL) ? endptr : &realptr;
|
||||
|
||||
@ -398,10 +402,11 @@ PGTYPESnumeric_aton(char *str, char **endptr)
|
||||
if (ret)
|
||||
return (NULL);
|
||||
|
||||
#if 0
|
||||
ret = apply_typmod(value, typmod);
|
||||
if (ret)
|
||||
return (NULL);
|
||||
|
||||
#endif
|
||||
return(value);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.90 2003/02/14 13:17:13 meskes Exp $
|
||||
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.91 2003/03/18 10:46:39 meskes Exp $
|
||||
|
||||
subdir = src/interfaces/ecpg/preproc
|
||||
top_builddir = ../../../..
|
||||
@ -18,7 +18,7 @@ override CFLAGS += -Wno-error
|
||||
endif
|
||||
|
||||
OBJS=preproc.o type.o ecpg.o ecpg_keywords.o output.o\
|
||||
keywords.o c_keywords.o ../lib/typename.o descriptor.o variable.o
|
||||
keywords.o c_keywords.o ../ecpglib/typename.o descriptor.o variable.o
|
||||
|
||||
|
||||
all: submake-libpgport ecpg
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.62 2003/03/16 10:42:54 meskes Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.63 2003/03/18 10:46:39 meskes Exp $ */
|
||||
|
||||
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
||||
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
||||
@ -7,6 +7,7 @@
|
||||
#include "postgres_fe.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
@ -69,10 +70,27 @@ static void
|
||||
add_preprocessor_define(char *define)
|
||||
{
|
||||
struct _defines *pd = defines;
|
||||
|
||||
char *ptr, *define_copy = mm_strdup(define);
|
||||
|
||||
defines = mm_alloc(sizeof(struct _defines));
|
||||
defines->old = strdup(define);
|
||||
defines->new = strdup("");
|
||||
|
||||
/* look for = sign */
|
||||
ptr = strchr(define_copy, '=');
|
||||
if (ptr != NULL)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
/* symbol gets a value */
|
||||
for (tmp=ptr-1; *tmp == ' '; tmp--);
|
||||
tmp[1] = '\0';
|
||||
defines->old = define_copy;
|
||||
defines->new = ptr+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
defines->old = define_copy;
|
||||
defines->new = mm_strdup("");
|
||||
}
|
||||
defines->pertinent = true;
|
||||
defines->next = pd;
|
||||
}
|
||||
@ -137,7 +155,10 @@ main(int argc, char *const argv[])
|
||||
break;
|
||||
case 'C':
|
||||
if (strcmp(optarg, "INFORMIX") == 0)
|
||||
{
|
||||
compat = ECPG_COMPAT_INFORMIX;
|
||||
add_preprocessor_define("dec_t=NumericVar");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
|
||||
@ -313,7 +334,7 @@ main(int argc, char *const argv[])
|
||||
lex_init();
|
||||
|
||||
/* we need several includes */
|
||||
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These four include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n#include <ecpgerrno.h>\n#include <sqlca.h>\n#include <pgtypes_numeric.h>\n#line 1 \"%s\"\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL, input_filename);
|
||||
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n/* These four include files are added by the preprocessor */\n#include <ecpgtype.h>\n#include <ecpglib.h>\n#include <ecpgerrno.h>\n#include <sqlca.h>\n#line 1 \"%s\"\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL, input_filename);
|
||||
|
||||
/* add some compatibility headers */
|
||||
if (compat == ECPG_COMPAT_INFORMIX)
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <pgtypes_numeric.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char *text="error\n";
|
||||
NumericVar *value1, *value2, *res;
|
||||
NumericVar *value1, *value2, *res;
|
||||
exec sql begin declare section;
|
||||
decimal(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
|
||||
exec sql end declare section;
|
||||
@ -23,8 +24,8 @@ main()
|
||||
text = PGTYPESnumeric_ntoa(value1);
|
||||
printf("long = %s\n", text);
|
||||
|
||||
value1 = PGTYPESnumeric_aton("2369.7", -1);
|
||||
value2 = PGTYPESnumeric_aton("10.0", -1);
|
||||
value1 = PGTYPESnumeric_aton("2369.7", NULL);
|
||||
value2 = PGTYPESnumeric_aton("10.0", NULL);
|
||||
res = PGTYPESnew();
|
||||
decadd(value1, value2, res);
|
||||
text = PGTYPESnumeric_ntoa(res);
|
||||
@ -37,7 +38,7 @@ main()
|
||||
PGTYPESnumeric_copy(res, &des);
|
||||
exec sql insert into test (text, num) values ('test', :des);
|
||||
|
||||
value2 = PGTYPESnumeric_aton("2369.7", -1);
|
||||
value2 = PGTYPESnumeric_aton("2369.7", NULL);
|
||||
PGTYPESnumeric_mul(value1, value2, res);
|
||||
|
||||
exec sql select num into :des from test where text = 'test';
|
||||
@ -46,7 +47,7 @@ main()
|
||||
text = PGTYPESnumeric_ntoa(res);
|
||||
printf("mul = %s\n", text);
|
||||
|
||||
value2 = PGTYPESnumeric_aton("10000", -1);
|
||||
value2 = PGTYPESnumeric_aton("10000", NULL);
|
||||
PGTYPESnumeric_div(res, value2, res);
|
||||
text = PGTYPESnumeric_ntoa(res);
|
||||
PGTYPESnumeric_ntod(res, &d);
|
||||
|
@ -53,7 +53,7 @@ exec sql endif;
|
||||
char *connection="pm";
|
||||
int how_many;
|
||||
exec sql end declare section;
|
||||
exec sql var name is string(AMOUNT);
|
||||
exec sql var name is string[AMOUNT];
|
||||
char msg[128];
|
||||
FILE *dbgs;
|
||||
int i,j;
|
||||
|
Loading…
x
Reference in New Issue
Block a user