diff options
author | Michael Meskes <meskes@postgresql.org> | 2019-02-18 10:20:31 +0100 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2019-02-18 10:20:31 +0100 |
commit | 050710b36964dee7e1b2bf6b5ef00041fd5d2787 (patch) | |
tree | 888139b986d5d65660bd26d11c3c69d3b1d7e513 /src/interfaces/ecpg/preproc/type.c | |
parent | 3fdc374b5d24b08119a91555ca2fae427af0b085 (diff) | |
download | postgresql-050710b36964dee7e1b2bf6b5ef00041fd5d2787.tar.gz |
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" <matsumura.ryo@jp.fujitsu.com>)
Discussion: https://postgr.es/m/flat/03040DFF97E6E54E88D3BFEE5F5480F737A141F9@G01JPEXMBYT04
Diffstat (limited to 'src/interfaces/ecpg/preproc/type.c')
-rw-r--r-- | src/interfaces/ecpg/preproc/type.c | 15 |
1 files changed, 12 insertions, 3 deletions
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: |