From 050710b36964dee7e1b2bf6b5ef00041fd5d2787 Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Mon, 18 Feb 2019 10:20:31 +0100 Subject: Add bytea datatype to ECPG. So far ECPG programs had to treat binary data for bytea column as 'char' type. But this meant converting from/to escaped format with PQunescapeBytea/ PQescapeBytea() and therefore forcing users to add unnecessary code and cost for the conversion in runtime. By adding a dedicated datatype for bytea most of this special handling is no longer needed. Author: Matsumura-san ("Matsumura, Ryo" ) Discussion: https://postgr.es/m/flat/03040DFF97E6E54E88D3BFEE5F5480F737A141F9@G01JPEXMBYT04 --- src/interfaces/ecpg/preproc/type.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/interfaces/ecpg/preproc/type.c') diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index afe90498b7..a9b4acfddf 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: -- cgit v1.2.1