- Added additional test case.
authorMichael Meskes
Fri, 7 May 2004 13:42:49 +0000 (13:42 +0000)
committerMichael Meskes
Fri, 7 May 2004 13:42:49 +0000 (13:42 +0000)
- Fixed bug that reversed string length in typedefs.
- Added portability file to pgtypeslib.

src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/pgtypeslib/Makefile
src/interfaces/ecpg/preproc/extern.h
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/variable.c
src/interfaces/ecpg/test/Makefile
src/interfaces/ecpg/test/test5.pgc [new file with mode: 0644]

index b1f3a52c3f43eabdeef5219c7508b3c98fa5c705..2a79f6048ac0cb2f58e6cb2a6e51e60d13a3e973 100644 (file)
@@ -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.
index 6e0692ef7ec840572b96b61ea37dcae1fe643040..fa02e09485a6b56bcf76f1c2dda7664fc6eb92d8 100644 (file)
@@ -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:
index 4ff8298e7199c16cc1dbf3cbf907f281addab09d..3383682fc46620f1499f4ac7f2259f590b6d34c0 100644 (file)
@@ -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);
index 8bec01187906a015b5d07826ff1cc6c8137ba136..b8642f2b91968e40226ffd9cb31745f0ad43bd1a 100644 (file)
@@ -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)
                {
index c4dfbb0f188766000f1fa03a0320c9c4517fd0f4..9663e29ef03efbf353e2a80404f54ad57694437e 100644 (file)
@@ -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");
index f50445c6d71cbee5912473852f8790489cbcc577..b3858466f3612555359f13baf1e652b79bcab99a 100644 (file)
@@ -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 (file)
index 0000000..928b3f2
--- /dev/null
@@ -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);
+}