From c1fbf06654aca97a109a2346d182158e8f14ab01 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 14 Sep 2001 17:46:40 +0000 Subject: > Here's a revised patch. Changes: > > 1. Now outputs '\\' instead of '\134' when using encode(bytea, 'escape') > Note that I ended up leaving \0 as \000 so that there are no ambiguities > when decoding something like, for example, \0123. > > 2. Fixed bug in byteain which allowed input values which were not valid > octals (e.g. \789), to be parsed as if they were octals. > > Joe > Here's rev 2 of the bytea string support patch. Changes: 1. Added missing declaration for MatchBytea function 2. Added PQescapeBytea to fe-exec.c 3. Applies cleanly on cvs tip from this afternoon I'm hoping that someone can review/approve/apply this before beta starts, so I guess I'd vote (not that it counts for much) to delay beta a few days :-) Joe Conway --- src/backend/utils/adt/oracle_compat.c | 74 ++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/oracle_compat.c') diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index b91230b1f0a..a0018522e8a 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -1,7 +1,7 @@ /* * Edmund Mergl * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.31 2001/03/22 03:59:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.32 2001/09/14 17:46:40 momjian Exp $ * */ @@ -349,6 +349,78 @@ btrim(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(ret); } +/******************************************************************** + * + * byteatrim + * + * Syntax: + * + * bytea byteatrim(byta string, bytea set) + * + * Purpose: + * + * Returns string with characters removed from the front and back + * up to the first character not in set. + * + * Cloned from btrim and modified as required. + ********************************************************************/ + +Datum +byteatrim(PG_FUNCTION_ARGS) +{ + bytea *string = PG_GETARG_BYTEA_P(0); + bytea *set = PG_GETARG_BYTEA_P(1); + bytea *ret; + char *ptr, + *end, + *ptr2, + *end2; + int m; + + if ((m = VARSIZE(string) - VARHDRSZ) <= 0 || + (VARSIZE(set) - VARHDRSZ) <= 0) + PG_RETURN_BYTEA_P(string); + + ptr = VARDATA(string); + end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1; + end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1; + + while (m > 0) + { + ptr2 = VARDATA(set); + while (ptr2 <= end2) + { + if (*ptr == *ptr2) + break; + ++ptr2; + } + if (ptr2 > end2) + break; + ptr++; + m--; + } + + while (m > 0) + { + ptr2 = VARDATA(set); + while (ptr2 <= end2) + { + if (*end == *ptr2) + break; + ++ptr2; + } + if (ptr2 > end2) + break; + end--; + m--; + } + + ret = (bytea *) palloc(VARHDRSZ + m); + VARATT_SIZEP(ret) = VARHDRSZ + m; + memcpy(VARDATA(ret), ptr, m); + + PG_RETURN_BYTEA_P(ret); +} /******************************************************************** * -- cgit v1.2.3