1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

> 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
This commit is contained in:
Bruce Momjian
2001-09-14 17:46:40 +00:00
parent e8d5b8d290
commit c1fbf06654
11 changed files with 799 additions and 38 deletions

View File

@ -1,7 +1,7 @@
/*
* Edmund Mergl <E.Mergl@bawue.de>
*
* $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);
}
/********************************************************************
*