]> granicus.if.org Git - postgresql/commitdiff
Several fixes to array handling in ecpg.
authorMichael Meskes <meskes@postgresql.org>
Wed, 9 Apr 2014 09:21:46 +0000 (11:21 +0200)
committerMichael Meskes <meskes@postgresql.org>
Wed, 9 Apr 2014 09:38:40 +0000 (11:38 +0200)
Patches by Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>

src/interfaces/ecpg/preproc/type.c
src/interfaces/ecpg/test/expected/preproc-array_of_struct.c
src/interfaces/ecpg/test/expected/preproc-outofscope.c
src/interfaces/ecpg/test/expected/preproc-type.c
src/interfaces/ecpg/test/expected/preproc-variable.c

index de3b22f4c50400919b712a9fc0e2a5158a71ab18..780b6aab71b3ab0b70ded0d023efea3fa0b5dd13 100644 (file)
@@ -303,7 +303,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type, const int bra
 
                                        ECPGdump_a_simple(o, name,
                                                                          type->u.element->type,
-                                                                         type->u.element->size, type->size, NULL, prefix, type->u.element->counter);
+                                                                         type->u.element->size, type->size, struct_sizeof ? struct_sizeof : NULL,
+                                                                         prefix, type->u.element->counter);
 
                                        if (ind_type != NULL)
                                        {
@@ -481,11 +482,19 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
                                sprintf(offset, "sizeof(%s)", ecpg_type_name(type));
                                break;
                }
-
-               if (atoi(arrsize) < 0)
+               
+               /*
+                * Array size would be -1 for addresses of members within structure,
+                * when pointer to structure is being dumped.
+                */
+               if (atoi(arrsize) < 0 && !siz)
                        strcpy(arrsize, "1");
 
-               if (siz == NULL || strlen(siz) == 0 || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
+               /*
+                * If siz i.e. the size of structure of which this variable is part of,
+                * that gives the offset to the next element, if required 
+                */
+               if (siz == NULL || strlen(siz) == 0)
                        fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
                else
                        fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
index 9bb09cc38f46bc38dc741100909cab80d5fb6655..216f234b92e6b45db995d6a2eff26b96c947ca21 100644 (file)
@@ -235,10 +235,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
     }
 
     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from customers limit 1", ECPGt_EOIT, 
-       ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof(struct varchar_4), 
-       ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof(short), 
-       ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof(int), 
-       ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
+       ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof( struct customer4 ), 
+       ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof( struct ind ), 
+       ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof( struct customer4 ), 
+       ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof( struct ind ), ECPGt_EORT);
 #line 80 "array_of_struct.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
index 125d7d8513e7c7a949bcd8d99238500efd9a91df..8e81c999d7fec17db399eb6e29fb11070f4029a8 100644 (file)
@@ -202,16 +202,16 @@ static void
 open_cur1(void)
 {
        { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
-       ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
-       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int), 
-       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int), 
-       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int), 
-       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
+       ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
 #line 40 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -226,16 +226,16 @@ static void
 get_record1(void)
 {
        { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
-       ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
-       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof(int), 
-       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof(double), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof(int), 
-       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof(double), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof(int), 
-       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,(30)*sizeof(char), 
-       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof(int), ECPGt_EORT);
+       ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ), 
+       ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ), 
+       ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
 #line 49 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
index f913158ff92d7af1b59d10f36adf82e85cff1667..95780236f0ce13c4d644ee15d9ca3c7db90d3d88 100644 (file)
@@ -140,11 +140,11 @@ main (void)
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select idnum , name , accs , string1 , string2 , string3 from empl where idnum = $1 ", 
        ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
-       ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
+       ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof( struct TBempl ), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
-       ECPGt_char,&(empl.name),(long)21,(long)1,(21)*sizeof(char), 
+       ECPGt_char,&(empl.name),(long)21,(long)1,sizeof( struct TBempl ), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
-       ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), 
+       ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof( struct TBempl ), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
        ECPGt_char,(str),(long)11,(long)1,(11)*sizeof(char), 
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
index 32e9778ee686a7d5a5d3516e2b494f47fd32f4e6..a93af97063bba3c2432dfd6b8aa0e3f09a6a8405 100644 (file)
@@ -207,12 +207,12 @@ if (sqlca.sqlcode < 0) exit (1);}
        while (1) {
                strcpy(msg, "fetch");
                { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT, 
-       ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_1), 
-       ECPGt_int,&(i->ind_name),(long)1,(long)1,sizeof(int), 
-       ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof(long), 
-       ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof(long), 
-       ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof(short), 
-       ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof(short), 
+       ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ), 
+       ECPGt_int,&(i->ind_name),(long)1,(long)-1,sizeof( struct birthinfo ), 
+       ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof( struct birthinfo ), 
+       ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof( struct birthinfo ), 
+       ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof( struct birthinfo ), 
+       ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof( struct birthinfo ), 
        ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char), 
        ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long), 
        ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int),