Commits

Anonymous committed 421513b

Do not use the variable name when defining a varchar structure in ecpg.

With a unique counter being added anyway, there is no need anymore to have the variable name listed, too.

  • Participants
  • Parent commits 6c1603c
  • Branches rowexpr91

Comments (0)

Files changed (8)

File src/interfaces/ecpg/preproc/ecpg.trailer

 						mmerror(PARSE_ERROR, ET_ERROR, "pointers to varchar are not implemented");
 
 					/* make sure varchar struct name is unique by adding a unique counter to its definition */
-					vcn = (char *) mm_alloc(strlen($2) + sizeof(int) * CHAR_BIT * 10 / 3);
-					sprintf(vcn, "%s_%d", $2, varchar_counter);
+					vcn = (char *) mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
+					sprintf(vcn, "%d", varchar_counter);
 					if (strcmp(dimension, "0") == 0)
 						$$ = cat_str(7, make2_str(mm_strdup(" struct varchar_"), vcn), mm_strdup(" { int len; char arr["), mm_strdup(length), mm_strdup("]; } *"), mm_strdup($2), $4, $5);
 					else

File src/interfaces/ecpg/preproc/type.c

 	{
 		char	   *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
 		char	   *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
-		char	   *var_name,
-				   *ptr;
 
 		switch (type)
 		{
 				else
 					sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
 
-				/* remove trailing [] is name is array element */
-				var_name = mm_strdup(name);
-				ptr = strchr(var_name, '[');
-				if (ptr)
-					*ptr = '\0';
+				/* If we created a varchar structure atomatically, counter is greater than 0. */
 				if (counter)
-					sprintf(offset, "sizeof(struct varchar_%s_%d)", var_name, counter);
+					sprintf(offset, "sizeof(struct varchar_%d)", counter);
 				else
-					sprintf(offset, "sizeof(struct varchar_%s)", var_name);
-				free(var_name);
+					sprintf(offset, "sizeof(struct varchar)");
 				break;
 			case ECPGt_char:
 			case ECPGt_unsigned_char:

File src/interfaces/ecpg/preproc/type.h

 /* Everything is malloced. */
 void		ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
 struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *, int);
-struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
 struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *);
 struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *, char *);
 struct ECPGstruct_member *ECPGstruct_member_dup(struct ECPGstruct_member *);

File src/interfaces/ecpg/test/expected/preproc-array_of_struct.c

 
 typedef  struct { 
 #line 12 "array_of_struct.pgc"
-  struct varchar_name_1  { int len; char arr[ 50 ]; }  name ;
+  struct varchar_1  { int len; char arr[ 50 ]; }  name ;
  
 #line 13 "array_of_struct.pgc"
  int phone ;
              
        typedef struct { 
 #line 30 "array_of_struct.pgc"
-  struct varchar_name_2  { int len; char arr[ 50 ]; }  name ;
+  struct varchar_2  { int len; char arr[ 50 ]; }  name ;
  
 #line 31 "array_of_struct.pgc"
  int phone ;
 #line 38 "array_of_struct.pgc"
  struct customer3 { 
 #line 36 "array_of_struct.pgc"
-  struct varchar_name_3  { int len; char arr[ 50 ]; }  name ;
+  struct varchar_3  { int len; char arr[ 50 ]; }  name ;
  
 #line 37 "array_of_struct.pgc"
  int phone ;
 #line 43 "array_of_struct.pgc"
  struct customer4 { 
 #line 41 "array_of_struct.pgc"
-  struct varchar_name_4  { int len; char arr[ 50 ]; }  name ;
+  struct varchar_4  { int len; char arr[ 50 ]; }  name ;
  
 #line 42 "array_of_struct.pgc"
  int phone ;
  int r ;
  
 #line 45 "array_of_struct.pgc"
-  struct varchar_onlyname_5  { int len; char arr[ 50 ]; }  onlyname [ 2 ] ;
+  struct varchar_5  { int len; char arr[ 50 ]; }  onlyname [ 2 ] ;
 /* exec sql end declare section */
 #line 46 "array_of_struct.pgc"
 
     }
 
     { 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_name_4), 
+	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);
     printf( "phone - %d\n", custs4.phone );
 
     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select c from customers limit 2", ECPGt_EOIT, 
-	ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_onlyname_5), 
+	ECPGt_varchar,(onlyname),(long)50,(long)2,sizeof(struct varchar_5), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 85 "array_of_struct.pgc"
 

File src/interfaces/ecpg/test/expected/preproc-cursor.c

  char * curname3 = CURNAME ;
  
 #line 27 "cursor.pgc"
-  struct varchar_curname4_1  { int len; char arr[ 50 ]; }  curname4 ;
+  struct varchar_1  { int len; char arr[ 50 ]; }  curname4 ;
  
 #line 28 "cursor.pgc"
  int count ;
 
 	strcpy(msg, "open");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare $0 cursor for $1", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 
 	strcpy(msg, "fetch from");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 
 	strcpy(msg, "fetch");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 
 	strcpy(msg, "fetch 1 from");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 from $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 
 	strcpy(msg, "move");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "move absolute 0 $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 216 "cursor.pgc"
 
 
 	strcpy(msg, "fetch 1");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 
 	strcpy(msg, "close");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close $0", 
-	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_curname4_1), 
+	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 228 "cursor.pgc"
 

File src/interfaces/ecpg/test/expected/preproc-type.c

  c ptr = NULL ;
  
 #line 36 "type.pgc"
- struct varchar_vc { 
+ struct varchar { 
 #line 34 "type.pgc"
  int len ;
  
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(ptr),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
-	ECPGt_varchar,&(vc),(long)10,(long)1,sizeof(struct varchar_vc), 
+	ECPGt_varchar,&(vc),(long)10,(long)1,sizeof(struct varchar), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 68 "type.pgc"
 

File src/interfaces/ecpg/test/expected/preproc-variable.c

 #line 27 "variable.pgc"
  struct personal_struct { 
 #line 25 "variable.pgc"
-  struct varchar_name_1  { int len; char arr[ BUFFERSIZ ]; }  name ;
+  struct varchar_1  { int len; char arr[ BUFFERSIZ ]; }  name ;
  
 #line 26 "variable.pgc"
  struct birthinfo birth ;
  ind ind_children ;
  struct t1 { 
 #line 32 "variable.pgc"
-  struct varchar_name_2  { int len; char arr[ BUFFERSIZ ]; }  name ;
+  struct varchar_2  { int len; char arr[ BUFFERSIZ ]; }  name ;
  } ; struct t2 { 
 #line 32 "variable.pgc"
-  struct varchar_name_3  { int len; char arr[ BUFFERSIZ ]; }  name ;
+  struct varchar_3  { int len; char arr[ BUFFERSIZ ]; }  name ;
  } ;/* exec sql end declare section */
 #line 33 "variable.pgc"
 
 	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_name_1), 
+	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), 

File src/interfaces/ecpg/test/preproc/type.pgc

   struct TBempl empl;
   string str;
   c ptr = NULL;
-  struct varchar_vc
+  struct varchar
   {
   	int len;
 	char text[10];