diff options
| author | Michael Meskes <meskes@postgresql.org> | 2003-03-16 10:42:54 +0000 |
|---|---|---|
| committer | Michael Meskes <meskes@postgresql.org> | 2003-03-16 10:42:54 +0000 |
| commit | a4f25b6a9c2dbf5f38e498922e3761cb3bf46ba0 (patch) | |
| tree | 54ff23d698b18c898c8fd7903df29b76e95df9fb /src/interfaces/ecpg/test | |
| parent | 48dfa0d057e0d9b2244ff1706dd72e91a0b45064 (diff) | |
| download | postgresql-a4f25b6a9c2dbf5f38e498922e3761cb3bf46ba0.tar.gz | |
Started working on a seperate pgtypes library. First test work. PLEASE test compilation on iother systems.
Diffstat (limited to 'src/interfaces/ecpg/test')
| -rw-r--r-- | src/interfaces/ecpg/test/Makefile | 6 | ||||
| -rw-r--r-- | src/interfaces/ecpg/test/num_test.pgc | 56 |
2 files changed, 59 insertions, 3 deletions
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index c5b50c6e0f..7c9c0d1edc 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -1,4 +1,4 @@ -# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.33 2001/12/23 12:17:41 meskes Exp $ +# $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Makefile,v 1.34 2003/03/16 10:42:54 meskes Exp $ subdir = src/interfaces/ecpg/test top_builddir = ../../../.. @@ -8,12 +8,12 @@ override CPPFLAGS := -I$(srcdir)/../include $(CPPFLAGS) -g ECPG = ../preproc/ecpg -I$(srcdir)/../include -TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc +TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice test_code100 test_init testdynalloc num_test all: $(TESTS) %: %.o - $(CC) $(CFLAGS) $(LDFLAGS) -L../lib -L../../libpq $^ $(LIBS) -lecpg -lpq -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) -L../ecpglib -L ../pgtypeslib -L../../libpq $^ $(LIBS) -lpgtypes -lecpg -lpq -o $@ %.c: %.pgc $(ECPG) $< diff --git a/src/interfaces/ecpg/test/num_test.pgc b/src/interfaces/ecpg/test/num_test.pgc new file mode 100644 index 0000000000..741ae16751 --- /dev/null +++ b/src/interfaces/ecpg/test/num_test.pgc @@ -0,0 +1,56 @@ +#include <stdio.h> + +int +main() +{ + char *text="error\n"; + 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; + double d; + FILE *dbgs; + + if ((dbgs = fopen("log", "w")) != NULL) + ECPGdebug(1, dbgs); + exec sql whenever sqlerror do sqlprint(); + + exec sql connect to mm; + exec sql create table test (text char(5), num decimal(14,7)); + + value1 = PGTYPESnew(); + PGTYPESnumeric_iton(1407, value1); + text = PGTYPESnumeric_ntoa(value1); + printf("long = %s\n", text); + + value1 = PGTYPESnumeric_aton("2369.7", -1); + value2 = PGTYPESnumeric_aton("10.0", -1); + res = PGTYPESnew(); + decadd(value1, value2, res); + text = PGTYPESnumeric_ntoa(res); + printf("add = %s\n", text); + + PGTYPESnumeric_sub(res, value2, res); + text = PGTYPESnumeric_ntoa(res); + printf("sub = %s\n", text); + + PGTYPESnumeric_copy(res, &des); + exec sql insert into test (text, num) values ('test', :des); + + value2 = PGTYPESnumeric_aton("2369.7", -1); + PGTYPESnumeric_mul(value1, value2, res); + + exec sql select num into :des from test where text = 'test'; + + PGTYPESnumeric_mul(res, &des, res); + text = PGTYPESnumeric_ntoa(res); + printf("mul = %s\n", text); + + value2 = PGTYPESnumeric_aton("10000", -1); + PGTYPESnumeric_div(res, value2, res); + text = PGTYPESnumeric_ntoa(res); + PGTYPESnumeric_ntod(res, &d); + printf("div = %s %e\n", text, d); + return (0); +} + |
