mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Functions on 'text' type updated to new fmgr style. 'text' is
now TOAST-able.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* workings can be found in the book "Software Solutions in C" by
|
||||
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.41 2000/07/03 23:09:50 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.42 2000/07/06 05:48:11 tgl Exp $
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
@@ -41,7 +41,7 @@ static struct lconv *lconvert = NULL;
|
||||
* Cash is a pass-by-ref SQL type, so we must pass and return pointers.
|
||||
* These macros and support routine hide the pass-by-refness.
|
||||
*/
|
||||
#define PG_GETARG_CASH(n) (* ((Cash *) DatumGetPointer(fcinfo->arg[n])))
|
||||
#define PG_GETARG_CASH(n) (* ((Cash *) PG_GETARG_POINTER(n)))
|
||||
#define PG_RETURN_CASH(x) return CashGetDatum(x)
|
||||
|
||||
static Datum
|
||||
@@ -677,10 +677,11 @@ cashsmaller(Cash *c1, Cash *c2)
|
||||
* This converts a int4 as well but to a representation using words
|
||||
* Obviously way North American centric - sorry
|
||||
*/
|
||||
text *
|
||||
cash_words_out(Cash *value)
|
||||
Datum
|
||||
cash_words_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
static char buf[128];
|
||||
Cash value = PG_GETARG_CASH(0);
|
||||
char buf[128];
|
||||
char *p = buf;
|
||||
Cash m0;
|
||||
Cash m1;
|
||||
@@ -689,19 +690,19 @@ cash_words_out(Cash *value)
|
||||
text *result;
|
||||
|
||||
/* work with positive numbers */
|
||||
if (*value < 0)
|
||||
if (value < 0)
|
||||
{
|
||||
*value *= -1;
|
||||
value = -value;
|
||||
strcpy(buf, "minus ");
|
||||
p += 6;
|
||||
}
|
||||
else
|
||||
*buf = 0;
|
||||
buf[0] = '\0';
|
||||
|
||||
m0 = *value % 100; /* cents */
|
||||
m1 = (*value / 100) % 1000; /* hundreds */
|
||||
m2 = (*value / 100000) % 1000; /* thousands */
|
||||
m3 = *value / 100000000 % 1000; /* millions */
|
||||
m0 = value % 100; /* cents */
|
||||
m1 = (value / 100) % 1000; /* hundreds */
|
||||
m2 = (value / 100000) % 1000; /* thousands */
|
||||
m3 = value / 100000000 % 1000; /* millions */
|
||||
|
||||
if (m3)
|
||||
{
|
||||
@@ -721,20 +722,20 @@ cash_words_out(Cash *value)
|
||||
if (!*p)
|
||||
strcat(buf, "zero");
|
||||
|
||||
strcat(buf, (int) (*value / 100) == 1 ? " dollar and " : " dollars and ");
|
||||
strcat(buf, (int) (value / 100) == 1 ? " dollar and " : " dollars and ");
|
||||
strcat(buf, num_word(m0));
|
||||
strcat(buf, m0 == 1 ? " cent" : " cents");
|
||||
|
||||
/* capitalize output */
|
||||
*buf = toupper(*buf);
|
||||
buf[0] = toupper(buf[0]);
|
||||
|
||||
/* make a text type for output */
|
||||
result = (text *) palloc(strlen(buf) + VARHDRSZ);
|
||||
VARATT_SIZEP(result) = strlen(buf) + VARHDRSZ;
|
||||
memcpy(VARDATA(result), buf, strlen(buf));
|
||||
|
||||
return result;
|
||||
} /* cash_words_out() */
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.62 2000/07/03 23:09:50 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.63 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -941,91 +941,99 @@ i2tof(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* float8_text - converts a float8 number to a text string
|
||||
*/
|
||||
text *
|
||||
float8_text(float64 num)
|
||||
Datum
|
||||
float8_text(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float8 num = PG_GETARG_FLOAT8(0);
|
||||
text *result;
|
||||
int len;
|
||||
char *str;
|
||||
|
||||
str = float8out(num);
|
||||
len = (strlen(str) + VARHDRSZ);
|
||||
str = float8out(&num); /* XXX temporary hack */
|
||||
len = strlen(str) + VARHDRSZ;
|
||||
|
||||
result = palloc(len);
|
||||
result = (text *) palloc(len);
|
||||
|
||||
VARATT_SIZEP(result) = len;
|
||||
memmove(VARDATA(result), str, (len - VARHDRSZ));
|
||||
memcpy(VARDATA(result), str, (len - VARHDRSZ));
|
||||
|
||||
pfree(str);
|
||||
return result;
|
||||
} /* float8_text() */
|
||||
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* text_float8 - converts a text string to a float8 number
|
||||
*/
|
||||
float64
|
||||
text_float8(text *string)
|
||||
Datum
|
||||
text_float8(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
float64 result;
|
||||
int len;
|
||||
char *str;
|
||||
|
||||
len = (VARSIZE(string) - VARHDRSZ);
|
||||
str = palloc(len + 1);
|
||||
memmove(str, VARDATA(string), len);
|
||||
memcpy(str, VARDATA(string), len);
|
||||
*(str + len) = '\0';
|
||||
|
||||
result = float8in(str);
|
||||
|
||||
pfree(str);
|
||||
|
||||
return result;
|
||||
} /* text_float8() */
|
||||
return PointerGetDatum(result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* float4_text - converts a float4 number to a text string
|
||||
*/
|
||||
text *
|
||||
float4_text(float32 num)
|
||||
Datum
|
||||
float4_text(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float4 num = PG_GETARG_FLOAT4(0);
|
||||
text *result;
|
||||
int len;
|
||||
char *str;
|
||||
|
||||
str = float4out(num);
|
||||
len = (strlen(str) + VARHDRSZ);
|
||||
str = float4out(&num); /* XXX temporary hack */
|
||||
len = strlen(str) + VARHDRSZ;
|
||||
|
||||
result = palloc(len);
|
||||
result = (text *) palloc(len);
|
||||
|
||||
VARATT_SIZEP(result) = len;
|
||||
memmove(VARDATA(result), str, (len - VARHDRSZ));
|
||||
memcpy(VARDATA(result), str, (len - VARHDRSZ));
|
||||
|
||||
pfree(str);
|
||||
return result;
|
||||
} /* float4_text() */
|
||||
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* text_float4 - converts a text string to a float4 number
|
||||
*/
|
||||
float32
|
||||
text_float4(text *string)
|
||||
Datum
|
||||
text_float4(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
float32 result;
|
||||
int len;
|
||||
char *str;
|
||||
|
||||
len = (VARSIZE(string) - VARHDRSZ);
|
||||
str = palloc(len + 1);
|
||||
memmove(str, VARDATA(string), len);
|
||||
memcpy(str, VARDATA(string), len);
|
||||
*(str + len) = '\0';
|
||||
|
||||
result = float4in(str);
|
||||
|
||||
pfree(str);
|
||||
|
||||
return result;
|
||||
} /* text_float4() */
|
||||
return PointerGetDatum(result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,15 +11,16 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.35 2000/06/14 18:59:42 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.36 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "mb/pg_wchar.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
static int like(pg_wchar * text, pg_wchar * p);
|
||||
static bool like(pg_wchar * text, pg_wchar * p);
|
||||
|
||||
/*
|
||||
* interface routines called by the function manager
|
||||
@@ -30,20 +31,17 @@ static int like(pg_wchar * text, pg_wchar * p);
|
||||
|
||||
a generic fixed length like routine
|
||||
s - the string to match against (not necessarily null-terminated)
|
||||
p - the pattern
|
||||
p - the pattern (as text*)
|
||||
charlen - the length of the string
|
||||
*/
|
||||
static bool
|
||||
fixedlen_like(char *s, struct varlena * p, int charlen)
|
||||
fixedlen_like(char *s, text *p, int charlen)
|
||||
{
|
||||
pg_wchar *sterm,
|
||||
*pterm;
|
||||
int result;
|
||||
bool result;
|
||||
int len;
|
||||
|
||||
if (!s || !p)
|
||||
return FALSE;
|
||||
|
||||
/* be sure sterm is null-terminated */
|
||||
#ifdef MULTIBYTE
|
||||
sterm = (pg_wchar *) palloc((charlen + 1) * sizeof(pg_wchar));
|
||||
@@ -54,7 +52,7 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* p is a text = varlena, not a string so we have to make a string
|
||||
* p is a text, not a string so we have to make a string
|
||||
* from the vl_data field of the struct.
|
||||
*/
|
||||
|
||||
@@ -65,8 +63,8 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
|
||||
(void) pg_mb2wchar_with_len((unsigned char *) VARDATA(p), pterm, len);
|
||||
#else
|
||||
pterm = (char *) palloc(len + 1);
|
||||
memmove(pterm, VARDATA(p), len);
|
||||
*(pterm + len) = (char) NULL;
|
||||
memcpy(pterm, VARDATA(p), len);
|
||||
*(pterm + len) = '\0';
|
||||
#endif
|
||||
|
||||
/* do the regexp matching */
|
||||
@@ -75,35 +73,43 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
|
||||
pfree(sterm);
|
||||
pfree(pterm);
|
||||
|
||||
return (bool) result;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
namelike(NameData *n, struct varlena * p)
|
||||
Datum
|
||||
namelike(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!n)
|
||||
return FALSE;
|
||||
return fixedlen_like(NameStr(*n), p, NAMEDATALEN);
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_like(NameStr(*n), p, strlen(NameStr(*n))));
|
||||
}
|
||||
|
||||
bool
|
||||
namenlike(NameData *s, struct varlena * p)
|
||||
Datum
|
||||
namenlike(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !namelike(s, p);
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_like(NameStr(*n), p, strlen(NameStr(*n))));
|
||||
}
|
||||
|
||||
bool
|
||||
textlike(struct varlena * s, struct varlena * p)
|
||||
Datum
|
||||
textlike(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!s)
|
||||
return FALSE;
|
||||
return fixedlen_like(VARDATA(s), p, VARSIZE(s) - VARHDRSZ);
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_like(VARDATA(s), p, VARSIZE(s) - VARHDRSZ));
|
||||
}
|
||||
|
||||
bool
|
||||
textnlike(struct varlena * s, struct varlena * p)
|
||||
Datum
|
||||
textnlike(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !textlike(s, p);
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_like(VARDATA(s), p, VARSIZE(s) - VARHDRSZ));
|
||||
}
|
||||
|
||||
|
||||
@@ -221,11 +227,11 @@ DoMatch(pg_wchar * text, pg_wchar * p)
|
||||
/*
|
||||
** User-level routine. Returns TRUE or FALSE.
|
||||
*/
|
||||
static int
|
||||
static bool
|
||||
like(pg_wchar * text, pg_wchar * p)
|
||||
{
|
||||
/* Fast path for match-everything pattern */
|
||||
if (p[0] == '%' && p[1] == '\0')
|
||||
return TRUE;
|
||||
return true;
|
||||
return DoMatch(text, p) == LIKE_TRUE;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* ----------
|
||||
* lztext.c -
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.9 2000/07/05 10:09:53 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.10 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
* Text type with internal LZ compressed representation. Uses the
|
||||
* standard PostgreSQL compression method.
|
||||
@@ -174,19 +174,13 @@ lztextoctetlen(lztext *lz)
|
||||
* Convert text to lztext
|
||||
* ----------
|
||||
*/
|
||||
lztext *
|
||||
text_lztext(text *txt)
|
||||
Datum
|
||||
text_lztext(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *txt = PG_GETARG_TEXT_P(0);
|
||||
lztext *result;
|
||||
int32 rawsize;
|
||||
|
||||
/* ----------
|
||||
* Handle NULL
|
||||
* ----------
|
||||
*/
|
||||
if (txt == NULL)
|
||||
return NULL;
|
||||
|
||||
/* ----------
|
||||
* Copy the entire attribute
|
||||
* ----------
|
||||
@@ -196,7 +190,7 @@ text_lztext(text *txt)
|
||||
VARATT_SIZEP(result) = rawsize + VARHDRSZ;
|
||||
memcpy(VARATT_DATA(result), VARATT_DATA(txt), rawsize);
|
||||
|
||||
return result;
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
/*
|
||||
* PostgreSQL type definitions for MAC addresses.
|
||||
*
|
||||
* $Id: mac.c,v 1.15 2000/07/03 23:09:52 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.16 2000/07/06 05:48:11 tgl Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/builtins.h"
|
||||
|
||||
manufacturer manufacturers[] = {
|
||||
|
||||
/*
|
||||
* macaddr is a pass-by-reference datatype.
|
||||
*/
|
||||
#define PG_GETARG_MACADDR_P(n) ((macaddr *) PG_GETARG_POINTER(n))
|
||||
#define PG_RETURN_MACADDR_P(x) return PointerGetDatum(x)
|
||||
|
||||
|
||||
typedef struct manufacturer
|
||||
{
|
||||
unsigned char a;
|
||||
unsigned char b;
|
||||
unsigned char c;
|
||||
char *name;
|
||||
} manufacturer;
|
||||
|
||||
static manufacturer manufacturers[] = {
|
||||
{0x00, 0x00, 0x0C, "Cisco"},
|
||||
{0x00, 0x00, 0x0E, "Fujitsu"},
|
||||
{0x00, 0x00, 0x0F, "NeXT"},
|
||||
@@ -290,19 +306,17 @@ macaddr_cmp(macaddr *a1, macaddr *a2)
|
||||
}
|
||||
|
||||
/*
|
||||
* The special manufacturer fetching function. See "mac.h".
|
||||
* The special manufacturer fetching function.
|
||||
*/
|
||||
|
||||
text *
|
||||
macaddr_manuf(macaddr *addr)
|
||||
Datum
|
||||
macaddr_manuf(PG_FUNCTION_ARGS)
|
||||
{
|
||||
macaddr *addr = PG_GETARG_MACADDR_P(0);
|
||||
manufacturer *manuf;
|
||||
int length;
|
||||
text *result;
|
||||
|
||||
if (!PointerIsValid(addr))
|
||||
return NULL;
|
||||
|
||||
for (manuf = manufacturers; manuf->name != NULL; manuf++)
|
||||
{
|
||||
if ((manuf->a == addr->a) &&
|
||||
@@ -312,17 +326,16 @@ macaddr_manuf(macaddr *addr)
|
||||
}
|
||||
if (manuf->name == NULL)
|
||||
{
|
||||
result = palloc(VARHDRSZ + 1);
|
||||
memset(result, 0, VARHDRSZ + 1);
|
||||
VARATT_SIZEP(result) = VARHDRSZ + 1;
|
||||
/* Not known, so return empty string */
|
||||
result = palloc(VARHDRSZ);
|
||||
VARATT_SIZEP(result) = VARHDRSZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = strlen(manuf->name) + 1;
|
||||
length = strlen(manuf->name);
|
||||
result = palloc(length + VARHDRSZ);
|
||||
memset(result, 0, length + VARHDRSZ);
|
||||
VARATT_SIZEP(result) = length + VARHDRSZ;
|
||||
memcpy(VARDATA(result), manuf->name, length);
|
||||
}
|
||||
return result;
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
@@ -3,21 +3,29 @@
|
||||
* is for IP V4 CIDR notation, but prepared for V6: just
|
||||
* add the necessary bits where the comments indicate.
|
||||
*
|
||||
* $Id: network.c,v 1.22 2000/07/03 23:09:52 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/network.c,v 1.23 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
* Jon Postel RIP 16 Oct 1998
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include "postgres.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "postgres.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
/*
|
||||
* inet is a pass-by-reference datatype. It's not toastable, and we
|
||||
* don't try to hide the pass-by-refness, so these macros are simple.
|
||||
*/
|
||||
#define PG_GETARG_INET_P(n) ((inet *) PG_GETARG_POINTER(n))
|
||||
#define PG_RETURN_INET_P(x) return PointerGetDatum(x)
|
||||
|
||||
|
||||
static int v4bitncmp(unsigned int a1, unsigned int a2, int bits);
|
||||
|
||||
/*
|
||||
@@ -315,17 +323,15 @@ network_cmp(inet *a1, inet *a2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
text *
|
||||
network_host(inet *ip)
|
||||
Datum
|
||||
network_host(PG_FUNCTION_ARGS)
|
||||
{
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
text *ret;
|
||||
int len;
|
||||
char *ptr,
|
||||
tmp[sizeof("255.255.255.255/32")];
|
||||
|
||||
if (!PointerIsValid(ip))
|
||||
return NULL;
|
||||
|
||||
if (ip_type(ip))
|
||||
elog(ERROR, "CIDR type has no host part");
|
||||
|
||||
@@ -339,16 +345,16 @@ network_host(inet *ip)
|
||||
/* Go for an IPV6 address here, before faulting out: */
|
||||
elog(ERROR, "unknown address family (%d)", ip_family(ip));
|
||||
|
||||
/* Suppress /n if present */
|
||||
if ((ptr = strchr(tmp, '/')) != NULL)
|
||||
*ptr = 0;
|
||||
len = VARHDRSZ + strlen(tmp) + 1;
|
||||
ret = palloc(len);
|
||||
if (ret == NULL)
|
||||
elog(ERROR, "unable to allocate memory in network_host()");
|
||||
*ptr = '\0';
|
||||
|
||||
VARATT_SIZEP(ret) = len;
|
||||
strcpy(VARDATA(ret), tmp);
|
||||
return (ret);
|
||||
/* Return string as a text datum */
|
||||
len = strlen(tmp);
|
||||
ret = (text *) palloc(len + VARHDRSZ);
|
||||
VARATT_SIZEP(ret) = len + VARHDRSZ;
|
||||
memcpy(VARDATA(ret), tmp, len);
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
int4
|
||||
@@ -360,17 +366,15 @@ network_masklen(inet *ip)
|
||||
return ip_bits(ip);
|
||||
}
|
||||
|
||||
text *
|
||||
network_broadcast(inet *ip)
|
||||
Datum
|
||||
network_broadcast(PG_FUNCTION_ARGS)
|
||||
{
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
text *ret;
|
||||
int len;
|
||||
char *ptr,
|
||||
tmp[sizeof("255.255.255.255/32")];
|
||||
|
||||
if (!PointerIsValid(ip))
|
||||
return NULL;
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
/* It's an IP V4 address: */
|
||||
@@ -383,34 +387,31 @@ network_broadcast(inet *ip)
|
||||
|
||||
if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) == NULL)
|
||||
elog(ERROR, "unable to print address (%s)", strerror(errno));
|
||||
|
||||
}
|
||||
else
|
||||
/* Go for an IPV6 address here, before faulting out: */
|
||||
elog(ERROR, "unknown address family (%d)", ip_family(ip));
|
||||
|
||||
/* Suppress /n if present */
|
||||
if ((ptr = strchr(tmp, '/')) != NULL)
|
||||
*ptr = 0;
|
||||
len = VARHDRSZ + strlen(tmp) + 1;
|
||||
ret = palloc(len);
|
||||
if (ret == NULL)
|
||||
elog(ERROR, "unable to allocate memory in network_broadcast()");
|
||||
*ptr = '\0';
|
||||
|
||||
VARATT_SIZEP(ret) = len;
|
||||
strcpy(VARDATA(ret), tmp);
|
||||
return (ret);
|
||||
/* Return string as a text datum */
|
||||
len = strlen(tmp);
|
||||
ret = (text *) palloc(len + VARHDRSZ);
|
||||
VARATT_SIZEP(ret) = len + VARHDRSZ;
|
||||
memcpy(VARDATA(ret), tmp, len);
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
text *
|
||||
network_network(inet *ip)
|
||||
Datum
|
||||
network_network(PG_FUNCTION_ARGS)
|
||||
{
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
text *ret;
|
||||
int len;
|
||||
char tmp[sizeof("255.255.255.255/32")];
|
||||
|
||||
if (!PointerIsValid(ip))
|
||||
return NULL;
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
/* It's an IP V4 address: */
|
||||
@@ -418,33 +419,28 @@ network_network(inet *ip)
|
||||
|
||||
if (inet_cidr_ntop(AF_INET, &addr, ip_bits(ip), tmp, sizeof(tmp)) == NULL)
|
||||
elog(ERROR, "unable to print network (%s)", strerror(errno));
|
||||
|
||||
}
|
||||
else
|
||||
/* Go for an IPV6 address here, before faulting out: */
|
||||
elog(ERROR, "unknown address family (%d)", ip_family(ip));
|
||||
|
||||
len = VARHDRSZ + strlen(tmp) + 1;
|
||||
ret = palloc(len);
|
||||
if (ret == NULL)
|
||||
elog(ERROR, "unable to allocate memory in network_network()");
|
||||
|
||||
VARATT_SIZEP(ret) = len;
|
||||
strcpy(VARDATA(ret), tmp);
|
||||
return (ret);
|
||||
/* Return string as a text datum */
|
||||
len = strlen(tmp);
|
||||
ret = (text *) palloc(len + VARHDRSZ);
|
||||
VARATT_SIZEP(ret) = len + VARHDRSZ;
|
||||
memcpy(VARDATA(ret), tmp, len);
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
text *
|
||||
network_netmask(inet *ip)
|
||||
Datum
|
||||
network_netmask(PG_FUNCTION_ARGS)
|
||||
{
|
||||
inet *ip = PG_GETARG_INET_P(0);
|
||||
text *ret;
|
||||
int len;
|
||||
char *ptr,
|
||||
tmp[sizeof("255.255.255.255/32")];
|
||||
|
||||
if (!PointerIsValid(ip))
|
||||
return NULL;
|
||||
|
||||
if (ip_family(ip) == AF_INET)
|
||||
{
|
||||
/* It's an IP V4 address: */
|
||||
@@ -453,22 +449,21 @@ network_netmask(inet *ip)
|
||||
|
||||
if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) == NULL)
|
||||
elog(ERROR, "unable to print netmask (%s)", strerror(errno));
|
||||
|
||||
}
|
||||
else
|
||||
/* Go for an IPV6 address here, before faulting out: */
|
||||
elog(ERROR, "unknown address family (%d)", ip_family(ip));
|
||||
|
||||
/* Suppress /n if present */
|
||||
if ((ptr = strchr(tmp, '/')) != NULL)
|
||||
*ptr = 0;
|
||||
len = VARHDRSZ + strlen(tmp) + 1;
|
||||
ret = palloc(len);
|
||||
if (ret == NULL)
|
||||
elog(ERROR, "unable to allocate memory in network_netmask()");
|
||||
*ptr = '\0';
|
||||
|
||||
VARATT_SIZEP(ret) = len;
|
||||
strcpy(VARDATA(ret), tmp);
|
||||
return (ret);
|
||||
/* Return string as a text datum */
|
||||
len = strlen(tmp);
|
||||
ret = (text *) palloc(len + VARHDRSZ);
|
||||
VARATT_SIZEP(ret) = len + VARHDRSZ;
|
||||
memcpy(VARDATA(ret), tmp, len);
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/*
|
||||
* Edmund Mergl <E.Mergl@bawue.de>
|
||||
*
|
||||
* $Id: oracle_compat.c,v 1.26 2000/07/03 23:09:52 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.27 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
||||
@@ -17,7 +18,7 @@
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *lower(text *string)
|
||||
* text lower(text string)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -25,27 +26,24 @@
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
lower(text *string)
|
||||
Datum
|
||||
lower(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*ptr_ret;
|
||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||
char *ptr;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) || ((m = VARSIZE(string) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
|
||||
ret = (text *) palloc(VARSIZE(string));
|
||||
VARATT_SIZEP(ret) = VARSIZE(string);
|
||||
|
||||
/* Since we copied the string, we can scribble directly on the value */
|
||||
ptr = VARDATA(string);
|
||||
ptr_ret = VARDATA(ret);
|
||||
m = VARSIZE(string) - VARHDRSZ;
|
||||
|
||||
while (m--)
|
||||
*ptr_ret++ = tolower((unsigned char) *ptr++);
|
||||
while (m-- > 0)
|
||||
{
|
||||
*ptr = tolower((unsigned char) *ptr);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
PG_RETURN_TEXT_P(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +53,7 @@ lower(text *string)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *upper(text *string)
|
||||
* text upper(text string)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -63,27 +61,24 @@ lower(text *string)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
upper(text *string)
|
||||
Datum
|
||||
upper(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*ptr_ret;
|
||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||
char *ptr;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) || ((m = VARSIZE(string) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
|
||||
ret = (text *) palloc(VARSIZE(string));
|
||||
VARATT_SIZEP(ret) = VARSIZE(string);
|
||||
|
||||
/* Since we copied the string, we can scribble directly on the value */
|
||||
ptr = VARDATA(string);
|
||||
ptr_ret = VARDATA(ret);
|
||||
m = VARSIZE(string) - VARHDRSZ;
|
||||
|
||||
while (m--)
|
||||
*ptr_ret++ = toupper((unsigned char) *ptr++);
|
||||
while (m-- > 0)
|
||||
{
|
||||
*ptr = toupper((unsigned char) *ptr);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
PG_RETURN_TEXT_P(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +88,7 @@ upper(text *string)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *initcap(text *string)
|
||||
* text initcap(text string)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -103,35 +98,34 @@ upper(text *string)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
initcap(text *string)
|
||||
Datum
|
||||
initcap(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*ptr_ret;
|
||||
text *string = PG_GETARG_TEXT_P_COPY(0);
|
||||
char *ptr;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) || ((m = VARSIZE(string) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
|
||||
ret = (text *) palloc(VARSIZE(string));
|
||||
VARATT_SIZEP(ret) = VARSIZE(string);
|
||||
|
||||
/* Since we copied the string, we can scribble directly on the value */
|
||||
ptr = VARDATA(string);
|
||||
ptr_ret = VARDATA(ret);
|
||||
m = VARSIZE(string) - VARHDRSZ;
|
||||
|
||||
*ptr_ret++ = toupper((unsigned char) *ptr++);
|
||||
--m;
|
||||
|
||||
while (m--)
|
||||
if (m > 0)
|
||||
{
|
||||
if (*(ptr_ret - 1) == ' ' || *(ptr_ret - 1) == ' ')
|
||||
*ptr_ret++ = toupper((unsigned char) *ptr++);
|
||||
else
|
||||
*ptr_ret++ = tolower((unsigned char) *ptr++);
|
||||
*ptr = toupper((unsigned char) *ptr);
|
||||
ptr++;
|
||||
m--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
while (m-- > 0)
|
||||
{
|
||||
if (isspace(ptr[-1]))
|
||||
*ptr = toupper((unsigned char) *ptr);
|
||||
else
|
||||
*ptr = tolower((unsigned char) *ptr);
|
||||
ptr++;
|
||||
}
|
||||
|
||||
PG_RETURN_TEXT_P(string);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +135,7 @@ initcap(text *string)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *lpad(text *string1, int4 len, text *string2)
|
||||
* text lpad(text string1, int4 len, text string2)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -196,7 +190,7 @@ lpad(PG_FUNCTION_ARGS)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *rpad(text *string1, int4 len, text *string2)
|
||||
* text rpad(text string1, int4 len, text string2)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -251,7 +245,7 @@ rpad(PG_FUNCTION_ARGS)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *btrim(text *string, text *set)
|
||||
* text btrim(text string, text set)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -260,9 +254,11 @@ rpad(PG_FUNCTION_ARGS)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
btrim(text *string, text *set)
|
||||
Datum
|
||||
btrim(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
text *set = PG_GETARG_TEXT_P(1);
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*end,
|
||||
@@ -270,18 +266,17 @@ btrim(text *string, text *set)
|
||||
*end2;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) ||
|
||||
((m = VARSIZE(string) - VARHDRSZ) <= 0) ||
|
||||
(set == (text *) NULL) ||
|
||||
((VARSIZE(set) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
if ((m = VARSIZE(string) - VARHDRSZ) <= 0 ||
|
||||
(VARSIZE(set) - VARHDRSZ) <= 0)
|
||||
PG_RETURN_TEXT_P(string);
|
||||
|
||||
ptr = VARDATA(string);
|
||||
ptr2 = VARDATA(set);
|
||||
end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
||||
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
|
||||
|
||||
while (m--)
|
||||
while (m > 0)
|
||||
{
|
||||
ptr2 = VARDATA(set);
|
||||
while (ptr2 <= end2)
|
||||
{
|
||||
if (*ptr == *ptr2)
|
||||
@@ -291,16 +286,12 @@ btrim(text *string, text *set)
|
||||
if (ptr2 > end2)
|
||||
break;
|
||||
ptr++;
|
||||
ptr2 = VARDATA(set);
|
||||
m--;
|
||||
}
|
||||
|
||||
++m;
|
||||
|
||||
end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
||||
ptr2 = VARDATA(set);
|
||||
|
||||
while (m--)
|
||||
while (m > 0)
|
||||
{
|
||||
ptr2 = VARDATA(set);
|
||||
while (ptr2 <= end2)
|
||||
{
|
||||
if (*end == *ptr2)
|
||||
@@ -309,18 +300,16 @@ btrim(text *string, text *set)
|
||||
}
|
||||
if (ptr2 > end2)
|
||||
break;
|
||||
--end;
|
||||
ptr2 = VARDATA(set);
|
||||
end--;
|
||||
m--;
|
||||
}
|
||||
|
||||
++m;
|
||||
|
||||
ret = (text *) palloc(VARHDRSZ + m);
|
||||
VARATT_SIZEP(ret) = VARHDRSZ + m;
|
||||
memcpy(VARDATA(ret), ptr, m);
|
||||
|
||||
return ret;
|
||||
} /* btrim() */
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
@@ -329,7 +318,7 @@ btrim(text *string, text *set)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *ltrim(text *string, text *set)
|
||||
* text ltrim(text string, text set)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -338,27 +327,27 @@ btrim(text *string, text *set)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
ltrim(text *string, text *set)
|
||||
Datum
|
||||
ltrim(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
text *set = PG_GETARG_TEXT_P(1);
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*ptr2,
|
||||
*end2;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) ||
|
||||
((m = VARSIZE(string) - VARHDRSZ) <= 0) ||
|
||||
(set == (text *) NULL) ||
|
||||
((VARSIZE(set) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
if ((m = VARSIZE(string) - VARHDRSZ) <= 0 ||
|
||||
(VARSIZE(set) - VARHDRSZ) <= 0)
|
||||
PG_RETURN_TEXT_P(string);
|
||||
|
||||
ptr = VARDATA(string);
|
||||
ptr2 = VARDATA(set);
|
||||
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
|
||||
|
||||
while (m--)
|
||||
while (m > 0)
|
||||
{
|
||||
ptr2 = VARDATA(set);
|
||||
while (ptr2 <= end2)
|
||||
{
|
||||
if (*ptr == *ptr2)
|
||||
@@ -368,17 +357,14 @@ ltrim(text *string, text *set)
|
||||
if (ptr2 > end2)
|
||||
break;
|
||||
ptr++;
|
||||
ptr2 = VARDATA(set);
|
||||
m--;
|
||||
}
|
||||
|
||||
++m;
|
||||
|
||||
ret = (text *) palloc(VARHDRSZ + m);
|
||||
VARATT_SIZEP(ret) = VARHDRSZ + m;
|
||||
|
||||
memcpy(VARDATA(ret), ptr, m);
|
||||
|
||||
return ret;
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -388,7 +374,7 @@ ltrim(text *string, text *set)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *rtrim(text *string, text *set)
|
||||
* text rtrim(text string, text set)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -397,54 +383,46 @@ ltrim(text *string, text *set)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
rtrim(text *string, text *set)
|
||||
Datum
|
||||
rtrim(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
text *set = PG_GETARG_TEXT_P(1);
|
||||
text *ret;
|
||||
char *ptr,
|
||||
*end,
|
||||
*ptr2,
|
||||
*end2,
|
||||
*ptr_ret;
|
||||
*end2;
|
||||
int m;
|
||||
|
||||
if ((string == (text *) NULL) ||
|
||||
((m = VARSIZE(string) - VARHDRSZ) <= 0) ||
|
||||
(set == (text *) NULL) ||
|
||||
((VARSIZE(set) - VARHDRSZ) <= 0))
|
||||
return string;
|
||||
if ((m = VARSIZE(string) - VARHDRSZ) <= 0 ||
|
||||
(VARSIZE(set) - VARHDRSZ) <= 0)
|
||||
PG_RETURN_TEXT_P(string);
|
||||
|
||||
ptr = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
||||
ptr2 = VARDATA(set);
|
||||
ptr = VARDATA(string);
|
||||
end = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
||||
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
|
||||
|
||||
while (m--)
|
||||
while (m > 0)
|
||||
{
|
||||
ptr2 = VARDATA(set);
|
||||
while (ptr2 <= end2)
|
||||
{
|
||||
if (*ptr == *ptr2)
|
||||
if (*end == *ptr2)
|
||||
break;
|
||||
++ptr2;
|
||||
}
|
||||
if (ptr2 > end2)
|
||||
break;
|
||||
--ptr;
|
||||
ptr2 = VARDATA(set);
|
||||
end--;
|
||||
m--;
|
||||
}
|
||||
|
||||
++m;
|
||||
|
||||
ret = (text *) palloc(VARHDRSZ + m);
|
||||
VARATT_SIZEP(ret) = VARHDRSZ + m;
|
||||
#ifdef NOT_USED
|
||||
memcpy(VARDATA(ret), ptr - VARSIZE(ret) + m, m);
|
||||
#endif
|
||||
memcpy(VARDATA(ret), ptr, m);
|
||||
|
||||
ptr_ret = VARDATA(ret) + m - 1;
|
||||
|
||||
while (m--)
|
||||
*ptr_ret-- = *ptr--;
|
||||
|
||||
return ret;
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -454,7 +432,7 @@ rtrim(text *string, text *set)
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* text *translate(text *string, text *from, text *to)
|
||||
* text translate(text string, text from, text to)
|
||||
*
|
||||
* Purpose:
|
||||
*
|
||||
@@ -465,9 +443,12 @@ rtrim(text *string, text *set)
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
text *
|
||||
translate(text *string, text *from, text *to)
|
||||
Datum
|
||||
translate(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
text *from = PG_GETARG_TEXT_P(1);
|
||||
text *to = PG_GETARG_TEXT_P(2);
|
||||
text *result;
|
||||
char *from_ptr,
|
||||
*to_ptr;
|
||||
@@ -479,13 +460,8 @@ translate(text *string, text *from, text *to)
|
||||
retlen,
|
||||
i;
|
||||
|
||||
if (string == (text *) NULL ||
|
||||
from == (text *) NULL ||
|
||||
to == (text *) NULL)
|
||||
return (text *) NULL;
|
||||
|
||||
if ((m = VARSIZE(string) - VARHDRSZ) <= 0)
|
||||
return string;
|
||||
PG_RETURN_TEXT_P(string);
|
||||
|
||||
fromlen = VARSIZE(from) - VARHDRSZ;
|
||||
from_ptr = VARDATA(from);
|
||||
@@ -536,21 +512,20 @@ translate(text *string, text *from, text *to)
|
||||
* won't live long anyway.
|
||||
*/
|
||||
|
||||
return result;
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
|
||||
int4
|
||||
ascii(text *string)
|
||||
Datum
|
||||
ascii(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!PointerIsValid(string))
|
||||
return 0;
|
||||
text *string = PG_GETARG_TEXT_P(0);
|
||||
|
||||
if (VARSIZE(string) <= VARHDRSZ)
|
||||
return 0;
|
||||
PG_RETURN_INT32(0);
|
||||
|
||||
return ((int) *(VARDATA(string)));
|
||||
} /* ascii() */
|
||||
PG_RETURN_INT32((int32) *((unsigned char *) VARDATA(string)));
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.31 2000/07/05 23:11:35 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.32 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
* Alistair Crooks added the code for the regex caching
|
||||
* agc - cached the regular expressions used - there's a good chance
|
||||
@@ -25,12 +25,10 @@
|
||||
* instead of `oldest' when compiling regular expressions - benign
|
||||
* results mostly, although occasionally it bit you...
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
|
||||
#include "regex/regex.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
@@ -46,7 +44,6 @@
|
||||
/* this structure describes a cached regular expression */
|
||||
struct cached_re_str
|
||||
{
|
||||
struct varlena *cre_text; /* pattern as a text* */
|
||||
char *cre_s; /* pattern as null-terminated string */
|
||||
int cre_type; /* compiled-type: extended,icase etc */
|
||||
regex_t cre_re; /* the compiled regular expression */
|
||||
@@ -59,38 +56,35 @@ static unsigned long lru; /* system lru tag */
|
||||
|
||||
/* attempt to compile `re' as an re, then match it against text */
|
||||
/* cflags - flag to regcomp indicates case sensitivity */
|
||||
static int
|
||||
RE_compile_and_execute(struct varlena * text_re, char *text, int cflags)
|
||||
static bool
|
||||
RE_compile_and_execute(text *text_re, char *text, int cflags)
|
||||
{
|
||||
int oldest;
|
||||
int n;
|
||||
int i;
|
||||
char *re;
|
||||
int oldest;
|
||||
int i;
|
||||
int regcomp_result;
|
||||
|
||||
/* Convert 'text' pattern to null-terminated string */
|
||||
re = DatumGetCString(DirectFunctionCall1(textout,
|
||||
PointerGetDatum(text_re)));
|
||||
|
||||
/* find a previously compiled regular expression */
|
||||
for (i = 0; i < rec; i++)
|
||||
{
|
||||
if (rev[i].cre_s)
|
||||
{
|
||||
if (strcmp(rev[i].cre_s, re) == 0)
|
||||
if (strcmp(rev[i].cre_s, re) == 0 &&
|
||||
rev[i].cre_type == cflags)
|
||||
{
|
||||
if (rev[i].cre_type == cflags)
|
||||
{
|
||||
rev[i].cre_lru = ++lru;
|
||||
pfree(re);
|
||||
return (pg95_regexec(&rev[i].cre_re,
|
||||
text, 0,
|
||||
(regmatch_t *) NULL, 0) == 0);
|
||||
}
|
||||
rev[i].cre_lru = ++lru;
|
||||
pfree(re);
|
||||
return (pg95_regexec(&rev[i].cre_re,
|
||||
text, 0,
|
||||
(regmatch_t *) NULL, 0) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* we didn't find it - make room in the cache for it */
|
||||
if (rec == MAX_CACHED_RES)
|
||||
{
|
||||
@@ -120,22 +114,18 @@ RE_compile_and_execute(struct varlena * text_re, char *text, int cflags)
|
||||
* persist across transactions
|
||||
*/
|
||||
free(rev[oldest].cre_s);
|
||||
rev[oldest].cre_s = (char *) NULL;
|
||||
}
|
||||
|
||||
/* compile the re */
|
||||
regcomp_result = pg95_regcomp(&rev[oldest].cre_re, re, cflags);
|
||||
if (regcomp_result == 0)
|
||||
{
|
||||
n = strlen(re);
|
||||
|
||||
/*
|
||||
* use malloc/free for the cre_s field because the storage has to
|
||||
* persist across transactions
|
||||
*/
|
||||
rev[oldest].cre_s = (char *) malloc(n + 1);
|
||||
memmove(rev[oldest].cre_s, re, n);
|
||||
rev[oldest].cre_s[n] = 0;
|
||||
rev[oldest].cre_text = text_re;
|
||||
rev[oldest].cre_s = strdup(re);
|
||||
rev[oldest].cre_lru = ++lru;
|
||||
rev[oldest].cre_type = cflags;
|
||||
pfree(re);
|
||||
@@ -148,38 +138,29 @@ RE_compile_and_execute(struct varlena * text_re, char *text, int cflags)
|
||||
char errMsg[1000];
|
||||
|
||||
/* re didn't compile */
|
||||
rev[oldest].cre_s = (char *) NULL;
|
||||
pg95_regerror(regcomp_result, &rev[oldest].cre_re, errMsg,
|
||||
sizeof(errMsg));
|
||||
elog(ERROR, "regcomp failed with error %s", errMsg);
|
||||
}
|
||||
|
||||
/* not reached */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* interface routines called by the function manager
|
||||
*/
|
||||
|
||||
/*
|
||||
fixedlen_regexeq:
|
||||
|
||||
a generic fixed length regexp routine
|
||||
s - the string to match against (not necessarily null-terminated)
|
||||
p - the pattern
|
||||
p - the pattern (as a text*)
|
||||
charlen - the length of the string
|
||||
*/
|
||||
static bool
|
||||
fixedlen_regexeq(char *s, struct varlena * p, int charlen, int cflags)
|
||||
fixedlen_regexeq(char *s, text *p, int charlen, int cflags)
|
||||
{
|
||||
char *sterm;
|
||||
int result;
|
||||
|
||||
if (!s || !p)
|
||||
return FALSE;
|
||||
bool result;
|
||||
|
||||
/* be sure sterm is null-terminated */
|
||||
sterm = (char *) palloc(charlen + 1);
|
||||
@@ -189,73 +170,113 @@ fixedlen_regexeq(char *s, struct varlena * p, int charlen, int cflags)
|
||||
|
||||
pfree(sterm);
|
||||
|
||||
return (bool) result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* routines that use the regexp stuff
|
||||
* interface routines called by the function manager
|
||||
*/
|
||||
bool
|
||||
nameregexeq(NameData *n, struct varlena * p)
|
||||
|
||||
Datum
|
||||
nameregexeq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!n)
|
||||
return FALSE;
|
||||
return fixedlen_regexeq(NameStr(*n), p, NAMEDATALEN, REG_EXTENDED);
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_regexeq(NameStr(*n),
|
||||
p,
|
||||
strlen(NameStr(*n)),
|
||||
REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
nameregexne(NameData *s, struct varlena * p)
|
||||
Datum
|
||||
nameregexne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !nameregexeq(s, p);
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n),
|
||||
p,
|
||||
strlen(NameStr(*n)),
|
||||
REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
textregexeq(struct varlena * s, struct varlena * p)
|
||||
Datum
|
||||
textregexeq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!s)
|
||||
return FALSE;
|
||||
return fixedlen_regexeq(VARDATA(s), p, VARSIZE(s) - VARHDRSZ, REG_EXTENDED);
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_regexeq(VARDATA(s),
|
||||
p,
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
textregexne(struct varlena * s, struct varlena * p)
|
||||
Datum
|
||||
textregexne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !textregexeq(s, p);
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s),
|
||||
p,
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_EXTENDED));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* routines that use the regexp stuff, but ignore the case.
|
||||
* routines that use the regexp stuff, but ignore the case.
|
||||
* for this, we use the REG_ICASE flag to pg95_regcomp
|
||||
*/
|
||||
bool
|
||||
texticregexeq(struct varlena * s, struct varlena * p)
|
||||
|
||||
|
||||
Datum
|
||||
texticregexeq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!s)
|
||||
return FALSE;
|
||||
return (fixedlen_regexeq(VARDATA(s), p, VARSIZE(s) - VARHDRSZ,
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_regexeq(VARDATA(s),
|
||||
p,
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
texticregexne(struct varlena * s, struct varlena * p)
|
||||
Datum
|
||||
texticregexne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !texticregexeq(s, p);
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_regexeq(VARDATA(s),
|
||||
p,
|
||||
VARSIZE(s) - VARHDRSZ,
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
nameicregexeq(NameData *n, struct varlena * p)
|
||||
Datum
|
||||
nameicregexeq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!n)
|
||||
return FALSE;
|
||||
return (fixedlen_regexeq(NameStr(*n), p, NAMEDATALEN,
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(fixedlen_regexeq(NameStr(*n),
|
||||
p,
|
||||
strlen(NameStr(*n)),
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
}
|
||||
|
||||
bool
|
||||
nameicregexne(NameData *s, struct varlena * p)
|
||||
Datum
|
||||
nameicregexne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return !nameicregexeq(s, p);
|
||||
Name n = PG_GETARG_NAME(0);
|
||||
text *p = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(! fixedlen_regexeq(NameStr(*n),
|
||||
p,
|
||||
strlen(NameStr(*n)),
|
||||
REG_ICASE | REG_EXTENDED));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* out of its tuple
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.55 2000/07/03 23:09:52 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.56 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||
*
|
||||
@@ -123,9 +123,10 @@ static bool check_if_rte_used_walker(Node *node,
|
||||
* to recreate the rule
|
||||
* ----------
|
||||
*/
|
||||
text *
|
||||
pg_get_ruledef(NameData *rname)
|
||||
Datum
|
||||
pg_get_ruledef(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Name rname = PG_GETARG_NAME(0);
|
||||
text *ruledef;
|
||||
Datum args[1];
|
||||
char nulls[2];
|
||||
@@ -180,10 +181,10 @@ pg_get_ruledef(NameData *rname)
|
||||
{
|
||||
if (SPI_finish() != SPI_OK_FINISH)
|
||||
elog(ERROR, "get_ruledef: SPI_finish() failed");
|
||||
ruledef = SPI_palloc(VARHDRSZ + 1);
|
||||
ruledef = palloc(VARHDRSZ + 1);
|
||||
VARATT_SIZEP(ruledef) = VARHDRSZ + 1;
|
||||
VARDATA(ruledef)[0] = '-';
|
||||
return ruledef;
|
||||
PG_RETURN_TEXT_P(ruledef);
|
||||
}
|
||||
|
||||
ruletup = SPI_tuptable->vals[0];
|
||||
@@ -212,7 +213,7 @@ pg_get_ruledef(NameData *rname)
|
||||
* Easy - isn't it?
|
||||
* ----------
|
||||
*/
|
||||
return ruledef;
|
||||
PG_RETURN_TEXT_P(ruledef);
|
||||
}
|
||||
|
||||
|
||||
@@ -221,9 +222,10 @@ pg_get_ruledef(NameData *rname)
|
||||
* only return the SELECT part of a view
|
||||
* ----------
|
||||
*/
|
||||
text *
|
||||
pg_get_viewdef(NameData *rname)
|
||||
Datum
|
||||
pg_get_viewdef(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Name rname = PG_GETARG_NAME(0);
|
||||
text *ruledef;
|
||||
Datum args[2];
|
||||
char nulls[3];
|
||||
@@ -311,7 +313,7 @@ pg_get_viewdef(NameData *rname)
|
||||
* Easy - isn't it?
|
||||
* ----------
|
||||
*/
|
||||
return ruledef;
|
||||
PG_RETURN_TEXT_P(ruledef);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.74 2000/07/05 23:11:35 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.75 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1820,7 +1820,8 @@ string_lessthan(const char *str1, const char *str2, Oid datatype)
|
||||
switch (datatype)
|
||||
{
|
||||
case TEXTOID:
|
||||
result = text_lt((text *) datum1, (text *) datum2);
|
||||
result = DatumGetBool(DirectFunctionCall2(text_lt,
|
||||
datum1, datum2));
|
||||
break;
|
||||
|
||||
case BPCHAROID:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.62 2000/07/05 23:11:35 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.63 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -196,21 +196,16 @@ textout(PG_FUNCTION_ARGS)
|
||||
* returns the logical length of a text*
|
||||
* (which is less than the VARSIZE of the text*)
|
||||
*/
|
||||
int32
|
||||
textlen(text *t)
|
||||
Datum
|
||||
textlen(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *t = PG_GETARG_TEXT_P(0);
|
||||
#ifdef MULTIBYTE
|
||||
unsigned char *s;
|
||||
int len,
|
||||
l,
|
||||
wl;
|
||||
|
||||
#endif
|
||||
|
||||
if (!PointerIsValid(t))
|
||||
return 0;
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
len = 0;
|
||||
s = VARDATA(t);
|
||||
l = VARSIZE(t) - VARHDRSZ;
|
||||
@@ -221,30 +216,35 @@ textlen(text *t)
|
||||
s += wl;
|
||||
len++;
|
||||
}
|
||||
return (len);
|
||||
PG_RETURN_INT32(len);
|
||||
#else
|
||||
return VARSIZE(t) - VARHDRSZ;
|
||||
PG_RETURN_INT32(VARSIZE(t) - VARHDRSZ);
|
||||
#endif
|
||||
|
||||
} /* textlen() */
|
||||
}
|
||||
|
||||
/*
|
||||
* textoctetlen -
|
||||
* returns the physical length of a text*
|
||||
* (which is less than the VARSIZE of the text*)
|
||||
*
|
||||
* XXX is it actually appropriate to return the compressed length
|
||||
* when the value is compressed? It's not at all clear to me that
|
||||
* this is what SQL92 has in mind ...
|
||||
*/
|
||||
int32
|
||||
textoctetlen(text *t)
|
||||
Datum
|
||||
textoctetlen(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (!PointerIsValid(t))
|
||||
return 0;
|
||||
struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0);
|
||||
|
||||
return VARSIZE(t) - VARHDRSZ;
|
||||
} /* textoctetlen() */
|
||||
if (!VARATT_IS_EXTERNAL(t))
|
||||
PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ);
|
||||
|
||||
PG_RETURN_INT32(t->va_content.va_external.va_extsize);
|
||||
}
|
||||
|
||||
/*
|
||||
* textcat -
|
||||
* takes two text* and returns a text* that is the concatentation of
|
||||
* takes two text* and returns a text* that is the concatenation of
|
||||
* the two.
|
||||
*
|
||||
* Rewritten by Sapa, sapa@hq.icb.chel.su. 8-Jul-96.
|
||||
@@ -252,32 +252,27 @@ textoctetlen(text *t)
|
||||
* Allocate space for output in all cases.
|
||||
* XXX - thomas 1997-07-10
|
||||
*/
|
||||
text *
|
||||
textcat(text *t1, text *t2)
|
||||
Datum
|
||||
textcat(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *t1 = PG_GETARG_TEXT_P(0);
|
||||
text *t2 = PG_GETARG_TEXT_P(1);
|
||||
int len1,
|
||||
len2,
|
||||
len;
|
||||
char *ptr;
|
||||
text *result;
|
||||
|
||||
if (!PointerIsValid(t1) || !PointerIsValid(t2))
|
||||
return NULL;
|
||||
char *ptr;
|
||||
|
||||
len1 = (VARSIZE(t1) - VARHDRSZ);
|
||||
if (len1 < 0)
|
||||
len1 = 0;
|
||||
while (len1 > 0 && VARDATA(t1)[len1 - 1] == '\0')
|
||||
len1--;
|
||||
|
||||
len2 = (VARSIZE(t2) - VARHDRSZ);
|
||||
if (len2 < 0)
|
||||
len2 = 0;
|
||||
while (len2 > 0 && VARDATA(t2)[len2 - 1] == '\0')
|
||||
len2--;
|
||||
|
||||
len = len1 + len2 + VARHDRSZ;
|
||||
result = palloc(len);
|
||||
result = (text *) palloc(len);
|
||||
|
||||
/* Set size of result string... */
|
||||
VARATT_SIZEP(result) = len;
|
||||
@@ -289,8 +284,8 @@ textcat(text *t1, text *t2)
|
||||
if (len2 > 0)
|
||||
memcpy(ptr + len1, VARDATA(t2), len2);
|
||||
|
||||
return result;
|
||||
} /* textcat() */
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* text_substr()
|
||||
@@ -383,9 +378,11 @@ text_substr(PG_FUNCTION_ARGS)
|
||||
* Added multi-byte support.
|
||||
* - Tatsuo Ishii 1998-4-21
|
||||
*/
|
||||
int32
|
||||
textpos(text *t1, text *t2)
|
||||
Datum
|
||||
textpos(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *t1 = PG_GETARG_TEXT_P(0);
|
||||
text *t2 = PG_GETARG_TEXT_P(1);
|
||||
int pos;
|
||||
int px,
|
||||
p;
|
||||
@@ -393,18 +390,13 @@ textpos(text *t1, text *t2)
|
||||
len2;
|
||||
pg_wchar *p1,
|
||||
*p2;
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
pg_wchar *ps1,
|
||||
*ps2;
|
||||
|
||||
#endif
|
||||
|
||||
if (!PointerIsValid(t1) || !PointerIsValid(t2))
|
||||
return 0;
|
||||
|
||||
if (VARSIZE(t2) <= 0)
|
||||
return 1;
|
||||
if (VARSIZE(t2) <= VARHDRSZ)
|
||||
PG_RETURN_INT32(1); /* result for empty pattern */
|
||||
|
||||
len1 = (VARSIZE(t1) - VARHDRSZ);
|
||||
len2 = (VARSIZE(t2) - VARHDRSZ);
|
||||
@@ -438,43 +430,51 @@ textpos(text *t1, text *t2)
|
||||
pfree(ps1);
|
||||
pfree(ps2);
|
||||
#endif
|
||||
return pos;
|
||||
} /* textpos() */
|
||||
PG_RETURN_INT32(pos);
|
||||
}
|
||||
|
||||
/*
|
||||
* texteq - returns 1 iff arguments are equal
|
||||
* textne - returns 1 iff arguments are not equal
|
||||
* texteq - returns true iff arguments are equal
|
||||
* textne - returns true iff arguments are not equal
|
||||
*/
|
||||
bool
|
||||
texteq(text *arg1, text *arg2)
|
||||
Datum
|
||||
texteq(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
int len;
|
||||
char *a1p,
|
||||
*a2p;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return (bool) NULL;
|
||||
if ((len = arg1->vl_len) != arg2->vl_len)
|
||||
return (bool) 0;
|
||||
a1p = arg1->vl_dat;
|
||||
a2p = arg2->vl_dat;
|
||||
if (VARSIZE(arg1) != VARSIZE(arg2))
|
||||
PG_RETURN_BOOL(false);
|
||||
|
||||
/*
|
||||
* Varlenas are stored as the total size (data + size variable)
|
||||
* followed by the data. Use VARHDRSZ instead of explicit sizeof() -
|
||||
* thomas 1997-07-10
|
||||
*/
|
||||
len -= VARHDRSZ;
|
||||
while (len-- != 0)
|
||||
if (*a1p++ != *a2p++)
|
||||
return (bool) 0;
|
||||
return (bool) 1;
|
||||
} /* texteq() */
|
||||
len = VARSIZE(arg1) - VARHDRSZ;
|
||||
|
||||
bool
|
||||
textne(text *arg1, text *arg2)
|
||||
a1p = VARDATA(arg1);
|
||||
a2p = VARDATA(arg2);
|
||||
|
||||
PG_RETURN_BOOL(memcmp(a1p, a2p, len) == 0);
|
||||
}
|
||||
|
||||
Datum
|
||||
textne(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return (bool) !texteq(arg1, arg2);
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
int len;
|
||||
char *a1p,
|
||||
*a2p;
|
||||
|
||||
if (VARSIZE(arg1) != VARSIZE(arg2))
|
||||
PG_RETURN_BOOL(true);
|
||||
|
||||
len = VARSIZE(arg1) - VARHDRSZ;
|
||||
|
||||
a1p = VARDATA(arg1);
|
||||
a2p = VARDATA(arg2);
|
||||
|
||||
PG_RETURN_BOOL(memcmp(a1p, a2p, len) != 0);
|
||||
}
|
||||
|
||||
/* varstr_cmp()
|
||||
@@ -515,7 +515,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
|
||||
#endif
|
||||
|
||||
return result;
|
||||
} /* varstr_cmp() */
|
||||
}
|
||||
|
||||
|
||||
/* text_cmp()
|
||||
@@ -534,9 +534,6 @@ text_cmp(text *arg1, text *arg2)
|
||||
int len1,
|
||||
len2;
|
||||
|
||||
if (arg1 == NULL || arg2 == NULL)
|
||||
return (bool) FALSE;
|
||||
|
||||
a1p = VARDATA(arg1);
|
||||
a2p = VARDATA(arg2);
|
||||
|
||||
@@ -544,68 +541,82 @@ text_cmp(text *arg1, text *arg2)
|
||||
len2 = VARSIZE(arg2) - VARHDRSZ;
|
||||
|
||||
return varstr_cmp(a1p, len1, a2p, len2);
|
||||
} /* text_cmp() */
|
||||
|
||||
/* text_lt()
|
||||
* Comparison function for text strings.
|
||||
*/
|
||||
bool
|
||||
text_lt(text *arg1, text *arg2)
|
||||
{
|
||||
return (bool) (text_cmp(arg1, arg2) < 0);
|
||||
} /* text_lt() */
|
||||
|
||||
/* text_le()
|
||||
* Comparison function for text strings.
|
||||
*/
|
||||
bool
|
||||
text_le(text *arg1, text *arg2)
|
||||
{
|
||||
return (bool) (text_cmp(arg1, arg2) <= 0);
|
||||
} /* text_le() */
|
||||
|
||||
bool
|
||||
text_gt(text *arg1, text *arg2)
|
||||
{
|
||||
return (bool) !text_le(arg1, arg2);
|
||||
}
|
||||
|
||||
bool
|
||||
text_ge(text *arg1, text *arg2)
|
||||
/*
|
||||
* Comparison functions for text strings.
|
||||
*/
|
||||
|
||||
Datum
|
||||
text_lt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return (bool) !text_lt(arg1, arg2);
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(text_cmp(arg1, arg2) < 0);
|
||||
}
|
||||
|
||||
text *
|
||||
text_larger(text *arg1, text *arg2)
|
||||
Datum
|
||||
text_le(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(text_cmp(arg1, arg2) <= 0);
|
||||
}
|
||||
|
||||
Datum
|
||||
text_gt(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(text_cmp(arg1, arg2) > 0);
|
||||
}
|
||||
|
||||
Datum
|
||||
text_ge(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
|
||||
PG_RETURN_BOOL(text_cmp(arg1, arg2) >= 0);
|
||||
}
|
||||
|
||||
Datum
|
||||
text_larger(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
text *result;
|
||||
text *temp;
|
||||
|
||||
temp = ((text_cmp(arg1, arg2) <= 0) ? arg2 : arg1);
|
||||
temp = ((text_cmp(arg1, arg2) > 0) ? arg1 : arg2);
|
||||
|
||||
/* Make a copy */
|
||||
/* Make a copy --- temporary hack until nodeAgg.c is smarter */
|
||||
|
||||
result = (text *) palloc(VARSIZE(temp));
|
||||
memmove((char *) result, (char *) temp, VARSIZE(temp));
|
||||
memcpy((char *) result, (char *) temp, VARSIZE(temp));
|
||||
|
||||
return (result);
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
text *
|
||||
text_smaller(text *arg1, text *arg2)
|
||||
Datum
|
||||
text_smaller(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *arg1 = PG_GETARG_TEXT_P(0);
|
||||
text *arg2 = PG_GETARG_TEXT_P(1);
|
||||
text *result;
|
||||
text *temp;
|
||||
|
||||
temp = ((text_cmp(arg1, arg2) > 0) ? arg2 : arg1);
|
||||
temp = ((text_cmp(arg1, arg2) < 0) ? arg1 : arg2);
|
||||
|
||||
/* Make a copy */
|
||||
/* Make a copy --- temporary hack until nodeAgg.c is smarter */
|
||||
|
||||
result = (text *) palloc(VARSIZE(temp));
|
||||
memmove((char *) result, (char *) temp, VARSIZE(temp));
|
||||
memcpy((char *) result, (char *) temp, VARSIZE(temp));
|
||||
|
||||
return (result);
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------
|
||||
@@ -780,28 +791,28 @@ byteaSetBit(PG_FUNCTION_ARGS)
|
||||
|
||||
|
||||
/* text_name()
|
||||
* Converts a text() type to a NameData type.
|
||||
* Converts a text type to a Name type.
|
||||
*/
|
||||
NameData *
|
||||
text_name(text *s)
|
||||
Datum
|
||||
text_name(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NameData *result;
|
||||
text *s = PG_GETARG_TEXT_P(0);
|
||||
Name result;
|
||||
int len;
|
||||
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
len = VARSIZE(s) - VARHDRSZ;
|
||||
if (len > NAMEDATALEN)
|
||||
len = NAMEDATALEN;
|
||||
|
||||
/* Truncate oversize input */
|
||||
if (len >= NAMEDATALEN)
|
||||
len = NAMEDATALEN-1;
|
||||
|
||||
#ifdef STRINGDEBUG
|
||||
printf("text- convert string length %d (%d) ->%d\n",
|
||||
VARSIZE(s) - VARHDRSZ, VARSIZE(s), len);
|
||||
#endif
|
||||
|
||||
result = palloc(NAMEDATALEN);
|
||||
StrNCpy(NameStr(*result), VARDATA(s), NAMEDATALEN);
|
||||
result = (Name) palloc(NAMEDATALEN);
|
||||
memcpy(NameStr(*result), VARDATA(s), len);
|
||||
|
||||
/* now null pad to full length... */
|
||||
while (len < NAMEDATALEN)
|
||||
@@ -810,21 +821,19 @@ text_name(text *s)
|
||||
len++;
|
||||
}
|
||||
|
||||
return result;
|
||||
} /* text_name() */
|
||||
PG_RETURN_NAME(result);
|
||||
}
|
||||
|
||||
/* name_text()
|
||||
* Converts a NameData type to a text type.
|
||||
* Converts a Name type to a text type.
|
||||
*/
|
||||
text *
|
||||
name_text(NameData *s)
|
||||
Datum
|
||||
name_text(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Name s = PG_GETARG_NAME(0);
|
||||
text *result;
|
||||
int len;
|
||||
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(NameStr(*s));
|
||||
|
||||
#ifdef STRINGDEBUG
|
||||
@@ -833,8 +842,8 @@ name_text(NameData *s)
|
||||
#endif
|
||||
|
||||
result = palloc(VARHDRSZ + len);
|
||||
strncpy(VARDATA(result), NameStr(*s), len);
|
||||
VARATT_SIZEP(result) = len + VARHDRSZ;
|
||||
VARATT_SIZEP(result) = VARHDRSZ + len;
|
||||
memcpy(VARDATA(result), NameStr(*s), len);
|
||||
|
||||
return result;
|
||||
} /* name_text() */
|
||||
PG_RETURN_TEXT_P(result);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* version.c
|
||||
* Returns the version string
|
||||
* Returns the PostgreSQL version string
|
||||
*
|
||||
* IDENTIFICATION
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.11 2000/07/03 23:09:54 wieck Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.12 2000/07/06 05:48:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/builtins.h"
|
||||
|
||||
text *version(void);
|
||||
|
||||
text *
|
||||
version(void)
|
||||
Datum
|
||||
pgsql_version(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int n = strlen(PG_VERSION_STR) + VARHDRSZ;
|
||||
text *ret = (text *) palloc(n);
|
||||
int n = strlen(PG_VERSION_STR);
|
||||
text *ret = (text *) palloc(n + VARHDRSZ);
|
||||
|
||||
VARATT_SIZEP(ret) = n;
|
||||
memcpy(VARDATA(ret), PG_VERSION_STR, strlen(PG_VERSION_STR));
|
||||
VARATT_SIZEP(ret) = n + VARHDRSZ;
|
||||
memcpy(VARDATA(ret), PG_VERSION_STR, n);
|
||||
|
||||
return ret;
|
||||
PG_RETURN_TEXT_P(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user