From 8f9fa0e14320c5e2f2d0514e5b6c404ec7b54016 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 30 Jul 2000 22:14:09 +0000 Subject: Type lztext is toast. (Sorry, couldn't help it...) Removed type filename as well, since it's unused and probably useless. INITDB FORCED, because pg_rewrite columns are now plain text again. --- src/backend/utils/adt/Makefile | 6 +- src/backend/utils/adt/filename.c | 132 -------------- src/backend/utils/adt/lztext.c | 359 ------------------------------------- src/backend/utils/cache/relcache.c | 10 +- 4 files changed, 10 insertions(+), 497 deletions(-) delete mode 100644 src/backend/utils/adt/filename.c delete mode 100644 src/backend/utils/adt/lztext.c (limited to 'src/backend/utils') diff --git a/src/backend/utils/adt/Makefile b/src/backend/utils/adt/Makefile index 0f42d93aad..00917cac8f 100644 --- a/src/backend/utils/adt/Makefile +++ b/src/backend/utils/adt/Makefile @@ -1,7 +1,7 @@ # # Makefile for utils/adt # -# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.40 2000/07/22 03:34:43 tgl Exp $ +# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.41 2000/07/30 22:13:52 tgl Exp $ # subdir = src/backend/utils/adt @@ -16,8 +16,8 @@ endif endif OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o \ - date.o datetime.o datum.o filename.o float.o format_type.o \ - geo_ops.o geo_selfuncs.o int.o int8.o like.o lztext.o \ + date.o datetime.o datum.o float.o format_type.o \ + geo_ops.o geo_selfuncs.o int.o int8.o like.o \ misc.o nabstime.o name.o not_in.o numeric.o numutils.o \ oid.o oracle_compat.o \ regexp.o regproc.o ruleutils.o selfuncs.o sets.o \ diff --git a/src/backend/utils/adt/filename.c b/src/backend/utils/adt/filename.c deleted file mode 100644 index 60034d5fd2..0000000000 --- a/src/backend/utils/adt/filename.c +++ /dev/null @@ -1,132 +0,0 @@ -/*------------------------------------------------------------------------- - * - * filename.c - * - * - * Portions Copyright (c) 1996-2000, PostgreSQL, Inc - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.24 2000/01/26 05:57:14 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include - -#include - -#include "postgres.h" -#include "miscadmin.h" -#include "utils/builtins.h" - -char * -filename_in(char *file) -{ - char *str; - int ind = 0; - - /* - * XXX - HACK CITY --- REDO should let the shell do expansions - * (shexpand) - */ - - str = (char *) palloc(MAXPGPATH); - str[0] = '\0'; - if (file[0] == '~') - { - if (file[1] == '\0' || file[1] == '/') - { - /* Home directory */ - - char *userName; - struct passwd *pw; - - userName = GetPgUserName(); - - if ((pw = getpwnam(userName)) == NULL) - { - elog(ERROR, "User %s is not a Unix user on the db server.", - userName); - } - - strcpy(str, pw->pw_dir); - - ind = 1; - } - else - { - /* Someone else's directory */ - char name[17], - *p; - struct passwd *pw; - int len; - - if ((p = (char *) strchr(file, '/')) == NULL) - { - strcpy(name, file + 1); - len = strlen(name); - } - else - { - len = (p - file) - 1; - StrNCpy(name, file + 1, len + 1); - } - /* printf("name: %s\n"); */ - if ((pw = getpwnam(name)) == NULL) - { - elog(ERROR, "No such user: %s\n", name); - ind = 0; - } - else - { - strcpy(str, pw->pw_dir); - ind = len + 1; - } - } - } - else if (file[0] == '$') - { /* $POSTGRESHOME, etc. expand it. */ - char environment[80], - *envirp, - *p; - int len; - - if ((p = (char *) strchr(file, '/')) == NULL) - { - strcpy(environment, file + 1); - len = strlen(environment); - } - else - { - len = (p - file) - 1; - StrNCpy(environment, file + 1, len + 1); - } - envirp = getenv(environment); - if (envirp) - { - strcpy(str, envirp); - ind = len + 1; - } - else - elog(ERROR, "Couldn't find %s in your environment", environment); - } - else - ind = 0; - strcat(str, file + ind); - return str; -} - -char * -filename_out(char *s) -{ - char *ret; - - if (!s) - return (char *) NULL; - ret = (char *) palloc(strlen(s) + 1); - if (!ret) - elog(ERROR, "filename_out: palloc failed"); - return strcpy(ret, s); -} diff --git a/src/backend/utils/adt/lztext.c b/src/backend/utils/adt/lztext.c deleted file mode 100644 index e1f80f63da..0000000000 --- a/src/backend/utils/adt/lztext.c +++ /dev/null @@ -1,359 +0,0 @@ -/* ---------- - * lztext.c - - * - * $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. - * - * This code requires that the LZ compressor found in pg_lzcompress - * codes a usable VARSIZE word at the beginning of the output buffer. - * ---------- - */ - -#include -#include -#include -#include -#include - -#include "postgres.h" -#include "utils/builtins.h" -#ifdef MULTIBYTE -#include "mb/pg_wchar.h" -#endif - -/* ---------- - * lztextin - - * - * Input function for datatype lztext - * ---------- - */ -lztext * -lztextin(char *str) -{ - lztext *result; - int32 rawsize; - - /* ---------- - * Handle NULL - * ---------- - */ - if (str == NULL) - return NULL; - - rawsize = strlen(str); - result = (lztext *)palloc(VARHDRSZ + rawsize); - - VARATT_SIZEP(result) = VARHDRSZ + rawsize; - memcpy(VARATT_DATA(result), str, rawsize); - - return result; -} - - -/* ---------- - * lztextout - - * - * Output function for data type lztext - * ---------- - */ -char * -lztextout(lztext *lz) -{ - char *result; - void *tmp; - int32 rawsize; - - /* ---------- - * Handle NULL - * ---------- - */ - if (lz == NULL) - { - result = (char *) palloc(2); - result[0] = '-'; - result[1] = '\0'; - return result; - } - - VARATT_GETPLAIN(lz, tmp); - - rawsize = VARATT_SIZE(tmp) - VARHDRSZ; - result = (char *)palloc(rawsize + 1); - memcpy(result, VARATT_DATA(tmp), rawsize); - result[rawsize] = '\0'; - - VARATT_FREE(lz, tmp); - - return result; -} - - -/* ---------- - * lztextlen - - * - * Logical length of lztext field (it's the uncompressed size - * of the original data). - * ---------- - */ -int32 -lztextlen(lztext *lz) -{ -#ifdef MULTIBYTE - unsigned char *s1, - *s2; - int len; - int l; - int wl; - -#endif - /* ---------- - * Handle NULL - * ---------- - */ - if (lz == NULL) - return 0; - -#ifdef MULTIBYTE - len = 0; - s1 = s2 = (unsigned char *) lztextout(lz); - l = strlen(s2); - while (l > 0) - { - wl = pg_mblen(s1); - l -= wl; - s1 += wl; - len++; - } - pfree((char *) s2); - return (len); -#else - /* ---------- - * without multibyte support, it's the remembered rawsize - * ---------- - */ - if (!VARATT_IS_EXTENDED(lz)) - return VARATT_SIZE(lz) - VARHDRSZ; - - if (VARATT_IS_EXTERNAL(lz)) - return lz->va_content.va_external.va_rawsize; - - return lz->va_content.va_compressed.va_rawsize; -#endif -} - - -/* ---------- - * lztextoctetlen - - * - * Physical length of lztext field (it's the compressed size - * plus the rawsize field). - * ---------- - */ -int32 -lztextoctetlen(lztext *lz) -{ - /* ---------- - * Handle NULL - * ---------- - */ - if (lz == NULL) - return 0; - - if (!VARATT_IS_EXTERNAL(lz)) - return VARATT_SIZE(lz) - VARHDRSZ; - - return lz->va_content.va_external.va_extsize; -} - - -/* ---------- - * text_lztext - - * - * Convert text to lztext - * ---------- - */ -Datum -text_lztext(PG_FUNCTION_ARGS) -{ - text *txt = PG_GETARG_TEXT_P(0); - lztext *result; - int32 rawsize; - - /* ---------- - * Copy the entire attribute - * ---------- - */ - rawsize = VARSIZE(txt) - VARHDRSZ; - result = (lztext *)palloc(rawsize + VARHDRSZ); - VARATT_SIZEP(result) = rawsize + VARHDRSZ; - memcpy(VARATT_DATA(result), VARATT_DATA(txt), rawsize); - - PG_RETURN_POINTER(result); -} - - -/* ---------- - * lztext_text - - * - * Convert lztext to text - * ---------- - */ -text * -lztext_text(lztext *lz) -{ - text *result; - lztext *tmp; - int32 rawsize; - - /* ---------- - * Handle NULL - * ---------- - */ - if (lz == NULL) - return NULL; - - VARATT_GETPLAIN(lz, tmp); - - rawsize = VARATT_SIZE(tmp) - VARHDRSZ; - result = (text *)palloc(rawsize + VARHDRSZ); - VARATT_SIZEP(result) = rawsize + VARHDRSZ; - memcpy(VARATT_DATA(result), VARATT_DATA(tmp), rawsize); - - VARATT_FREE(lz, tmp); - - return result; -} - - -/* ---------- - * lztext_cmp - - * - * Comparision function for two lztext datum's. - * - * Returns -1, 0 or 1. - * ---------- - */ -int32 -lztext_cmp(lztext *lz1, lztext *lz2) -{ -#ifdef USE_LOCALE - - char *cp1; - char *cp2; - int result; - - if (lz1 == NULL || lz2 == NULL) - return (int32) 0; - - cp1 = lztextout(lz1); - cp2 = lztextout(lz2); - - result = strcoll(cp1, cp2); - - pfree(cp1); - pfree(cp2); - - return result; - -#else /* !USE_LOCALE */ - - int result; - char *p1 = NULL; - char *p2 = NULL; - int size1; - int size2; - - if (lz1 == NULL || lz2 == NULL) - return 0; - - VARATT_GETPLAIN(lz1, p1); - VARATT_GETPLAIN(lz2, p2); - - size1 = VARATT_SIZE(p1) - VARHDRSZ; - size2 = VARATT_SIZE(p2) - VARHDRSZ; - result = memcmp(VARATT_DATA(p1), VARATT_DATA(p2), - (size1 < size2) ? size1 : size2); - if (result == 0) - { - if (size1 > size2) - result = 1; - else if (size1 < size2) - result = -1; - } - - VARATT_FREE(lz2, p2); - VARATT_FREE(lz1, p1); - - return result; - -#endif /* USE_LOCALE */ -} - - -/* ---------- - * lztext_eq ... - - * - * =, !=, >, >=, < and <= operator functions for two - * lztext datums. - * ---------- - */ -bool -lztext_eq(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) == 0); -} - - -bool -lztext_ne(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) != 0); -} - - -bool -lztext_gt(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) > 0); -} - - -bool -lztext_ge(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) >= 0); -} - - -bool -lztext_lt(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) < 0); -} - - -bool -lztext_le(lztext *lz1, lztext *lz2) -{ - if (lz1 == NULL || lz2 == NULL) - return false; - - return (bool) (lztext_cmp(lz1, lz2) <= 0); -} diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index a7cb0ecac4..84f20757d6 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.107 2000/07/14 22:17:50 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.108 2000/07/30 22:13:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -775,7 +775,9 @@ RelationBuildRuleLock(Relation relation) Anum_pg_rewrite_ev_action, pg_rewrite_tupdesc, &isnull); - ruleaction_str = lztextout((lztext *) DatumGetPointer(ruleaction)); + Assert(! isnull); + ruleaction_str = DatumGetCString(DirectFunctionCall1(textout, + ruleaction)); oldcxt = MemoryContextSwitchTo(CacheMemoryContext); rule->actions = (List *) stringToNode(ruleaction_str); MemoryContextSwitchTo(oldcxt); @@ -785,7 +787,9 @@ RelationBuildRuleLock(Relation relation) Anum_pg_rewrite_ev_qual, pg_rewrite_tupdesc, &isnull); - rule_evqual_str = lztextout((lztext *) DatumGetPointer(rule_evqual)); + Assert(! isnull); + rule_evqual_str = DatumGetCString(DirectFunctionCall1(textout, + rule_evqual)); oldcxt = MemoryContextSwitchTo(CacheMemoryContext); rule->qual = (Node *) stringToNode(rule_evqual_str); MemoryContextSwitchTo(oldcxt); -- cgit v1.2.1