aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/preproc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/preproc')
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.header2
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.trailer39
-rw-r--r--src/interfaces/ecpg/preproc/type.c15
-rw-r--r--src/interfaces/ecpg/preproc/variable.c1
4 files changed, 45 insertions, 12 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header
index a6f870dcda2..366dc231caf 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -47,6 +47,7 @@ static char pacounter_buffer[sizeof(int) * CHAR_BIT * 10 / 3]; /* a rough guess
static struct this_type actual_type[STRUCT_DEPTH];
static char *actual_startline[STRUCT_DEPTH];
static int varchar_counter = 1;
+static int bytea_counter = 1;
/* temporarily store struct members while creating the data structure */
struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH] = { NULL };
@@ -563,6 +564,7 @@ add_typedef(char *name, char *dimension, char *length, enum ECPGttype type_enum,
ECPGstruct_member_dup(struct_member_list[struct_level]) : NULL;
if (type_enum != ECPGt_varchar &&
+ type_enum != ECPGt_bytea &&
type_enum != ECPGt_char &&
type_enum != ECPGt_unsigned_char &&
type_enum != ECPGt_string &&
diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 6755d4a0d27..88b27a297a8 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -580,6 +580,14 @@ var_type: simple_type
$$.type_index = mm_strdup("-1");
$$.type_sizeof = NULL;
}
+ else if (strcmp($1, "bytea") == 0)
+ {
+ $$.type_enum = ECPGt_bytea;
+ $$.type_str = EMPTY;
+ $$.type_dimension = mm_strdup("-1");
+ $$.type_index = mm_strdup("-1");
+ $$.type_sizeof = NULL;
+ }
else if (strcmp($1, "float") == 0)
{
$$.type_enum = ECPGt_float;
@@ -657,7 +665,7 @@ var_type: simple_type
/* this is for typedef'ed types */
struct typedefs *this = get_typedef($1);
- $$.type_str = (this->type->type_enum == ECPGt_varchar) ? EMPTY : mm_strdup(this->name);
+ $$.type_str = (this->type->type_enum == ECPGt_varchar || this->type->type_enum == ECPGt_bytea) ? EMPTY : mm_strdup(this->name);
$$.type_enum = this->type->type_enum;
$$.type_dimension = this->type->type_dimension;
$$.type_index = this->type->type_index;
@@ -868,7 +876,7 @@ variable_list: variable
{ $$ = $1; }
| variable_list ',' variable
{
- if (actual_type[struct_level].type_enum == ECPGt_varchar)
+ if (actual_type[struct_level].type_enum == ECPGt_varchar || actual_type[struct_level].type_enum == ECPGt_bytea)
$$ = cat_str(3, $1, mm_strdup(";"), $3);
else
$$ = cat_str(3, $1, mm_strdup(","), $3);
@@ -882,9 +890,10 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
char *length = $3.index2; /* length of string */
char *dim_str;
char *vcn;
+ int *varlen_type_counter;
+ char *struct_name;
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)
{
case ECPGt_struct:
@@ -898,10 +907,21 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
break;
case ECPGt_varchar:
+ case ECPGt_bytea:
+ if (actual_type[struct_level].type_enum == ECPGt_varchar)
+ {
+ varlen_type_counter = &varchar_counter;
+ struct_name = " struct varchar_";
+ }
+ else
+ {
+ varlen_type_counter = &bytea_counter;
+ struct_name = " struct bytea_";
+ }
if (atoi(dimension) < 0)
- type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, varchar_counter);
+ type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, *varlen_type_counter);
else
- type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, varchar_counter), dimension);
+ type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, *varlen_type_counter), dimension);
if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1)
dim_str=mm_strdup("");
@@ -913,12 +933,12 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
/* make sure varchar struct name is unique by adding a unique counter to its definition */
vcn = (char *) mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
- sprintf(vcn, "%d", varchar_counter);
+ sprintf(vcn, "%d", *varlen_type_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);
+ $$ = cat_str(7, make2_str(mm_strdup(struct_name), vcn), mm_strdup(" { int len; char arr["), mm_strdup(length), mm_strdup("]; } *"), mm_strdup($2), $4, $5);
else
- $$ = cat_str(8, make2_str(mm_strdup(" struct varchar_"), vcn), mm_strdup(" { int len; char arr["), mm_strdup(length), mm_strdup("]; } "), mm_strdup($2), dim_str, $4, $5);
- varchar_counter++;
+ $$ = cat_str(8, make2_str(mm_strdup(struct_name), vcn), mm_strdup(" { int len; char arr["), mm_strdup(length), mm_strdup("]; } "), mm_strdup($2), dim_str, $4, $5);
+ (*varlen_type_counter)++;
break;
case ECPGt_char:
@@ -1384,6 +1404,7 @@ ECPGVar: SQL_VAR
break;
case ECPGt_varchar:
+ case ECPGt_bytea:
if (atoi(dimension) == -1)
type = ECPGmake_simple_type($5.type_enum, length, 0);
else
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index afe90498b72..a9b4acfddfb 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -102,7 +102,7 @@ ECPGmake_simple_type(enum ECPGttype type, char *size, int counter)
ne->size = size;
ne->u.element = NULL;
ne->struct_sizeof = NULL;
- ne->counter = counter; /* only needed for varchar */
+ ne->counter = counter; /* only needed for varchar and bytea */
return ne;
}
@@ -175,6 +175,8 @@ get_type(enum ECPGttype type)
break;
case ECPGt_varchar:
return "ECPGt_varchar";
+ case ECPGt_bytea:
+ return "ECPGt_bytea";
case ECPGt_NO_INDICATOR: /* no indicator */
return "ECPGt_NO_INDICATOR";
break;
@@ -424,6 +426,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
{
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 *struct_name;
switch (type)
{
@@ -433,6 +436,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
*/
case ECPGt_varchar:
+ case ECPGt_bytea:
/*
* we have to use the pointer except for arrays with given
@@ -449,10 +453,15 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* If we created a varchar structure automatically, counter is
* greater than 0.
*/
+ if (type == ECPGt_varchar)
+ struct_name = "struct varchar";
+ else
+ struct_name = "struct bytea";
+
if (counter)
- sprintf(offset, "sizeof(struct varchar_%d)", counter);
+ sprintf(offset, "sizeof(%s_%d)", struct_name, counter);
else
- sprintf(offset, "sizeof(struct varchar)");
+ sprintf(offset, "sizeof(%s)", struct_name);
break;
case ECPGt_char:
case ECPGt_unsigned_char:
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index a953498c1c9..887d479e735 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -560,6 +560,7 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty
break;
case ECPGt_varchar:
+ case ECPGt_bytea:
/* pointer has to get dimension 0 */
if (pointer_len)
*dimension = mm_strdup("0");