From 2b5561264506dbf4bfbf2730248320629c62e225 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Fri, 7 May 2004 13:42:49 +0000 Subject: [PATCH] - Added additional test case. - Fixed bug that reversed string length in typedefs. - Added portability file to pgtypeslib. --- src/interfaces/ecpg/ChangeLog | 6 +++ src/interfaces/ecpg/pgtypeslib/Makefile | 7 +++- src/interfaces/ecpg/preproc/extern.h | 2 +- src/interfaces/ecpg/preproc/preproc.y | 11 +++--- src/interfaces/ecpg/preproc/variable.c | 9 +++-- src/interfaces/ecpg/test/Makefile | 4 +- src/interfaces/ecpg/test/test5.pgc | 66 +++++++++++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 src/interfaces/ecpg/test/test5.pgc diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog index b1f3a52c3f..2a79f6048a 100644 --- a/src/interfaces/ecpg/ChangeLog +++ b/src/interfaces/ecpg/ChangeLog @@ -1784,6 +1784,12 @@ Wed May 5 11:51:47 CEST 2004 variables. - Synced parser again. - Synced lexer. + +Fri May 7 15:34:05 CEST 2004 + + - Added portability file to pgtypeslib. + - Fixed bug that reversed string length in typedefs. + - Added additional test case. - Set pgtypes library version to 1.2. - Set ecpg version to 3.2.0. - Set compat library version to 1.2. diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile index 6e0692ef7e..fa02e09485 100644 --- a/src/interfaces/ecpg/pgtypeslib/Makefile +++ b/src/interfaces/ecpg/pgtypeslib/Makefile @@ -4,7 +4,7 @@ # # Copyright (c) 1994, Regents of the University of California # -# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.18 2004/04/30 04:14:06 momjian Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.19 2004/05/07 13:42:48 meskes Exp $ # #------------------------------------------------------------------------- @@ -23,7 +23,7 @@ override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include \ SHLIB_LINK += -lm OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \ - $(filter rint.o, $(LIBOBJS)) + $(filter rint.o, $(LIBOBJS)) $(filter pgstrcasecmp.o, $(LIBOBJS)) all: all-lib @@ -33,6 +33,9 @@ include $(top_srcdir)/src/Makefile.shlib rint.c: %.c : $(top_srcdir)/src/port/%.c rm -f $@ && $(LN_S) $< . +pgstrcasecmp.c: %.c : $(top_srcdir)/src/port/%.c + rm -f $@ && $(LN_S) $< . + install: all installdirs install-lib installdirs: diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 4ff8298e71..3383682fc4 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -79,7 +79,7 @@ extern void add_variable_to_head(struct arguments **, struct variable *, struct extern void add_variable_to_tail(struct arguments **, struct variable *, struct variable *); extern void dump_variables(struct arguments *, int); extern struct typedefs *get_typedef(char *); -extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int); +extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int, bool); extern void reset_variables(void); extern void check_indicator(struct ECPGtype *); extern void remove_variables(int); diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 8bec011879..b8642f2b91 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.280 2004/05/07 00:24:59 tgl Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.281 2004/05/07 13:42:49 meskes Exp $ */ /* Copyright comment */ %{ @@ -4574,8 +4574,7 @@ type_declaration: S_TYPEDEF mmerror(PARSE_ERROR, ET_ERROR, errortext); } } - - adjust_array($3.type_enum, &dimension, &length, $3.type_dimension, $3.type_index, *$4?1:0); + adjust_array($3.type_enum, &dimension, &length, $3.type_dimension, $3.type_index, *$4?1:0, true); this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); @@ -5021,7 +5020,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_initializer char *length = $3.index2; /* length of string */ char dim[14L]; - adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1)); + adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1), false); switch (actual_type[struct_level].type_enum) { @@ -5411,7 +5410,7 @@ ECPGTypedef: TYPE_P } } - adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0); + adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false); this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); @@ -5469,7 +5468,7 @@ ECPGVar: SQL_VAR mmerror(PARSE_ERROR, ET_ERROR, "Initializer not allowed in EXEC SQL VAR command"); else { - adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0); + adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false); switch ($5.type_enum) { diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index c4dfbb0f18..9663e29ef0 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -459,7 +459,7 @@ get_typedef(char *name) } void -adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len) +adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len, bool type_definition) { if (atoi(type_index) >= 0) { @@ -484,7 +484,6 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty { snprintf(errortext, sizeof(errortext), "No multilevel (more than 2) pointer supported %d", pointer_len); mmerror(PARSE_ERROR, ET_FATAL, errortext); -/* mmerror(PARSE_ERROR, ET_FATAL, "No multilevel (more than 2) pointer supported %d",pointer_len);*/ } if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char) @@ -544,7 +543,11 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty * make sure we return length = -1 for arrays without * given bounds */ - if (atoi(*dimension) < 0) + if (atoi(*dimension) < 0 && !type_definition) + /* + * do not change this for typedefs + * since it will be changed later on when the variable is defined + */ *length = make_str("1"); else if (atoi(*dimension) == 0) *length = make_str("-1"); diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile index f50445c6d7..b3858466f3 100644 --- a/src/interfaces/ecpg/test/Makefile +++ b/src/interfaces/ecpg/test/Makefile @@ -1,4 +1,4 @@ -# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.47 2004/04/30 04:14:06 momjian Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.48 2004/05/07 13:42:49 meskes Exp $ subdir = src/interfaces/ecpg/test top_builddir = ../../../.. @@ -9,7 +9,7 @@ override CFLAGS += $(PTHREAD_CFLAGS) ECPG = ../preproc/ecpg -I$(srcdir)/../include -TESTS = test1 test2 test3 test4 perftest dyntest dyntest2 test_notice \ +TESTS = test1 test2 test3 test4 test5 perftest dyntest dyntest2 test_notice \ test_code100 test_init testdynalloc num_test dt_test test_informix ifeq ($(enable_thread_safety), yes) TESTS += test_thread test_thread_implicit diff --git a/src/interfaces/ecpg/test/test5.pgc b/src/interfaces/ecpg/test/test5.pgc new file mode 100644 index 0000000000..928b3f2a57 --- /dev/null +++ b/src/interfaces/ecpg/test/test5.pgc @@ -0,0 +1,66 @@ +#include +#include + +EXEC SQL typedef long mmInteger; +EXEC SQL typedef char mmChar; +EXEC SQL typedef short mmSmallInt; + +EXEC SQL BEGIN DECLARE SECTION; +struct TBempl + { + mmInteger idnum; + mmChar name[21]; + mmSmallInt accs; + }; +EXEC SQL END DECLARE SECTION; + +int main() +{ +EXEC SQL BEGIN DECLARE SECTION; +struct TBempl empl; +EXEC SQL END DECLARE SECTION; +FILE *dbgs; + +if ((dbgs = fopen("log", "w")) != NULL) + ECPGdebug(1, dbgs); + +empl.idnum = 1; +EXEC SQL connect to mm; +if (sqlca.sqlcode) + { + printf("connect error = %ld\n", sqlca.sqlcode); + exit(sqlca.sqlcode); + } + +EXEC SQL create table empl + ( + idnum integer, + name char(20), + accs smallint + ); +if (sqlca.sqlcode) + { + printf("select error = %ld\n", sqlca.sqlcode); + exit(sqlca.sqlcode); + } + +EXEC SQL insert into empl values (1, 'first user', 20); +if (sqlca.sqlcode) + { + printf("select error = %ld\n", sqlca.sqlcode); + exit(sqlca.sqlcode); + } + +EXEC SQL select name, accs + into :empl.name, :empl.accs + from empl where idnum = :empl.idnum; +if (sqlca.sqlcode) + { + printf("select error = %ld\n", sqlca.sqlcode); + exit(sqlca.sqlcode); + } +printf("name=%s, accs=%d\n", empl.name, empl.accs); +EXEC SQL disconnect; +fclose(dbgs); +exit(0); +} -- 2.11.0