diff options
author | Bruce Momjian <bruce@momjian.us> | 1998-09-01 04:40:42 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1998-09-01 04:40:42 +0000 |
commit | fa1a8d6a97068295fe30ac646aec7493a6305bc2 (patch) | |
tree | 645f7cef3c78fbab4d6d7bbc7c9a61ad2893d273 /src/backend/utils/adt | |
parent | af74855a608da4cd7ef88ceb2241ec1c75537f39 (diff) | |
download | postgresql-fa1a8d6a97068295fe30ac646aec7493a6305bc2.tar.gz postgresql-fa1a8d6a97068295fe30ac646aec7493a6305bc2.zip |
OK, folks, here is the pgindent output.
Diffstat (limited to 'src/backend/utils/adt')
25 files changed, 1594 insertions, 1489 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index db5ea074c81..15c590dc811 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.30 1998/09/01 03:25:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.31 1998/09/01 04:32:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -151,8 +151,8 @@ aclparse(char *s, AclItem *aip, unsigned *modechg) { case ACL_IDTYPE_UID: htup = SearchSysCacheTuple(USENAME, - PointerGetDatum(name), - 0, 0, 0); + PointerGetDatum(name), + 0, 0, 0); if (!HeapTupleIsValid(htup)) elog(ERROR, "aclparse: non-existent user \"%s\"", name); aip->ai_id = ((Form_pg_shadow) GETSTRUCT(htup))->usesysid; @@ -262,8 +262,8 @@ aclitemout(AclItem *aip) { case ACL_IDTYPE_UID: htup = SearchSysCacheTuple(USESYSID, - ObjectIdGetDatum(aip->ai_id), - 0, 0, 0); + ObjectIdGetDatum(aip->ai_id), + 0, 0, 0); if (!HeapTupleIsValid(htup)) { char *tmp = int2out(aip->ai_id); diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index cb604baa0ff..04a224feaeb 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.33 1998/09/01 03:25:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.34 1998/09/01 04:32:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,23 +43,19 @@ /*-=-=--=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-*/ static int _ArrayCount(char *str, int *dim, int typdelim); -static char * -_ReadArrayStr(char *arrayStr, int nitems, int ndim, int *dim, +static char *_ReadArrayStr(char *arrayStr, int nitems, int ndim, int *dim, FmgrInfo *inputproc, Oid typelem, int32 typmod, char typdelim, int typlen, bool typbyval, char typalign, int *nbytes); #ifdef LOARRAY -static char * -_ReadLOArray(char *str, int *nbytes, int *fd, bool *chunkFlag, +static char *_ReadLOArray(char *str, int *nbytes, int *fd, bool *chunkFlag, int ndim, int *dim, int baseSize); #endif -static void -_CopyArrayEls(char **values, char *p, int nitems, int typlen, +static void _CopyArrayEls(char **values, char *p, int nitems, int typlen, char typalign, bool typbyval); -static void -system_cache_lookup(Oid element_type, bool input, int *typlen, +static void system_cache_lookup(Oid element_type, bool input, int *typlen, bool *typbyval, char *typdelim, Oid *typelem, Oid *proc, char *typalign); static Datum _ArrayCast(char *value, bool byval, int len); @@ -68,18 +64,15 @@ static Datum _ArrayCast(char *value, bool byval, int len); static char *_AdvanceBy1word(char *str, char **word); #endif -static void -_ArrayRange(int *st, int *endp, int bsize, char *destPtr, +static void _ArrayRange(int *st, int *endp, int bsize, char *destPtr, ArrayType *array, int from); static int _ArrayClipCount(int *stI, int *endpI, ArrayType *array); -static void -_LOArrayRange(int *st, int *endp, int bsize, int srcfd, +static void _LOArrayRange(int *st, int *endp, int bsize, int srcfd, int destfd, ArrayType *array, int isSrcLO, bool *isNull); -static void -_ReadArray(int *st, int *endp, int bsize, int srcfd, int destfd, +static void _ReadArray(int *st, int *endp, int bsize, int srcfd, int destfd, ArrayType *array, int isDestLO, bool *isNull); -static int ArrayCastAndSet(char *src, bool typbyval, int typlen, char *dest); -static int SanityCheckInput(int ndim, int n, int *dim, int *lb, int *indx); +static int ArrayCastAndSet(char *src, bool typbyval, int typlen, char *dest); +static int SanityCheckInput(int ndim, int n, int *dim, int *lb, int *indx); static int array_read(char *destptr, int eltsize, int nitems, char *srcptr); static char *array_seek(char *ptr, int eltsize, int nitems); @@ -608,7 +601,8 @@ array_out(ArrayType *v, Oid element_type) FmgrInfo outputproc; char typalign; - char *p, *tmp, + char *p, + *tmp, *retval, **values, delim[2]; @@ -698,9 +692,11 @@ array_out(ArrayType *v, Oid element_type) */ overall_length += 2; } - for (tmp=values[i];*tmp;tmp++) { + for (tmp = values[i]; *tmp; tmp++) + { overall_length += 1; - if (*tmp=='"') overall_length += 1; + if (*tmp == '"') + overall_length += 1; } overall_length += 1; } @@ -729,12 +725,14 @@ array_out(ArrayType *v, Oid element_type) if (!typbyval) { strcat(p, "\""); - l=strlen(p); - for (tmp=values[k];*tmp;tmp++) { - if (*tmp=='"') p[l++]='\\'; - p[l++]=*tmp; - } - p[l]='\0'; + l = strlen(p); + for (tmp = values[k]; *tmp; tmp++) + { + if (*tmp == '"') + p[l++] = '\\'; + p[l++] = *tmp; + } + p[l] = '\0'; strcat(p, "\""); } else diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index dde1eb2f2c6..262d2d4deda 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -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.25 1998/09/01 03:25:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.26 1998/09/01 04:32:26 momjian Exp $ */ #include <stdio.h> @@ -34,6 +34,7 @@ static const char *num_word(Cash value); #ifdef USE_LOCALE static struct lconv *lconvert = NULL; + #endif /* cash_in() @@ -46,7 +47,7 @@ static struct lconv *lconvert = NULL; * monetary values returned by localeconv() can be multiple * bytes/characters. This code assumes one byte only. - tgl 97/04/14 * XXX UNHACK Allow the currency symbol to be multi-byte. - * - thomas 1998-03-01 + * - thomas 1998-03-01 */ Cash * cash_in(const char *str) @@ -77,11 +78,11 @@ cash_in(const char *str) /* best guess is 2 in this case I think */ fpoint = ((lconvert->frac_digits != CHAR_MAX) ? lconvert->frac_digits : 2); /* int_frac_digits? */ - dsymbol = ((*lconvert->mon_decimal_point != '\0')? *lconvert->mon_decimal_point: '.'); - ssymbol = ((*lconvert->mon_thousands_sep != '\0')? *lconvert->mon_thousands_sep: ','); - csymbol = ((*lconvert->currency_symbol != '\0')? lconvert->currency_symbol: "$"); - psymbol = ((*lconvert->positive_sign != '\0')? *lconvert->positive_sign: '+'); - nsymbol = ((*lconvert->negative_sign != '\0')? lconvert->negative_sign: "-"); + dsymbol = ((*lconvert->mon_decimal_point != '\0') ? *lconvert->mon_decimal_point : '.'); + ssymbol = ((*lconvert->mon_thousands_sep != '\0') ? *lconvert->mon_thousands_sep : ','); + csymbol = ((*lconvert->currency_symbol != '\0') ? lconvert->currency_symbol : "$"); + psymbol = ((*lconvert->positive_sign != '\0') ? *lconvert->positive_sign : '+'); + nsymbol = ((*lconvert->negative_sign != '\0') ? lconvert->negative_sign : "-"); #else fpoint = 2; dsymbol = '.'; @@ -92,27 +93,29 @@ cash_in(const char *str) #endif #ifdef CASHDEBUG -printf( "cashin- precision '%d'; decimal '%c'; thousands '%c'; currency '%s'; positive '%c'; negative '%s'\n", - fpoint, dsymbol, ssymbol, csymbol, psymbol, nsymbol); + printf("cashin- precision '%d'; decimal '%c'; thousands '%c'; currency '%s'; positive '%c'; negative '%s'\n", + fpoint, dsymbol, ssymbol, csymbol, psymbol, nsymbol); #endif /* we need to add all sorts of checking here. For now just */ /* strip all leading whitespace and any leading currency symbol */ - while (isspace(*s)) s++; - if (strncmp(s,csymbol,strlen(csymbol)) == 0) s += strlen(csymbol); + while (isspace(*s)) + s++; + if (strncmp(s, csymbol, strlen(csymbol)) == 0) + s += strlen(csymbol); #ifdef CASHDEBUG -printf( "cashin- string is '%s'\n", s); + printf("cashin- string is '%s'\n", s); #endif /* a leading minus or paren signifies a negative number */ /* again, better heuristics needed */ - if (strncmp(s,nsymbol,strlen(nsymbol)) == 0) + if (strncmp(s, nsymbol, strlen(nsymbol)) == 0) { sgn = -1; s += strlen(nsymbol); #ifdef CASHDEBUG -printf( "cashin- negative symbol; string is '%s'\n", s); + printf("cashin- negative symbol; string is '%s'\n", s); #endif } else if (*s == '(') @@ -125,14 +128,16 @@ printf( "cashin- negative symbol; string is '%s'\n", s); s++; #ifdef CASHDEBUG -printf( "cashin- string is '%s'\n", s); + printf("cashin- string is '%s'\n", s); #endif - while (isspace(*s)) s++; - if (strncmp(s,csymbol,strlen(csymbol)) == 0) s += strlen(csymbol); + while (isspace(*s)) + s++; + if (strncmp(s, csymbol, strlen(csymbol)) == 0) + s += strlen(csymbol); #ifdef CASHDEBUG -printf( "cashin- string is '%s'\n", s); + printf("cashin- string is '%s'\n", s); #endif for (;; s++) @@ -184,7 +189,7 @@ printf( "cashin- string is '%s'\n", s); *result = (value * sgn); #ifdef CASHDEBUG -printf( "cashin- result is %d\n", *result); + printf("cashin- result is %d\n", *result); #endif return result; @@ -219,14 +224,14 @@ cash_out(Cash *in_value) lconvert = localeconv(); mon_group = *lconvert->mon_grouping; - comma = ((*lconvert->mon_thousands_sep != '\0')? *lconvert->mon_thousands_sep: ','); + comma = ((*lconvert->mon_thousands_sep != '\0') ? *lconvert->mon_thousands_sep : ','); /* frac_digits in the C locale seems to return CHAR_MAX */ /* best guess is 2 in this case I think */ points = ((lconvert->frac_digits != CHAR_MAX) ? lconvert->frac_digits : 2); /* int_frac_digits? */ convention = lconvert->n_sign_posn; - dsymbol = ((*lconvert->mon_decimal_point != '\0')? *lconvert->mon_decimal_point: '.'); - csymbol = ((*lconvert->currency_symbol != '\0')? lconvert->currency_symbol: "$"); - nsymbol = ((*lconvert->negative_sign != '\0')? lconvert->negative_sign: "-"); + dsymbol = ((*lconvert->mon_decimal_point != '\0') ? *lconvert->mon_decimal_point : '.'); + csymbol = ((*lconvert->currency_symbol != '\0') ? lconvert->currency_symbol : "$"); + nsymbol = ((*lconvert->negative_sign != '\0') ? lconvert->negative_sign : "-"); #else mon_group = 3; comma = ','; @@ -273,8 +278,8 @@ cash_out(Cash *in_value) value /= 10; } - strncpy((buf+count-strlen(csymbol)+1),csymbol,strlen(csymbol)); - count -= strlen(csymbol)-1; + strncpy((buf + count - strlen(csymbol) + 1), csymbol, strlen(csymbol)); + count -= strlen(csymbol) - 1; if (buf[LAST_DIGIT] == ',') buf[LAST_DIGIT] = buf[LAST_PAREN]; diff --git a/src/backend/utils/adt/chunk.c b/src/backend/utils/adt/chunk.c index 05d9a52bc54..2f340f41ade 100644 --- a/src/backend/utils/adt/chunk.c +++ b/src/backend/utils/adt/chunk.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.17 1998/09/01 03:25:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.18 1998/09/01 04:32:28 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,25 +40,21 @@ static CHUNK_INFO cInfo; /* non-export function prototypes */ -static int -_FindBestChunk(int size, int *dmax, int *dbest, int dim, +static int _FindBestChunk(int size, int *dmax, int *dbest, int dim, int A[MAXPAT][MAXDIM + 1], int N); static int get_next(int *d, int k, int C, int *dmax); static void initialize_info(CHUNK_INFO *A, int ndim, int *dim, int *chunk); #ifdef LOARRAY -static void -_ConvertToChunkFile(int n, int baseSize, int *dim, int *C, +static void _ConvertToChunkFile(int n, int baseSize, int *dim, int *C, int srcfd, int destfd); -static void -read_chunk(int *chunk_no, int *C, char *a_chunk, int srcfd, +static void read_chunk(int *chunk_no, int *C, char *a_chunk, int srcfd, int n, int baseSize, int *PX, int *dist); static int write_chunk(struct varlena * a_chunk, int ofile); static int seek_and_read(int pos, int size, char *buff, int fp, int from); #endif -static int -GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize, +static int GetChunkSize(FILE *fd, int ndim, int dim[MAXDIM], int baseSize, int d[MAXDIM]); /*------------------------------------------------------------------------ @@ -421,7 +417,7 @@ seek_and_read(int pos, int size, char *buff, int fp, int from) } -#endif /* LOARRAY */ +#endif /* LOARRAY */ /*---------------------------------------------------------------------------- * _ReadChunkArray -- diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index 720178c4005..efbb8e45dcf 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.26 1998/09/01 03:25:53 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.27 1998/09/01 04:32:29 momjian Exp $ * * NOTES * This code is actually (almost) unused. @@ -102,8 +102,7 @@ static int correct_dir(char *direction, int *signptr); #endif -static int -istinterval(char *i_string, +static int istinterval(char *i_string, AbsoluteTime *i_start, AbsoluteTime *i_end); @@ -207,36 +206,39 @@ reltime2tm(int32 time, struct tm * tm) } /* reltime2tm() */ #if FALSE -char *timestring; -long quantity; -int i; -int unitnr; - -timestring = (char *) palloc(Max(strlen(INVALID_RELTIME_STR), - UNITMAXLEN) + 1); -if (timevalue == INVALID_RELTIME) +int +dummyfunc() { - strcpy(timestring, INVALID_RELTIME_STR); - return timestring; -} + char *timestring; + long quantity; + int i; + int unitnr; + + timestring = (char *) palloc(Max(strlen(INVALID_RELTIME_STR), + UNITMAXLEN) + 1); + if (timevalue == INVALID_RELTIME) + { + strcpy(timestring, INVALID_RELTIME_STR); + return timestring; + } -if (timevalue == 0) - i = 1; /* unit = 'seconds' */ -else - for (i = 12; i >= 0; i = i - 2) - if ((timevalue % sec_tab[i]) == 0) - break; /* appropriate unit found */ -unitnr = i; -quantity = (timevalue / sec_tab[unitnr]); -if (quantity > 1 || quantity < -1) - unitnr++; /* adjust index for PLURAL of unit */ -if (quantity >= 0) - sprintf(timestring, "%c %lu %s", RELTIME_LABEL, - quantity, unit_tab[unitnr]); -else - sprintf(timestring, "%c %lu %s %s", RELTIME_LABEL, - (quantity * -1), unit_tab[unitnr], RELTIME_PAST); -return timestring; + if (timevalue == 0) + i = 1; /* unit = 'seconds' */ + else + for (i = 12; i >= 0; i = i - 2) + if ((timevalue % sec_tab[i]) == 0) + break; /* appropriate unit found */ + unitnr = i; + quantity = (timevalue / sec_tab[unitnr]); + if (quantity > 1 || quantity < -1) + unitnr++; /* adjust index for PLURAL of unit */ + if (quantity >= 0) + sprintf(timestring, "%c %lu %s", RELTIME_LABEL, + quantity, unit_tab[unitnr]); + else + sprintf(timestring, "%c %lu %s %s", RELTIME_LABEL, + (quantity * -1), unit_tab[unitnr], RELTIME_PAST); + return timestring; } #endif @@ -987,126 +989,123 @@ isreltime(char *str) } /* isreltime() */ #if FALSE -char *p; -char c; -int i; -char unit[UNITMAXLEN]; -char direction[DIRMAXLEN]; -int localSign; -int localUnitNumber; -long localQuantity; - -if (!PointerIsValid(sign)) -{ - sign = &localSign; -} - -if (!PointerIsValid(unitnr)) +int +dummyfunc() { - unitnr = &localUnitNumber; -} + char *p; + char c; + int i; + char unit[UNITMAXLEN]; + char direction[DIRMAXLEN]; + int localSign; + int localUnitNumber; + long localQuantity; + + if (!PointerIsValid(sign)) + sign = &localSign; + + if (!PointerIsValid(unitnr)) + unitnr = &localUnitNumber; + + if (!PointerIsValid(quantity)) + quantity = &localQuantity; + + unit[0] = '\0'; + direction[0] = '\0'; + p = timestring; + /* skip leading blanks */ + while ((c = *p) != '\0') + { + if (c != ' ') + break; + p++; + } -if (!PointerIsValid(quantity)) -{ - quantity = &localQuantity; -} + /* Test whether 'invalid time' identifier or not */ + if (!strncmp(INVALID_RELTIME_STR, p, strlen(INVALID_RELTIME_STR) + 1)) + return 2; /* correct 'invalid time' identifier found */ -unit[0] = '\0'; -direction[0] = '\0'; -p = timestring; - /* skip leading blanks */ -while ((c = *p) != '\0') -{ + /* handle label of relative time */ + if (c != RELTIME_LABEL) + return 0; /* syntax error */ + c = *++p; if (c != ' ') - break; + return 0; /* syntax error */ p++; -} - - /* Test whether 'invalid time' identifier or not */ -if (!strncmp(INVALID_RELTIME_STR, p, strlen(INVALID_RELTIME_STR) + 1)) - return 2; /* correct 'invalid time' identifier found */ - - /* handle label of relative time */ -if (c != RELTIME_LABEL) - return 0; /* syntax error */ -c = *++p; -if (c != ' ') - return 0; /* syntax error */ -p++; - /* handle the quantity */ -*quantity = 0; -for (;;) -{ - c = *p; - if (isdigit(c)) - { - *quantity = *quantity * 10 + (c - '0'); - p++; - } - else + /* handle the quantity */ + *quantity = 0; + for (;;) { - if (c == ' ') - break; /* correct quantity found */ + c = *p; + if (isdigit(c)) + { + *quantity = *quantity * 10 + (c - '0'); + p++; + } else - return 0; /* syntax error */ + { + if (c == ' ') + break; /* correct quantity found */ + else + return 0; /* syntax error */ + } } -} - /* handle unit */ -p++; -i = 0; -for (;;) -{ - c = *p; - if (c >= 'a' && c <= 'z' && i <= (UNITMAXLEN - 1)) - { - unit[i] = c; - p++; - i++; - } - else + /* handle unit */ + p++; + i = 0; + for (;;) { - if ((c == ' ' || c == '\0') - && correct_unit(unit, unitnr)) - break; /* correct unit found */ + c = *p; + if (c >= 'a' && c <= 'z' && i <= (UNITMAXLEN - 1)) + { + unit[i] = c; + p++; + i++; + } else - return 0; /* syntax error */ + { + if ((c == ' ' || c == '\0') + && correct_unit(unit, unitnr)) + break; /* correct unit found */ + else + return 0; /* syntax error */ + } } -} - /* handle optional direction */ -if (c == ' ') - p++; -i = 0; -*sign = 1; -for (;;) -{ - c = *p; - if (c >= 'a' && c <= 'z' && i <= (DIRMAXLEN - 1)) - { - direction[i] = c; + /* handle optional direction */ + if (c == ' ') p++; - i++; - } - else + i = 0; + *sign = 1; + for (;;) { - if ((c == ' ' || c == '\0') && i == 0) + c = *p; + if (c >= 'a' && c <= 'z' && i <= (DIRMAXLEN - 1)) { - *sign = 1; - break; /* no direction specified */ + direction[i] = c; + p++; + i++; } - if ((c == ' ' || c == '\0') && i != 0) + else { - direction[i] = '\0'; - correct_dir(direction, sign); - break; /* correct direction found */ + if ((c == ' ' || c == '\0') && i == 0) + { + *sign = 1; + break; /* no direction specified */ + } + if ((c == ' ' || c == '\0') && i != 0) + { + direction[i] = '\0'; + correct_dir(direction, sign); + break; /* correct direction found */ + } + else + return 0; /* syntax error */ } - else - return 0; /* syntax error */ } -} -return 1; + return 1; } /* diff --git a/src/backend/utils/adt/dt.c b/src/backend/utils/adt/dt.c index fa6854fdc92..ae9c4663d2f 100644 --- a/src/backend/utils/adt/dt.c +++ b/src/backend/utils/adt/dt.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.56 1998/09/01 03:25:57 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.57 1998/09/01 04:32:30 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,15 +32,12 @@ #include "utils/builtins.h" static int DecodeDate(char *str, int fmask, int *tmask, struct tm * tm); -static int -DecodeNumber(int flen, char *field, +static int DecodeNumber(int flen, char *field, int fmask, int *tmask, struct tm * tm, double *fsec); -static int -DecodeNumberField(int len, char *str, +static int DecodeNumberField(int len, char *str, int fmask, int *tmask, struct tm * tm, double *fsec); static int DecodeSpecial(int field, char *lowtoken, int *val); -static int -DecodeTime(char *str, int fmask, int *tmask, +static int DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, double *fsec); static int DecodeTimezone(char *str, int *tzp); static int DecodeUnits(int field, char *lowtoken, int *val); @@ -2208,7 +2205,7 @@ static datetkn deltatktbl[] = { {"mils", UNITS, DTK_MILLENIUM}, /* "millenia" relative time units */ {"millenia", UNITS, DTK_MILLENIUM}, /* "millenia" relative time units */ {DMILLENIUM, UNITS, DTK_MILLENIUM}, /* "millenium" relative time units */ - {"millisecon", UNITS, DTK_MILLISEC}, /* relative time units */ + {"millisecon", UNITS, DTK_MILLISEC}, /* relative time units */ {"min", UNITS, DTK_MINUTE}, /* "minute" relative time units */ {"mins", UNITS, DTK_MINUTE},/* "minutes" relative time units */ {"mins", UNITS, DTK_MINUTE},/* "minutes" relative time units */ @@ -2223,18 +2220,18 @@ static datetkn deltatktbl[] = { {DMILLISEC, UNITS, DTK_MILLISEC}, {"mseconds", UNITS, DTK_MILLISEC}, {"msecs", UNITS, DTK_MILLISEC}, - {"qtr", UNITS, DTK_QUARTER}, /* "quarter" relative time */ + {"qtr", UNITS, DTK_QUARTER},/* "quarter" relative time */ {DQUARTER, UNITS, DTK_QUARTER}, /* "quarter" relative time */ - {"reltime", IGNORE, 0}, /* for pre-v6.1 "Undefined Reltime" */ + {"reltime", IGNORE, 0}, /* for pre-v6.1 "Undefined Reltime" */ {"s", UNITS, DTK_SECOND}, {"sec", UNITS, DTK_SECOND}, {DSECOND, UNITS, DTK_SECOND}, {"seconds", UNITS, DTK_SECOND}, {"secs", UNITS, DTK_SECOND}, - {DTIMEZONE, UNITS, DTK_TZ}, /* "timezone" time offset */ - {"tz", UNITS, DTK_TZ}, /* "timezone" time offset */ + {DTIMEZONE, UNITS, DTK_TZ}, /* "timezone" time offset */ + {"tz", UNITS, DTK_TZ}, /* "timezone" time offset */ {"tz_hour", UNITS, DTK_TZ_HOUR}, /* timezone hour units */ - {"tz_minute", UNITS, DTK_TZ_MINUTE}, /* timezone minutes units */ + {"tz_minute", UNITS, DTK_TZ_MINUTE}, /* timezone minutes units */ {"undefined", RESERV, DTK_INVALID}, /* pre-v6.1 invalid time */ {"us", UNITS, DTK_MICROSEC},/* "microsecond" relative time units */ {"usec", UNITS, DTK_MICROSEC}, /* "microsecond" relative time @@ -3645,7 +3642,7 @@ DecodeSpecial(int field, char *lowtoken, int *val) * an unsigned floating point number. - thomas 1997-11-16 * * Allow ISO-style time span, with implicit units on number of days - * preceeding an hh:mm:ss field. - thomas 1998-04-30 + * preceeding an hh:mm:ss field. - thomas 1998-04-30 */ int DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, double *fsec) @@ -3688,8 +3685,10 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do break; case DTK_TZ: - /* Timezone is a token with a leading sign character - * and otherwise the same as a non-signed numeric field + + /* + * Timezone is a token with a leading sign character and + * otherwise the same as a non-signed numeric field */ case DTK_DATE: case DTK_NUMBER: @@ -4258,7 +4257,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha * * Support "traditional Postgres" and ISO-8601 styles. * Actually, afaik ISO does not address time interval formatting, - * but this looks similar to the spec for absolute date/time. + * but this looks similar to the spec for absolute date/time. * - thomas 1998-04-30 */ int @@ -4270,7 +4269,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) switch (style) { - /* compatible with ISO date formats */ + /* compatible with ISO date formats */ case USE_ISO_DATES: break; @@ -4284,7 +4283,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) { is_before |= (tm->tm_year < 0); sprintf(cp, "%d year%s", - abs(tm->tm_year), ((abs(tm->tm_year) != 1) ? "s" : "")); + abs(tm->tm_year), ((abs(tm->tm_year) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; } @@ -4292,26 +4291,26 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_mon != 0) { is_before |= (tm->tm_mon < 0); - sprintf(cp, "%s%d mon%s", (is_nonzero? " ": ""), - abs(tm->tm_mon), ((abs(tm->tm_mon) != 1) ? "s" : "")); + sprintf(cp, "%s%d mon%s", (is_nonzero ? " " : ""), + abs(tm->tm_mon), ((abs(tm->tm_mon) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; } switch (style) { - /* compatible with ISO date formats */ + /* compatible with ISO date formats */ case USE_ISO_DATES: if (tm->tm_mday != 0) { is_before |= (tm->tm_mday < 0); - sprintf(cp, "%s%d", (is_nonzero? " ": ""), abs(tm->tm_mday)); + sprintf(cp, "%s%d", (is_nonzero ? " " : ""), abs(tm->tm_mday)); cp += strlen(cp); is_nonzero = TRUE; } is_before |= ((tm->tm_hour < 0) || (tm->tm_min < 0)); - sprintf(cp, "%s%02d:%02d", (is_nonzero? " ": ""), - abs(tm->tm_hour), abs(tm->tm_min)); + sprintf(cp, "%s%02d:%02d", (is_nonzero ? " " : ""), + abs(tm->tm_hour), abs(tm->tm_min)); cp += strlen(cp); if ((tm->tm_hour != 0) || (tm->tm_min != 0)) is_nonzero = TRUE; @@ -4341,7 +4340,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_mday != 0) { is_before |= (tm->tm_mday < 0); - sprintf(cp, "%s%d day%s", (is_nonzero? " ": ""), + sprintf(cp, "%s%d day%s", (is_nonzero ? " " : ""), abs(tm->tm_mday), ((abs(tm->tm_mday) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; @@ -4349,7 +4348,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_hour != 0) { is_before |= (tm->tm_hour < 0); - sprintf(cp, "%s%d hour%s", (is_nonzero? " ": ""), + sprintf(cp, "%s%d hour%s", (is_nonzero ? " " : ""), abs(tm->tm_hour), ((abs(tm->tm_hour) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; @@ -4358,8 +4357,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) if (tm->tm_min != 0) { is_before |= (tm->tm_min < 0); - sprintf(cp, "%s%d min%s", (is_nonzero? " ": ""), - abs(tm->tm_min), ((abs(tm->tm_min) != 1) ? "s" : "")); + sprintf(cp, "%s%d min%s", (is_nonzero ? " " : ""), + abs(tm->tm_min), ((abs(tm->tm_min) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; } @@ -4369,7 +4368,7 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) { fsec += tm->tm_sec; is_before |= (fsec < 0); - sprintf(cp, "%s%.2f secs", (is_nonzero? " ": ""), fabs(fsec)); + sprintf(cp, "%s%.2f secs", (is_nonzero ? " " : ""), fabs(fsec)); cp += strlen(cp); is_nonzero = TRUE; @@ -4378,8 +4377,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str) else if (tm->tm_sec != 0) { is_before |= (tm->tm_sec < 0); - sprintf(cp, "%s%d sec%s", (is_nonzero? " ": ""), - abs(tm->tm_sec), ((abs(tm->tm_sec) != 1) ? "s" : "")); + sprintf(cp, "%s%d sec%s", (is_nonzero ? " " : ""), + abs(tm->tm_sec), ((abs(tm->tm_sec) != 1) ? "s" : "")); cp += strlen(cp); is_nonzero = TRUE; } diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 69cd1a42018..b1de92f643e 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.32 1998/09/01 03:25:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.33 1998/09/01 04:32:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -158,7 +158,7 @@ CheckFloat4Val(double val) if (val != 0.0 && fabs(val) < FLOAT4_MIN) elog(ERROR, "Bad float4 input format -- underflow"); return; -#endif /* UNSAFE_FLOATS */ +#endif /* UNSAFE_FLOATS */ } /* @@ -183,7 +183,7 @@ CheckFloat8Val(double val) if (val != 0.0 && fabs(val) < FLOAT8_MIN) elog(ERROR, "Bad float8 input format -- underflow"); return; -#endif /* UNSAFE_FLOATS */ +#endif /* UNSAFE_FLOATS */ } /* @@ -1491,7 +1491,7 @@ double x; return w - TWO52[sx]; } -#endif /* !HAVE_RINT */ +#endif /* !HAVE_RINT */ #ifndef HAVE_CBRT @@ -1506,4 +1506,4 @@ double x; return isneg ? -tmpres : tmpres; } -#endif /* !HAVE_CBRT */ +#endif /* !HAVE_CBRT */ diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 2775f6b5fc9..1a99c366160 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.36 1998/09/01 03:26:01 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.37 1998/09/01 04:32:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -777,6 +777,7 @@ line_in(char *str) LSEG lseg; int isopen; char *s; + #endif if (!PointerIsValid(str)) @@ -800,9 +801,11 @@ line_in(char *str) char * line_out(LINE *line) { - char *result; + char *result; + #ifdef ENABLE_LINE_TYPE - LSEG lseg; + LSEG lseg; + #endif if (!PointerIsValid(line)) @@ -2343,7 +2346,7 @@ close_pl(Point *pt, LINE *line) * * Some tricky code here, relying on boolean expressions * evaluating to only zero or one to use as an array index. - * bug fixes by gthaker@atl.lmco.com; May 1, 1998 + * bug fixes by gthaker@atl.lmco.com; May 1, 1998 */ Point * close_ps(Point *pt, LSEG *lseg) @@ -2356,7 +2359,7 @@ close_ps(Point *pt, LSEG *lseg) #ifdef GEODEBUG printf("close_sp:pt->x %f pt->y %f\nlseg(0).x %f lseg(0).y %f lseg(1).x %f lseg(1).y %f\n", - pt->x, pt->y, lseg->p[0].x, lseg->p[0].y, lseg->p[1].x, lseg->p[1].y); + pt->x, pt->y, lseg->p[0].x, lseg->p[0].y, lseg->p[1].x, lseg->p[1].y); #endif result = NULL; @@ -2372,14 +2375,14 @@ close_ps(Point *pt, LSEG *lseg) #endif /* first check if point is below or above the entire lseg. */ if (pt->y < lseg->p[!yh].y) - result = point_copy(&lseg->p[!yh]); /* below the lseg */ + result = point_copy(&lseg->p[!yh]); /* below the lseg */ else if (pt->y > lseg->p[yh].y) - result = point_copy(&lseg->p[yh]); /* above the lseg */ + result = point_copy(&lseg->p[yh]); /* above the lseg */ if (result != NULL) - return result; + return result; /* point lines along (to left or right) of the vertical lseg. */ - + result = palloc(sizeof(*result)); result->x = lseg->p[0].x; result->y = pt->y; @@ -2392,11 +2395,11 @@ close_ps(Point *pt, LSEG *lseg) #endif /* first check if point is left or right of the entire lseg. */ if (pt->x < lseg->p[!xh].x) - result = point_copy(&lseg->p[!xh]); /* left of the lseg */ + result = point_copy(&lseg->p[!xh]); /* left of the lseg */ else if (pt->x > lseg->p[xh].x) - result = point_copy(&lseg->p[xh]); /* right of the lseg */ + result = point_copy(&lseg->p[xh]); /* right of the lseg */ if (result != NULL) - return result; + return result; /* point lines along (at top or below) the horiz. lseg. */ result = palloc(sizeof(*result)); @@ -2405,31 +2408,41 @@ close_ps(Point *pt, LSEG *lseg) return result; } - /* vert. and horiz. cases are down, now check if the closest - * point is one of the end points or someplace on the lseg. */ + /* + * vert. and horiz. cases are down, now check if the closest point is + * one of the end points or someplace on the lseg. + */ /* TODO: Ask if "tmp" should be freed to prevent memory leak */ invm = -1.0 / point_sl(&(lseg->p[0]), &(lseg->p[1])); - tmp = line_construct_pm(&lseg->p[!yh], invm); /* lower edge of the "band" */ - if (pt->y < (tmp->A*pt->x + tmp->C)) { /* we are below the lower edge */ - result = point_copy(&lseg->p[!yh]); /* below the lseg, take lower end pt */ -/* fprintf(stderr,"below: tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ - return result; + tmp = line_construct_pm(&lseg->p[!yh], invm); /* lower edge of the + * "band" */ + if (pt->y < (tmp->A * pt->x + tmp->C)) + { /* we are below the lower edge */ + result = point_copy(&lseg->p[!yh]); /* below the lseg, take + * lower end pt */ +/* fprintf(stderr,"below: tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ + return result; } - tmp = line_construct_pm(&lseg->p[yh], invm); /* upper edge of the "band" */ - if (pt->y > (tmp->A*pt->x + tmp->C)) { /* we are below the lower edge */ - result = point_copy(&lseg->p[yh]); /* above the lseg, take higher end pt */ -/* fprintf(stderr,"above: tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ - return result; + tmp = line_construct_pm(&lseg->p[yh], invm); /* upper edge of the + * "band" */ + if (pt->y > (tmp->A * pt->x + tmp->C)) + { /* we are below the lower edge */ + result = point_copy(&lseg->p[yh]); /* above the lseg, take + * higher end pt */ +/* fprintf(stderr,"above: tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ + return result; } - /* at this point the "normal" from point will hit lseg. The closet point - * will be somewhere on the lseg */ + /* + * at this point the "normal" from point will hit lseg. The closet + * point will be somewhere on the lseg + */ tmp = line_construct_pm(pt, invm); -/* fprintf(stderr,"tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ +/* fprintf(stderr,"tmp A %f B %f C %f m %f\n",tmp->A,tmp->B,tmp->C, tmp->m); */ result = interpt_sl(lseg, tmp); -/* fprintf(stderr,"result.x %f result.y %f\n", result->x, result->y); */ +/* fprintf(stderr,"result.x %f result.y %f\n", result->x, result->y); */ return result; } /* close_ps() */ @@ -4428,7 +4441,7 @@ box_circle(BOX *box) } /* box_circle() */ -POLYGON * +POLYGON * circle_poly(int npts, CIRCLE *circle) { POLYGON *poly; diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index d1e1a062dc2..4eb646392f6 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.16 1998/09/01 03:26:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.17 1998/09/01 04:32:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -80,7 +80,7 @@ int2out(int16 sh) int16 * int28in(char *shs) { - int16 **result; + int16 **result; int nums; if (shs == NULL) diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index f2ebad62a61..4ffdcbf225b 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -208,7 +208,7 @@ int48ge(int32 val1, int64 * val2) int64 * int8um(int64 * val) { - int64 temp = 0; + int64 temp = 0; int64 *result = palloc(sizeof(int64)); if (!PointerIsValid(val)) @@ -217,7 +217,7 @@ int8um(int64 * val) #if FALSE *result = temp - (*val); #else - result = int8mi(&temp, val); + result = int8mi(&temp, val); #endif return result; @@ -281,17 +281,18 @@ int8larger(int64 * val1, int64 * val2) { #if FALSE int64 *result = palloc(sizeof(int64)); + #endif if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; #if FALSE - *result = ((*val1 > *val2)? *val1: *val2); + *result = ((*val1 > *val2) ? *val1 : *val2); return result; #endif - return (*val1 > *val2)? val1: val2; + return (*val1 > *val2) ? val1 : val2; } /* int8larger() */ int64 * @@ -299,17 +300,18 @@ int8smaller(int64 * val1, int64 * val2) { #if FALSE int64 *result = palloc(sizeof(int64)); + #endif if ((!PointerIsValid(val1)) || (!PointerIsValid(val2))) return NULL; #if FALSE - *result = ((*val1 < *val2)? *val1: *val2); + *result = ((*val1 < *val2) ? *val1 : *val2); return result; #endif - return (*val1 < *val2)? val1: val2; + return (*val1 < *val2) ? val1 : val2; } /* int8smaller() */ @@ -400,7 +402,7 @@ int48mul(int32 val1, int64 * val2) if (!PointerIsValid(val2)) return NULL; - *result = (int64) val1 * *val2; + *result = (int64) val1 **val2; return result; } /* int48mul() */ @@ -442,14 +444,16 @@ int84(int64 * val) elog(ERROR, "Invalid (null) int64, can't convert int8 to int4", NULL); #if FALSE - /* Hmm. This conditional always tests true on my i686/linux box. - * It's a gcc compiler bug, or I'm missing something obvious, which is more likely... - * - thomas 1998-06-09 + + /* + * Hmm. This conditional always tests true on my i686/linux box. It's + * a gcc compiler bug, or I'm missing something obvious, which is more + * likely... - thomas 1998-06-09 */ if ((*val < INT_MIN) || (*val > INT_MAX)) #endif - if ((*val < (-pow(2, 31) + 1)) || (*val > (pow(2, 31) - 1))) - elog(ERROR, "int8 conversion to int4 is out of range", NULL); + if ((*val < (-pow(2, 31) + 1)) || (*val > (pow(2, 31) - 1))) + elog(ERROR, "int8 conversion to int4 is out of range", NULL); result = *val; @@ -501,10 +505,10 @@ i8tod(int64 * val) * Convert double float to 8-byte integer. * Do a range check before the conversion. * Note that the comparison probably isn't quite right - * since we only have ~52 bits of precision in a double float - * and so subtracting one from a large number gives the large - * number exactly. However, for some reason the comparison below - * does the right thing on my i686/linux-rh4.2 box. + * since we only have ~52 bits of precision in a double float + * and so subtracting one from a large number gives the large + * number exactly. However, for some reason the comparison below + * does the right thing on my i686/linux-rh4.2 box. * - thomas 1998-06-16 */ int64 * diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index bae7ae062e1..eb764e7c01a 100644 --- a/src/backend/utils/adt/like.c +++ b/src/backend/utils/adt/like.c @@ -23,7 +23,7 @@ #include "utils/builtins.h" /* where the function declarations go */ #include "mb/pg_wchar.h" -static int like(pg_wchar *text, pg_wchar *p); +static int like(pg_wchar * text, pg_wchar * p); /* * interface routines called by the function manager @@ -40,18 +40,18 @@ static int like(pg_wchar *text, pg_wchar *p); static bool fixedlen_like(char *s, struct varlena * p, int charlen) { - pg_wchar *sterm, + pg_wchar *sterm, *pterm; int result; - int len; + int len; if (!s || !p) return FALSE; /* be sure sterm is null-terminated */ #ifdef MULTIBYTE - sterm = (pg_wchar *) palloc((charlen + 1)*sizeof(pg_wchar)); - (void)pg_mb2wchar_with_len((unsigned char *)s,sterm,charlen); + sterm = (pg_wchar *) palloc((charlen + 1) * sizeof(pg_wchar)); + (void) pg_mb2wchar_with_len((unsigned char *) s, sterm, charlen); #else sterm = (char *) palloc(charlen + 1); StrNCpy(sterm, s, charlen + 1); @@ -65,8 +65,8 @@ fixedlen_like(char *s, struct varlena * p, int charlen) /* palloc the length of the text + the null character */ len = VARSIZE(p) - VARHDRSZ; #ifdef MULTIBYTE - pterm = (pg_wchar *) palloc((len + 1)*sizeof(pg_wchar)); - (void)pg_mb2wchar_with_len((unsigned char *)VARDATA(p),pterm,len); + pterm = (pg_wchar *) palloc((len + 1) * sizeof(pg_wchar)); + (void) pg_mb2wchar_with_len((unsigned char *) VARDATA(p), pterm, len); #else pterm = (char *) palloc(len + 1); memmove(pterm, VARDATA(p), len); @@ -111,7 +111,7 @@ textnlike(struct varlena * s, struct varlena * p) } -/* $Revision: 1.19 $ +/* $Revision: 1.20 $ ** "like.c" A first attempt at a LIKE operator for Postgres95. ** ** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986. @@ -146,7 +146,7 @@ textnlike(struct varlena * s, struct varlena * p) ** Match text and p, return LIKE_TRUE, LIKE_FALSE, or LIKE_ABORT. */ static int -DoMatch(pg_wchar *text, pg_wchar *p) +DoMatch(pg_wchar * text, pg_wchar * p) { int matched; @@ -189,7 +189,7 @@ DoMatch(pg_wchar *text, pg_wchar *p) ** User-level routine. Returns TRUE or FALSE. */ static int -like(pg_wchar *text, pg_wchar *p) +like(pg_wchar * text, pg_wchar * p) { if (p[0] == '%' && p[1] == '\0') return TRUE; diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 83632d70ca2..c6c84357d7a 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.14 1998/09/01 03:26:07 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.15 1998/09/01 04:32:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -73,13 +73,13 @@ oidrand(Oid o, int32 X) return true; /* - * We do this because the cancel key is actually a random, so we don't - * want them to be able to request random numbers using our postmaster - * seeded value. + * We do this because the cancel key is actually a random, so we don't + * want them to be able to request random numbers using our postmaster + * seeded value. */ if (!random_initialized) { - srandom((unsigned int)time(NULL)); + srandom((unsigned int) time(NULL)); random_initialized = true; } diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index ad37559bd03..f3a813ca01b 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.14 1998/09/01 03:26:10 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.15 1998/09/01 04:32:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -199,7 +199,7 @@ namestrcmp(Name name, char *str) if (!name && !str) return 0; if (!name) - return -1; /* NULL < anything */ + return -1; /* NULL < anything */ if (!str) return 1; /* NULL < anything */ return strncmp(name->data, str, NAMEDATALEN); diff --git a/src/backend/utils/adt/not_in.c b/src/backend/utils/adt/not_in.c index 0bb9412e0e5..52d8cd0c17e 100644 --- a/src/backend/utils/adt/not_in.c +++ b/src/backend/utils/adt/not_in.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.12 1998/09/01 03:26:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.13 1998/09/01 04:32:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -72,14 +72,14 @@ int4notin(int16 not_in_arg, char *relation_and_attr) /* the last argument should be a ScanKey, not an integer! - jolly */ /* it looks like the arguments are out of order, too */ /* but skeyData is never initialized! does this work?? - ay 2/95 */ - scan_descriptor = heap_beginscan(relation_to_scan, false, SnapshotNow, + scan_descriptor = heap_beginscan(relation_to_scan, false, SnapshotNow, 0, &skeyData); retval = true; /* do a scan of the relation, and do the check */ while (HeapTupleIsValid(current_tuple = heap_getnext(scan_descriptor, 0)) && - retval) + retval) { value = heap_getattr(current_tuple, (AttrNumber) attrid, diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c index 86a999709f4..b30b2fe557b 100644 --- a/src/backend/utils/adt/numutils.c +++ b/src/backend/utils/adt/numutils.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.25 1998/09/01 03:26:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.26 1998/09/01 04:32:43 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -77,7 +77,7 @@ pg_atoi(char *s, int size, int c) errno = ERANGE; elog(ERROR, "pg_atoi: error reading \"%s\": %m", s); } -#endif /* HAS_LONG_LONG */ +#endif /* HAS_LONG_LONG */ break; case sizeof(int16): if (l < SHRT_MIN) diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c index 153e80854aa..b98215f8754 100644 --- a/src/backend/utils/adt/oid.c +++ b/src/backend/utils/adt/oid.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.17 1998/09/01 03:26:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.18 1998/09/01 04:32:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ Oid * oid8in(char *oidString) { - Oid **result; + Oid **result; int nums; if (oidString == NULL) @@ -128,8 +128,9 @@ oid8eq(Oid *arg1, Oid *arg2) bool oid8lt(Oid *arg1, Oid *arg2) { - int i; - for (i=0; i < 8; i++) + int i; + + for (i = 0; i < 8; i++) if (!int4eq(arg1[i], arg2[i])) return int4lt(arg1[i], arg2[i]); return false; @@ -138,8 +139,9 @@ oid8lt(Oid *arg1, Oid *arg2) bool oid8le(Oid *arg1, Oid *arg2) { - int i; - for (i=0; i < 8; i++) + int i; + + for (i = 0; i < 8; i++) if (!int4eq(arg1[i], arg2[i])) return int4le(arg1[i], arg2[i]); return true; @@ -148,8 +150,9 @@ oid8le(Oid *arg1, Oid *arg2) bool oid8ge(Oid *arg1, Oid *arg2) { - int i; - for (i=0; i < 8; i++) + int i; + + for (i = 0; i < 8; i++) if (!int4eq(arg1[i], arg2[i])) return int4ge(arg1[i], arg2[i]); return true; @@ -158,8 +161,9 @@ oid8ge(Oid *arg1, Oid *arg2) bool oid8gt(Oid *arg1, Oid *arg2) { - int i; - for (i=0; i < 8; i++) + int i; + + for (i = 0; i < 8; i++) if (!int4eq(arg1[i], arg2[i])) return int4gt(arg1[i], arg2[i]); return false; diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index 2297d3246c1..084e0911a48 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -1,7 +1,7 @@ /* * Edmund Mergl <E.Mergl@bawue.de> * - * $Id: oracle_compat.c,v 1.15 1998/08/11 18:38:07 momjian Exp $ + * $Id: oracle_compat.c,v 1.16 1998/09/01 04:32:45 momjian Exp $ * */ @@ -54,7 +54,7 @@ lower(text *string) ptr_ret = VARDATA(ret); while (m--) - *ptr_ret++ = tolower((unsigned char)*ptr++); + *ptr_ret++ = tolower((unsigned char) *ptr++); return ret; } @@ -92,7 +92,7 @@ upper(text *string) ptr_ret = VARDATA(ret); while (m--) - *ptr_ret++ = toupper((unsigned char)*ptr++); + *ptr_ret++ = toupper((unsigned char) *ptr++); return ret; } @@ -131,15 +131,15 @@ initcap(text *string) ptr = VARDATA(string); ptr_ret = VARDATA(ret); - *ptr_ret++ = toupper((unsigned char)*ptr++); + *ptr_ret++ = toupper((unsigned char) *ptr++); --m; while (m--) { if (*(ptr_ret - 1) == ' ' || *(ptr_ret - 1) == ' ') - *ptr_ret++ = toupper((unsigned char)*ptr++); + *ptr_ret++ = toupper((unsigned char) *ptr++); else - *ptr_ret++ = tolower((unsigned char)*ptr++); + *ptr_ret++ = tolower((unsigned char) *ptr++); } return ret; diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index 377c3285d9a..6efb350266f 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.19 1998/09/01 03:26:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.20 1998/09/01 04:32:46 momjian Exp $ * * Alistair Crooks added the code for the regex caching * agc - cached the regular expressions used - there's a good chance @@ -36,7 +36,7 @@ #if defined(DISABLE_XOPEN_NLS) #undef _XOPEN_SOURCE -#endif /* DISABLE_XOPEN_NLS */ +#endif /* DISABLE_XOPEN_NLS */ /* this is the number of cached regular expressions held. */ #ifndef MAX_CACHED_RES diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 4a9f1a0bc0a..056e2fe3f5d 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.25 1998/09/01 03:26:16 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.26 1998/09/01 04:32:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -28,7 +28,7 @@ /***************************************************************************** * USER I/O ROUTINES * *****************************************************************************/ - + /* * regprocin - converts "proname" to proid * @@ -46,27 +46,29 @@ regprocin(char *pro_name_and_oid) if (!IsBootstrapProcessingMode()) { + /* - * we need to use the oid because there can be multiple entries - * with the same name. We accept 1323_int4eq and 1323. + * we need to use the oid because there can be multiple entries + * with the same name. We accept 1323_int4eq and 1323. */ - if (strrchr(pro_name_and_oid,'_') != NULL) + if (strrchr(pro_name_and_oid, '_') != NULL) { proctup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(atoi(strrchr(pro_name_and_oid,'_')+1)), - 0, 0, 0); + ObjectIdGetDatum(atoi(strrchr(pro_name_and_oid, '_') + 1)), + 0, 0, 0); } else if (atoi(pro_name_and_oid) != InvalidOid) { proctup = SearchSysCacheTuple(PROOID, - /* atoi stops at the _ */ - ObjectIdGetDatum(atoi(pro_name_and_oid)), - 0, 0, 0); + /* atoi stops at the _ */ + ObjectIdGetDatum(atoi(pro_name_and_oid)), + 0, 0, 0); } if (HeapTupleIsValid(proctup)) - result = (RegProcedure) proctup->t_oid; - else elog(ERROR, "regprocin: no such procedure %s", pro_name_and_oid); + result = (RegProcedure) proctup->t_oid; + else + elog(ERROR, "regprocin: no such procedure %s", pro_name_and_oid); } else { @@ -74,7 +76,7 @@ regprocin(char *pro_name_and_oid) HeapScanDesc procscan; ScanKeyData key; bool isnull; - + proc = heap_openr(ProcedureRelationName); if (!RelationIsValid(proc)) { @@ -87,7 +89,7 @@ regprocin(char *pro_name_and_oid) (AttrNumber) 1, (RegProcedure) F_NAMEEQ, (Datum) pro_name_and_oid); - + procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); if (!HeapScanIsValid(procscan)) { @@ -99,23 +101,23 @@ regprocin(char *pro_name_and_oid) proctup = heap_getnext(procscan, 0); if (HeapTupleIsValid(proctup)) { - result = (RegProcedure) heap_getattr(proctup, - ObjectIdAttributeNumber, - RelationGetDescr(proc), - &isnull); - if (isnull) - elog(FATAL, "regprocin: null procedure %s", pro_name_and_oid); + result = (RegProcedure) heap_getattr(proctup, + ObjectIdAttributeNumber, + RelationGetDescr(proc), + &isnull); + if (isnull) + elog(FATAL, "regprocin: null procedure %s", pro_name_and_oid); } else - result = (RegProcedure) 0; + result = (RegProcedure) 0; heap_endscan(procscan); heap_close(proc); - } + } #ifdef EBUG elog(DEBUG, "regprocin: no such procedure %s", pro_name_and_oid); -#endif /* defined(EBUG) */ +#endif /* defined(EBUG) */ return (int32) result; } @@ -133,15 +135,15 @@ regprocout(RegProcedure proid) if (!IsBootstrapProcessingMode()) { proctup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(proid), - 0, 0, 0); - + ObjectIdGetDatum(proid), + 0, 0, 0); + if (HeapTupleIsValid(proctup)) { - char *s; - - s = ((Form_pg_proc) GETSTRUCT(proctup))->proname.data; - snprintf(result, NAMEDATALEN, "%s_%d", s, proid); + char *s; + + s = ((Form_pg_proc) GETSTRUCT(proctup))->proname.data; + snprintf(result, NAMEDATALEN, "%s_%d", s, proid); } else { @@ -154,7 +156,7 @@ regprocout(RegProcedure proid) Relation proc; HeapScanDesc procscan; ScanKeyData key; - + proc = heap_openr(ProcedureRelationName); if (!RelationIsValid(proc)) { @@ -167,7 +169,7 @@ regprocout(RegProcedure proid) (AttrNumber) ObjectIdAttributeNumber, (RegProcedure) F_INT4EQ, (Datum) proid); - + procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); if (!HeapScanIsValid(procscan)) { @@ -183,7 +185,7 @@ regprocout(RegProcedure proid) bool isnull; s = (char *) heap_getattr(proctup, 1, - RelationGetDescr(proc), &isnull); + RelationGetDescr(proc), &isnull); if (!isnull) StrNCpy(result, s, NAMEDATALEN); else @@ -191,8 +193,8 @@ regprocout(RegProcedure proid) } else { - result[0] = '-'; - result[1] = '\0'; + result[0] = '-'; + result[1] = '\0'; } heap_endscan(procscan); heap_close(proc); @@ -200,8 +202,8 @@ regprocout(RegProcedure proid) } #ifdef EBUG - elog(DEBUG, "regprocout: no such procedure %d", proid); -#endif /* defined(EBUG) */ + elog(DEBUG, "regprocout: no such procedure %d", proid); +#endif /* defined(EBUG) */ return result; } @@ -232,15 +234,15 @@ oid8types(Oid **oidArray) if (*sp != InvalidOid) { typetup = SearchSysCacheTuple(TYPOID, - ObjectIdGetDatum(*sp), - 0, 0, 0); + ObjectIdGetDatum(*sp), + 0, 0, 0); if (HeapTupleIsValid(typetup)) { char *s; s = ((Form_pg_type) GETSTRUCT(typetup))->typname.data; StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s, - NAMEDATALEN); + NAMEDATALEN); strcat(VARDATA(result), " "); } } diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 593d670d374..f9774bf62f5 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,35 +3,35 @@ * out of it's tuple * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.2 1998/09/01 03:26:17 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.3 1998/09/01 04:32:49 momjian Exp $ * - * This software is copyrighted by Jan Wieck - Hamburg. + * This software is copyrighted by Jan Wieck - Hamburg. * - * The author hereby grants permission to use, copy, modify, - * distribute, and license this software and its documentation - * for any purpose, provided that existing copyright notices are - * retained in all copies and that this notice is included - * verbatim in any distributions. No written agreement, license, - * or royalty fee is required for any of the authorized uses. - * Modifications to this software may be copyrighted by their - * author and need not follow the licensing terms described - * here, provided that the new terms are clearly indicated on - * the first page of each file where they apply. + * The author hereby grants permission to use, copy, modify, + * distribute, and license this software and its documentation + * for any purpose, provided that existing copyright notices are + * retained in all copies and that this notice is included + * verbatim in any distributions. No written agreement, license, + * or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their + * author and need not follow the licensing terms described + * here, provided that the new terms are clearly indicated on + * the first page of each file where they apply. * - * IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS - * SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN - * IF THE AUTHOR HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. + * IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY + * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS + * SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN + * IF THE AUTHOR HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. * - * THE AUTHOR AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON - * AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAVE NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, - * ENHANCEMENTS, OR MODIFICATIONS. + * THE AUTHOR AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON + * AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAVE NO + * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, + * ENHANCEMENTS, OR MODIFICATIONS. * **********************************************************************/ @@ -70,8 +70,8 @@ static char *query_getview = "SELECT * FROM pg_rewrite WHERE rulename = $1 or ru * Global functions * ---------- */ -text *pg_get_ruledef(NameData *rname); -text *pg_get_viewdef(NameData *rname); +text *pg_get_ruledef(NameData *rname); +text *pg_get_viewdef(NameData *rname); /* ---------- @@ -103,90 +103,91 @@ static bool check_if_rte_used(int rt_index, Node *node, int sup); text * pg_get_ruledef(NameData *rname) { - text *ruledef; - Datum args[1]; - char nulls[2]; - int spirc; - HeapTuple ruletup; - TupleDesc rulettc; - char *tmp; - int len; - - /* ---------- - * We need the rules name somewhere deep down - * ---------- - */ - rulename = nameout(rname); - - /* ---------- - * Connect to SPI manager - * ---------- - */ - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "get_ruledef: cannot connect to SPI manager"); - - /* ---------- - * On the first call prepare the plan to lookup pg_proc. - * We read pg_proc over the SPI manager instead of using - * the syscache to be checked for read access on pg_proc. - * ---------- - */ - if (plan_getrule == NULL) { - Oid argtypes[1]; - void *plan; - - argtypes[0] = NAMEOID; - plan = SPI_prepare(query_getrule, 1, argtypes); - if (plan == NULL) - elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getrule); - plan_getrule = SPI_saveplan(plan); - } - - /* ---------- - * Get the pg_rewrite tuple for this rule - * ---------- - */ - args[0] = PointerGetDatum(rulename); - nulls[0] = (rulename == NULL) ? 'n' : ' '; - nulls[1] = '\0'; - spirc = SPI_execp(plan_getrule, args, nulls, 1); - if (spirc != SPI_OK_SELECT) { - elog(ERROR, "failed to get pg_rewrite tuple for %s", rulename); - } - if (SPI_processed != 1) { - if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "get_ruledef: SPI_finish() failed"); - ruledef = SPI_palloc(VARHDRSZ + 1); - VARSIZE(ruledef) = VARHDRSZ + 1; - VARDATA(ruledef)[0] = '-'; + text *ruledef; + Datum args[1]; + char nulls[2]; + int spirc; + HeapTuple ruletup; + TupleDesc rulettc; + char *tmp; + int len; + + /* ---------- + * We need the rules name somewhere deep down + * ---------- + */ + rulename = nameout(rname); + + /* ---------- + * Connect to SPI manager + * ---------- + */ + if (SPI_connect() != SPI_OK_CONNECT) + elog(ERROR, "get_ruledef: cannot connect to SPI manager"); + + /* ---------- + * On the first call prepare the plan to lookup pg_proc. + * We read pg_proc over the SPI manager instead of using + * the syscache to be checked for read access on pg_proc. + * ---------- + */ + if (plan_getrule == NULL) + { + Oid argtypes[1]; + void *plan; + + argtypes[0] = NAMEOID; + plan = SPI_prepare(query_getrule, 1, argtypes); + if (plan == NULL) + elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getrule); + plan_getrule = SPI_saveplan(plan); + } + + /* ---------- + * Get the pg_rewrite tuple for this rule + * ---------- + */ + args[0] = PointerGetDatum(rulename); + nulls[0] = (rulename == NULL) ? 'n' : ' '; + nulls[1] = '\0'; + spirc = SPI_execp(plan_getrule, args, nulls, 1); + if (spirc != SPI_OK_SELECT) + elog(ERROR, "failed to get pg_rewrite tuple for %s", rulename); + if (SPI_processed != 1) + { + if (SPI_finish() != SPI_OK_FINISH) + elog(ERROR, "get_ruledef: SPI_finish() failed"); + ruledef = SPI_palloc(VARHDRSZ + 1); + VARSIZE(ruledef) = VARHDRSZ + 1; + VARDATA(ruledef)[0] = '-'; + return ruledef; + } + + ruletup = SPI_tuptable->vals[0]; + rulettc = SPI_tuptable->tupdesc; + + /* ---------- + * Get the rules definition and put it into executors memory + * ---------- + */ + tmp = make_ruledef(ruletup, rulettc); + len = strlen(tmp) + VARHDRSZ; + ruledef = SPI_palloc(len); + VARSIZE(ruledef) = len; + memcpy(VARDATA(ruledef), tmp, len - VARHDRSZ); + + /* ---------- + * Disconnect from SPI manager + * ---------- + */ + if (SPI_finish() != SPI_OK_FINISH) + elog(ERROR, "get_ruledef: SPI_finish() failed"); + + /* ---------- + * Easy - isn't it? + * ---------- + */ return ruledef; - } - - ruletup = SPI_tuptable->vals[0]; - rulettc = SPI_tuptable->tupdesc; - - /* ---------- - * Get the rules definition and put it into executors memory - * ---------- - */ - tmp = make_ruledef(ruletup, rulettc); - len = strlen(tmp) + VARHDRSZ; - ruledef = SPI_palloc(len); - VARSIZE(ruledef) = len; - memcpy(VARDATA(ruledef), tmp, len - VARHDRSZ); - - /* ---------- - * Disconnect from SPI manager - * ---------- - */ - if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "get_ruledef: SPI_finish() failed"); - - /* ---------- - * Easy - isn't it? - * ---------- - */ - return ruledef; } @@ -198,91 +199,92 @@ pg_get_ruledef(NameData *rname) text * pg_get_viewdef(NameData *rname) { - text *ruledef; - Datum args[2]; - char nulls[3]; - int spirc; - HeapTuple ruletup; - TupleDesc rulettc; - char *tmp; - int len; - char name1[NAMEDATALEN + 5]; - char name2[NAMEDATALEN + 5]; - - /* ---------- - * We need the rules name somewhere deep down - * ---------- - */ - rulename = nameout(rname); - - /* ---------- - * Connect to SPI manager - * ---------- - */ - if (SPI_connect() != SPI_OK_CONNECT) - elog(ERROR, "get_viewdef: cannot connect to SPI manager"); - - /* ---------- - * On the first call prepare the plan to lookup pg_proc. - * We read pg_proc over the SPI manager instead of using - * the syscache to be checked for read access on pg_proc. - * ---------- - */ - if (plan_getview == NULL) { - Oid argtypes[2]; - void *plan; - - argtypes[0] = NAMEOID; - argtypes[1] = NAMEOID; - plan = SPI_prepare(query_getview, 2, argtypes); - if (plan == NULL) - elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getview); - plan_getview = SPI_saveplan(plan); - } - - /* ---------- - * Get the pg_rewrite tuple for this rule - * ---------- - */ - sprintf(name1, "_RET%s", rulename); - sprintf(name2, "_ret%s", rulename); - args[0] = PointerGetDatum(name1); - args[1] = PointerGetDatum(name2); - nulls[0] = ' '; - nulls[1] = ' '; - nulls[2] = '\0'; - spirc = SPI_execp(plan_getview, args, nulls, 1); - if (spirc != SPI_OK_SELECT) { - elog(ERROR, "failed to get pg_rewrite tuple for view %s", rulename); - } - if (SPI_processed != 1) { - tmp = "Not a view"; - } else { + text *ruledef; + Datum args[2]; + char nulls[3]; + int spirc; + HeapTuple ruletup; + TupleDesc rulettc; + char *tmp; + int len; + char name1[NAMEDATALEN + 5]; + char name2[NAMEDATALEN + 5]; + /* ---------- - * Get the rules definition and put it into executors memory + * We need the rules name somewhere deep down * ---------- */ - ruletup = SPI_tuptable->vals[0]; - rulettc = SPI_tuptable->tupdesc; - tmp = make_viewdef(ruletup, rulettc); - } - len = strlen(tmp) + VARHDRSZ; - ruledef = SPI_palloc(len); - VARSIZE(ruledef) = len; - memcpy(VARDATA(ruledef), tmp, len - VARHDRSZ); - - /* ---------- - * Disconnect from SPI manager - * ---------- - */ - if (SPI_finish() != SPI_OK_FINISH) - elog(ERROR, "get_viewdef: SPI_finish() failed"); - - /* ---------- - * Easy - isn't it? - * ---------- - */ - return ruledef; + rulename = nameout(rname); + + /* ---------- + * Connect to SPI manager + * ---------- + */ + if (SPI_connect() != SPI_OK_CONNECT) + elog(ERROR, "get_viewdef: cannot connect to SPI manager"); + + /* ---------- + * On the first call prepare the plan to lookup pg_proc. + * We read pg_proc over the SPI manager instead of using + * the syscache to be checked for read access on pg_proc. + * ---------- + */ + if (plan_getview == NULL) + { + Oid argtypes[2]; + void *plan; + + argtypes[0] = NAMEOID; + argtypes[1] = NAMEOID; + plan = SPI_prepare(query_getview, 2, argtypes); + if (plan == NULL) + elog(ERROR, "SPI_prepare() failed for \"%s\"", query_getview); + plan_getview = SPI_saveplan(plan); + } + + /* ---------- + * Get the pg_rewrite tuple for this rule + * ---------- + */ + sprintf(name1, "_RET%s", rulename); + sprintf(name2, "_ret%s", rulename); + args[0] = PointerGetDatum(name1); + args[1] = PointerGetDatum(name2); + nulls[0] = ' '; + nulls[1] = ' '; + nulls[2] = '\0'; + spirc = SPI_execp(plan_getview, args, nulls, 1); + if (spirc != SPI_OK_SELECT) + elog(ERROR, "failed to get pg_rewrite tuple for view %s", rulename); + if (SPI_processed != 1) + tmp = "Not a view"; + else + { + /* ---------- + * Get the rules definition and put it into executors memory + * ---------- + */ + ruletup = SPI_tuptable->vals[0]; + rulettc = SPI_tuptable->tupdesc; + tmp = make_viewdef(ruletup, rulettc); + } + len = strlen(tmp) + VARHDRSZ; + ruledef = SPI_palloc(len); + VARSIZE(ruledef) = len; + memcpy(VARDATA(ruledef), tmp, len - VARHDRSZ); + + /* ---------- + * Disconnect from SPI manager + * ---------- + */ + if (SPI_finish() != SPI_OK_FINISH) + elog(ERROR, "get_viewdef: SPI_finish() failed"); + + /* ---------- + * Easy - isn't it? + * ---------- + */ + return ruledef; } @@ -294,135 +296,151 @@ pg_get_viewdef(NameData *rname) static char * make_ruledef(HeapTuple ruletup, TupleDesc rulettc) { - char *buf; - char ev_type; - Oid ev_class; - int2 ev_attr; - bool is_instead; - char *ev_qual; - char *ev_action; - List *actions = NIL; - int fno; - bool isnull; - - /* ---------- - * Allocate space for the returned rule definition text - * ---------- - */ - buf = palloc(8192); - - /* ---------- - * Get the attribute values from the rules tuple - * ---------- - */ - fno = SPI_fnumber(rulettc, "ev_type"); - ev_type = (char)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_class"); - ev_class = (Oid)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_attr"); - ev_attr = (int2)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "is_instead"); - is_instead = (bool)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_qual"); - ev_qual = SPI_getvalue(ruletup, rulettc, fno); - if (isnull) ev_qual = NULL; - - fno = SPI_fnumber(rulettc, "ev_action"); - ev_action = SPI_getvalue(ruletup, rulettc, fno); - if (isnull) ev_action = NULL; - if (ev_action != NULL) { - actions = (List *)stringToNode(ev_action); - } - - /* ---------- - * Build the rules definition text - * ---------- - */ - strcpy(buf, "CREATE RULE "); - - /* The rule name */ - strcat(buf, rulename); - strcat(buf, " AS ON "); - - /* The event the rule is fired for */ - switch (ev_type) { - case '1': strcat(buf, "SELECT TO "); + char *buf; + char ev_type; + Oid ev_class; + int2 ev_attr; + bool is_instead; + char *ev_qual; + char *ev_action; + List *actions = NIL; + int fno; + bool isnull; + + /* ---------- + * Allocate space for the returned rule definition text + * ---------- + */ + buf = palloc(8192); + + /* ---------- + * Get the attribute values from the rules tuple + * ---------- + */ + fno = SPI_fnumber(rulettc, "ev_type"); + ev_type = (char) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_class"); + ev_class = (Oid) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_attr"); + ev_attr = (int2) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "is_instead"); + is_instead = (bool) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_qual"); + ev_qual = SPI_getvalue(ruletup, rulettc, fno); + if (isnull) + ev_qual = NULL; + + fno = SPI_fnumber(rulettc, "ev_action"); + ev_action = SPI_getvalue(ruletup, rulettc, fno); + if (isnull) + ev_action = NULL; + if (ev_action != NULL) + actions = (List *) stringToNode(ev_action); + + /* ---------- + * Build the rules definition text + * ---------- + */ + strcpy(buf, "CREATE RULE "); + + /* The rule name */ + strcat(buf, rulename); + strcat(buf, " AS ON "); + + /* The event the rule is fired for */ + switch (ev_type) + { + case '1': + strcat(buf, "SELECT TO "); break; - case '2': strcat(buf, "UPDATE TO "); + case '2': + strcat(buf, "UPDATE TO "); break; - case '3': strcat(buf, "INSERT TO "); + case '3': + strcat(buf, "INSERT TO "); break; - case '4': strcat(buf, "DELETE TO "); + case '4': + strcat(buf, "DELETE TO "); break; - default: - elog(ERROR, "get_ruledef: rule %s has unsupported event type %d", - rulename, ev_type); - break; - } + default: + elog(ERROR, "get_ruledef: rule %s has unsupported event type %d", + rulename, ev_type); + break; + } - /* The relation the rule is fired on */ - strcat(buf, get_relation_name(ev_class)); - if (ev_attr > 0) { - strcat(buf, "."); - strcat(buf, get_attribute_name(ev_class, ev_attr)); - } + /* The relation the rule is fired on */ + strcat(buf, get_relation_name(ev_class)); + if (ev_attr > 0) + { + strcat(buf, "."); + strcat(buf, get_attribute_name(ev_class, ev_attr)); + } - /* If the rule has an event qualification, add it */ - if (ev_qual == NULL) ev_qual = ""; - if (strlen(ev_qual) > 0) { - Node *qual; - Query *query; + /* If the rule has an event qualification, add it */ + if (ev_qual == NULL) + ev_qual = ""; + if (strlen(ev_qual) > 0) + { + Node *qual; + Query *query; - qual = stringToNode(ev_qual); - query = (Query *)lfirst(actions); + qual = stringToNode(ev_qual); + query = (Query *) lfirst(actions); - strcat(buf, " WHERE "); - strcat(buf, get_rule_expr(query->rtable, 0, qual, TRUE)); - } + strcat(buf, " WHERE "); + strcat(buf, get_rule_expr(query->rtable, 0, qual, TRUE)); + } - strcat(buf, " DO "); + strcat(buf, " DO "); - /* The INSTEAD keyword (if so) */ - if (is_instead) - strcat(buf, "INSTEAD "); + /* The INSTEAD keyword (if so) */ + if (is_instead) + strcat(buf, "INSTEAD "); - /* Finally the rules actions */ - if (length(actions) > 1) { - List *action; - Query *query; + /* Finally the rules actions */ + if (length(actions) > 1) + { + List *action; + Query *query; - strcat(buf, "("); - foreach (action, actions) { - query = (Query *)lfirst(action); - strcat(buf, get_query_def(query)); - strcat(buf, "; "); + strcat(buf, "("); + foreach(action, actions) + { + query = (Query *) lfirst(action); + strcat(buf, get_query_def(query)); + strcat(buf, "; "); + } + strcat(buf, ");"); } - strcat(buf, ");"); - } else { - if (length(actions) == 0) { - strcat(buf, "NOTHING;"); - } else { - Query *query; - - query = (Query *)lfirst(actions); - strcat(buf, get_query_def(query)); - strcat(buf, ";"); + else + { + if (length(actions) == 0) + { + strcat(buf, "NOTHING;"); + } + else + { + Query *query; + + query = (Query *) lfirst(actions); + strcat(buf, get_query_def(query)); + strcat(buf, ";"); + } } - } - /* ---------- - * That's it - * ---------- - */ - return buf; + /* ---------- + * That's it + * ---------- + */ + return buf; } @@ -434,61 +452,62 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc) static char * make_viewdef(HeapTuple ruletup, TupleDesc rulettc) { - char buf[8192]; - Query *query; - char ev_type; - Oid ev_class; - int2 ev_attr; - bool is_instead; - char *ev_qual; - char *ev_action; - List *actions = NIL; - int fno; - bool isnull; - - /* ---------- - * Get the attribute values from the rules tuple - * ---------- - */ - fno = SPI_fnumber(rulettc, "ev_type"); - ev_type = (char)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_class"); - ev_class = (Oid)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_attr"); - ev_attr = (int2)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "is_instead"); - is_instead = (bool)SPI_getbinval(ruletup, rulettc, fno, &isnull); - - fno = SPI_fnumber(rulettc, "ev_qual"); - ev_qual = SPI_getvalue(ruletup, rulettc, fno); - if (isnull) ev_qual = ""; - - fno = SPI_fnumber(rulettc, "ev_action"); - ev_action = SPI_getvalue(ruletup, rulettc, fno); - if (isnull) ev_action = NULL; - if (ev_action != NULL) { - actions = (List *)stringToNode(ev_action); - } - - if (length(actions) != 1) - return "Not a view"; - - query = (Query *)lfirst(actions); - - if (ev_type != '1' || ev_attr >= 0 || !is_instead || strcmp(ev_qual, "")) - return "Not a view"; - - strcpy(buf, get_select_query_def(query)); - strcat(buf, ";"); - - /* ---------- - * That's it - * ---------- - */ - return pstrdup(buf); + char buf[8192]; + Query *query; + char ev_type; + Oid ev_class; + int2 ev_attr; + bool is_instead; + char *ev_qual; + char *ev_action; + List *actions = NIL; + int fno; + bool isnull; + + /* ---------- + * Get the attribute values from the rules tuple + * ---------- + */ + fno = SPI_fnumber(rulettc, "ev_type"); + ev_type = (char) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_class"); + ev_class = (Oid) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_attr"); + ev_attr = (int2) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "is_instead"); + is_instead = (bool) SPI_getbinval(ruletup, rulettc, fno, &isnull); + + fno = SPI_fnumber(rulettc, "ev_qual"); + ev_qual = SPI_getvalue(ruletup, rulettc, fno); + if (isnull) + ev_qual = ""; + + fno = SPI_fnumber(rulettc, "ev_action"); + ev_action = SPI_getvalue(ruletup, rulettc, fno); + if (isnull) + ev_action = NULL; + if (ev_action != NULL) + actions = (List *) stringToNode(ev_action); + + if (length(actions) != 1) + return "Not a view"; + + query = (Query *) lfirst(actions); + + if (ev_type != '1' || ev_attr >= 0 || !is_instead || strcmp(ev_qual, "")) + return "Not a view"; + + strcpy(buf, get_select_query_def(query)); + strcat(buf, ";"); + + /* ---------- + * That's it + * ---------- + */ + return pstrdup(buf); } @@ -501,34 +520,35 @@ make_viewdef(HeapTuple ruletup, TupleDesc rulettc) static char * get_query_def(Query *query) { - switch (query->commandType) { - case CMD_SELECT: - return get_select_query_def(query); - break; - - case CMD_UPDATE: - return get_update_query_def(query); - break; - - case CMD_INSERT: - return get_insert_query_def(query); - break; - - case CMD_DELETE: - return get_delete_query_def(query); - break; - - case CMD_NOTHING: - return "NOTHING"; - break; - - default: - elog(ERROR, "get_ruledef of %s: query command type %d not implemented yet", - rulename, query->commandType); - break; - } - - return NULL; + switch (query->commandType) + { + case CMD_SELECT: + return get_select_query_def(query); + break; + + case CMD_UPDATE: + return get_update_query_def(query); + break; + + case CMD_INSERT: + return get_insert_query_def(query); + break; + + case CMD_DELETE: + return get_delete_query_def(query); + break; + + case CMD_NOTHING: + return "NOTHING"; + break; + + default: + elog(ERROR, "get_ruledef of %s: query command type %d not implemented yet", + rulename, query->commandType); + break; + } + + return NULL; } @@ -539,144 +559,162 @@ get_query_def(Query *query) static char * get_select_query_def(Query *query) { - char buf[8192]; - char *sep; - TargetEntry *tle; - RangeTblEntry *rte; - bool *rt_used; - int rt_length; - int rt_numused = 0; - bool rt_constonly = TRUE; - int i; - List *l; - - /* ---------- - * First we need need to know which and how many of the - * range table entries in the query are used in the target list - * or queries qualification - * ---------- - */ - rt_length = length(query->rtable); - rt_used = palloc(sizeof(bool) * rt_length); - for (i = 0; i < rt_length; i++) { - if (check_if_rte_used(i + 1, (Node *)(query->targetList), 0)) { - rt_used[i] = TRUE; - rt_numused++; - } else { - if (check_if_rte_used(i + 1, (Node *)(query->qual), 0)) { - rt_used[i] = TRUE; - rt_numused++; - } else { - rt_used[i] = FALSE; - } - } - } - - /* ---------- - * Now check if any of the used rangetable entries is different - * from *NEW* and *CURRENT*. If so we must omit the FROM clause - * later. - * ---------- - */ - i = 0; - foreach (l, query->rtable) { - if (!rt_used[i++]) - continue; - - rte = (RangeTblEntry *)lfirst(l); - if (!strcmp(rte->refname, "*NEW*")) - continue; - if (!strcmp(rte->refname, "*CURRENT*")) - continue; - - rt_constonly = FALSE; - break; - } - - /* ---------- - * Build up the query string - first we say SELECT - * ---------- - */ - strcpy(buf, "SELECT"); - - /* Then we tell what to select (the targetlist) */ - sep = " "; - foreach (l, query->targetList) { - bool tell_as = FALSE; - - tle = (TargetEntry *)lfirst(l); - strcat(buf, sep); - sep = ", "; - - strcat(buf, get_tle_expr(query->rtable, 0, tle, (rt_numused > 1))); - - /* Check if we must say AS ... */ - if (nodeTag(tle->expr) != T_Var) { - tell_as = strcmp(tle->resdom->resname, "?column?"); - } else { - Var *var = (Var *)(tle->expr); - char *attname; - - rte = (RangeTblEntry *)nth(var->varno - 1, query->rtable); - attname = get_attribute_name(rte->relid, var->varattno); - if (strcmp(attname, tle->resdom->resname)) - tell_as = TRUE; + char buf[8192]; + char *sep; + TargetEntry *tle; + RangeTblEntry *rte; + bool *rt_used; + int rt_length; + int rt_numused = 0; + bool rt_constonly = TRUE; + int i; + List *l; + + /* ---------- + * First we need need to know which and how many of the + * range table entries in the query are used in the target list + * or queries qualification + * ---------- + */ + rt_length = length(query->rtable); + rt_used = palloc(sizeof(bool) * rt_length); + for (i = 0; i < rt_length; i++) + { + if (check_if_rte_used(i + 1, (Node *) (query->targetList), 0)) + { + rt_used[i] = TRUE; + rt_numused++; + } + else + { + if (check_if_rte_used(i + 1, (Node *) (query->qual), 0)) + { + rt_used[i] = TRUE; + rt_numused++; + } + else + rt_used[i] = FALSE; + } } - /* and do if so */ - if (tell_as) { - strcat(buf, " AS "); - strcat(buf, tle->resdom->resname); + /* ---------- + * Now check if any of the used rangetable entries is different + * from *NEW* and *CURRENT*. If so we must omit the FROM clause + * later. + * ---------- + */ + i = 0; + foreach(l, query->rtable) + { + if (!rt_used[i++]) + continue; + + rte = (RangeTblEntry *) lfirst(l); + if (!strcmp(rte->refname, "*NEW*")) + continue; + if (!strcmp(rte->refname, "*CURRENT*")) + continue; + + rt_constonly = FALSE; + break; } - } - /* If we need other tables that *NEW* or *CURRENT* add the FROM clause */ - if (!rt_constonly && rt_numused > 0) { - strcat(buf, " FROM"); + /* ---------- + * Build up the query string - first we say SELECT + * ---------- + */ + strcpy(buf, "SELECT"); - i = 0; + /* Then we tell what to select (the targetlist) */ sep = " "; - foreach (l, query->rtable) { - if (rt_used[i++]) { - rte = (RangeTblEntry *)lfirst(l); + foreach(l, query->targetList) + { + bool tell_as = FALSE; - if (!strcmp(rte->refname, "*NEW*")) - continue; + tle = (TargetEntry *) lfirst(l); + strcat(buf, sep); + sep = ", "; - if (!strcmp(rte->refname, "*CURRENT*")) - continue; + strcat(buf, get_tle_expr(query->rtable, 0, tle, (rt_numused > 1))); - strcat(buf, sep); sep = ", "; - strcat(buf, rte->relname); - if (rt_numused > 1) { - strcat(buf, " "); - strcat(buf, rte->refname); + /* Check if we must say AS ... */ + if (nodeTag(tle->expr) != T_Var) + tell_as = strcmp(tle->resdom->resname, "?column?"); + else + { + Var *var = (Var *) (tle->expr); + char *attname; + + rte = (RangeTblEntry *) nth(var->varno - 1, query->rtable); + attname = get_attribute_name(rte->relid, var->varattno); + if (strcmp(attname, tle->resdom->resname)) + tell_as = TRUE; + } + + /* and do if so */ + if (tell_as) + { + strcat(buf, " AS "); + strcat(buf, tle->resdom->resname); } - } } - } - /* Add the WHERE clause if given */ - if (query->qual != NULL) { - strcat(buf, " WHERE "); - strcat(buf, get_rule_expr(query->rtable, 0, query->qual, (rt_numused > 1))); - } + /* If we need other tables that *NEW* or *CURRENT* add the FROM clause */ + if (!rt_constonly && rt_numused > 0) + { + strcat(buf, " FROM"); - /* Add the GROUP BY CLAUSE */ - if (query->groupClause != NULL) { - strcat(buf, " GROUP BY "); - sep = ""; - foreach (l, query->groupClause) { - strcat(buf, sep); sep = ", "; - strcat(buf, get_rule_expr(query->rtable, 0, lfirst(l), (rt_numused > 1))); + i = 0; + sep = " "; + foreach(l, query->rtable) + { + if (rt_used[i++]) + { + rte = (RangeTblEntry *) lfirst(l); + + if (!strcmp(rte->refname, "*NEW*")) + continue; + + if (!strcmp(rte->refname, "*CURRENT*")) + continue; + + strcat(buf, sep); + sep = ", "; + strcat(buf, rte->relname); + if (rt_numused > 1) + { + strcat(buf, " "); + strcat(buf, rte->refname); + } + } + } + } + + /* Add the WHERE clause if given */ + if (query->qual != NULL) + { + strcat(buf, " WHERE "); + strcat(buf, get_rule_expr(query->rtable, 0, query->qual, (rt_numused > 1))); + } + + /* Add the GROUP BY CLAUSE */ + if (query->groupClause != NULL) + { + strcat(buf, " GROUP BY "); + sep = ""; + foreach(l, query->groupClause) + { + strcat(buf, sep); + sep = ", "; + strcat(buf, get_rule_expr(query->rtable, 0, lfirst(l), (rt_numused > 1))); + } } - } - /* ---------- - * Copy the query string into allocated space and return it - * ---------- - */ - return pstrdup(buf); + /* ---------- + * Copy the query string into allocated space and return it + * ---------- + */ + return pstrdup(buf); } @@ -687,92 +725,103 @@ get_select_query_def(Query *query) static char * get_insert_query_def(Query *query) { - char buf[8192]; - char *sep; - TargetEntry *tle; - RangeTblEntry *rte; - bool *rt_used; - int rt_length; - int rt_numused = 0; - bool rt_constonly = TRUE; - int i; - List *l; - - /* ---------- - * We need to know if other tables than *NEW* or *CURRENT* - * are used in the query. If not, it's an INSERT ... VALUES, - * otherwise an INSERT ... SELECT. - * ---------- - */ - rt_length = length(query->rtable); - rt_used = palloc(sizeof(bool) * rt_length); - for (i = 0; i < rt_length; i++) { - if (check_if_rte_used(i + 1, (Node *)(query->targetList), 0)) { - rt_used[i] = TRUE; - rt_numused++; - } else { - if (check_if_rte_used(i + 1, (Node *)(query->qual), 0)) { - rt_used[i] = TRUE; - rt_numused++; - } else { - rt_used[i] = FALSE; - } + char buf[8192]; + char *sep; + TargetEntry *tle; + RangeTblEntry *rte; + bool *rt_used; + int rt_length; + int rt_numused = 0; + bool rt_constonly = TRUE; + int i; + List *l; + + /* ---------- + * We need to know if other tables than *NEW* or *CURRENT* + * are used in the query. If not, it's an INSERT ... VALUES, + * otherwise an INSERT ... SELECT. + * ---------- + */ + rt_length = length(query->rtable); + rt_used = palloc(sizeof(bool) * rt_length); + for (i = 0; i < rt_length; i++) + { + if (check_if_rte_used(i + 1, (Node *) (query->targetList), 0)) + { + rt_used[i] = TRUE; + rt_numused++; + } + else + { + if (check_if_rte_used(i + 1, (Node *) (query->qual), 0)) + { + rt_used[i] = TRUE; + rt_numused++; + } + else + rt_used[i] = FALSE; + } } - } - - i = 0; - foreach (l, query->rtable) { - if (!rt_used[i++]) - continue; - - rte = (RangeTblEntry *)lfirst(l); - if (!strcmp(rte->refname, "*NEW*")) - continue; - if (!strcmp(rte->refname, "*CURRENT*")) - continue; - - rt_constonly = FALSE; - break; - } - - /* ---------- - * Start the query with INSERT INTO relname - * ---------- - */ - rte = (RangeTblEntry *)nth(query->resultRelation - 1, query->rtable); - strcpy(buf, "INSERT INTO "); - strcat(buf, rte->relname); - - /* Add the target list */ - sep = " ("; - foreach (l, query->targetList) { - tle = (TargetEntry *)lfirst(l); - - strcat(buf, sep); sep = ", "; - strcat(buf, tle->resdom->resname); - } - strcat(buf, ") "); - - /* Add the VALUES or the SELECT */ - if (rt_constonly && query->qual == NULL) { - strcat(buf, "VALUES ("); - sep = ""; - foreach (l, query->targetList) { - tle = (TargetEntry *)lfirst(l); - strcat(buf, sep); sep = ", "; - strcat(buf, get_tle_expr(query->rtable, 0, tle, (rt_numused > 1))); + i = 0; + foreach(l, query->rtable) + { + if (!rt_used[i++]) + continue; + + rte = (RangeTblEntry *) lfirst(l); + if (!strcmp(rte->refname, "*NEW*")) + continue; + if (!strcmp(rte->refname, "*CURRENT*")) + continue; + + rt_constonly = FALSE; + break; } - strcat(buf, ")"); - } else { - strcat(buf, get_select_query_def(query)); - } - - /* ---------- - * Copy the query string into allocated space and return it - * ---------- - */ - return pstrdup(buf); + + /* ---------- + * Start the query with INSERT INTO relname + * ---------- + */ + rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable); + strcpy(buf, "INSERT INTO "); + strcat(buf, rte->relname); + + /* Add the target list */ + sep = " ("; + foreach(l, query->targetList) + { + tle = (TargetEntry *) lfirst(l); + + strcat(buf, sep); + sep = ", "; + strcat(buf, tle->resdom->resname); + } + strcat(buf, ") "); + + /* Add the VALUES or the SELECT */ + if (rt_constonly && query->qual == NULL) + { + strcat(buf, "VALUES ("); + sep = ""; + foreach(l, query->targetList) + { + tle = (TargetEntry *) lfirst(l); + + strcat(buf, sep); + sep = ", "; + strcat(buf, get_tle_expr(query->rtable, 0, tle, (rt_numused > 1))); + } + strcat(buf, ")"); + } + else + strcat(buf, get_select_query_def(query)); + + /* ---------- + * Copy the query string into allocated space and return it + * ---------- + */ + return pstrdup(buf); } @@ -783,45 +832,48 @@ get_insert_query_def(Query *query) static char * get_update_query_def(Query *query) { - char buf[8192]; - char *sep; - TargetEntry *tle; - RangeTblEntry *rte; - List *l; - - /* ---------- - * Start the query with UPDATE relname SET - * ---------- - */ - rte = (RangeTblEntry *)nth(query->resultRelation - 1, query->rtable); - strcpy(buf, "UPDATE "); - strcat(buf, rte->relname); - strcat(buf, " SET "); - - /* Add the comma separated list of 'attname = value' */ - sep = ""; - foreach (l, query->targetList) { - tle = (TargetEntry *)lfirst(l); - - strcat(buf, sep); sep = ", "; - strcat(buf, tle->resdom->resname); - strcat(buf, " = "); - strcat(buf, get_tle_expr(query->rtable, query->resultRelation, - tle, TRUE)); - } - - /* Finally add a WHERE clause if given */ - if (query->qual != NULL) { - strcat(buf, " WHERE "); - strcat(buf, get_rule_expr(query->rtable, query->resultRelation, - query->qual, TRUE)); - } - - /* ---------- - * Copy the query string into allocated space and return it - * ---------- - */ - return pstrdup(buf); + char buf[8192]; + char *sep; + TargetEntry *tle; + RangeTblEntry *rte; + List *l; + + /* ---------- + * Start the query with UPDATE relname SET + * ---------- + */ + rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable); + strcpy(buf, "UPDATE "); + strcat(buf, rte->relname); + strcat(buf, " SET "); + + /* Add the comma separated list of 'attname = value' */ + sep = ""; + foreach(l, query->targetList) + { + tle = (TargetEntry *) lfirst(l); + + strcat(buf, sep); + sep = ", "; + strcat(buf, tle->resdom->resname); + strcat(buf, " = "); + strcat(buf, get_tle_expr(query->rtable, query->resultRelation, + tle, TRUE)); + } + + /* Finally add a WHERE clause if given */ + if (query->qual != NULL) + { + strcat(buf, " WHERE "); + strcat(buf, get_rule_expr(query->rtable, query->resultRelation, + query->qual, TRUE)); + } + + /* ---------- + * Copy the query string into allocated space and return it + * ---------- + */ + return pstrdup(buf); } @@ -832,28 +884,29 @@ get_update_query_def(Query *query) static char * get_delete_query_def(Query *query) { - char buf[8192]; - RangeTblEntry *rte; - - /* ---------- - * Start the query with DELETE FROM relname - * ---------- - */ - rte = (RangeTblEntry *)nth(query->resultRelation - 1, query->rtable); - strcpy(buf, "DELETE FROM "); - strcat(buf, rte->relname); - - /* Add a WHERE clause if given */ - if (query->qual != NULL) { - strcat(buf, " WHERE "); - strcat(buf, get_rule_expr(query->rtable, 0, query->qual, FALSE)); - } - - /* ---------- - * Copy the query string into allocated space and return it - * ---------- - */ - return pstrdup(buf); + char buf[8192]; + RangeTblEntry *rte; + + /* ---------- + * Start the query with DELETE FROM relname + * ---------- + */ + rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable); + strcpy(buf, "DELETE FROM "); + strcat(buf, rte->relname); + + /* Add a WHERE clause if given */ + if (query->qual != NULL) + { + strcat(buf, " WHERE "); + strcat(buf, get_rule_expr(query->rtable, 0, query->qual, FALSE)); + } + + /* ---------- + * Copy the query string into allocated space and return it + * ---------- + */ + return pstrdup(buf); } @@ -864,191 +917,197 @@ get_delete_query_def(Query *query) static char * get_rule_expr(List *rtable, int rt_index, Node *node, bool varprefix) { - char buf[8192]; + char buf[8192]; - if (node == NULL) - return pstrdup(""); + if (node == NULL) + return pstrdup(""); - buf[0] = '\0'; + buf[0] = '\0'; - /* ---------- - * Up to now I don't know if all the node types below - * can really occur in rules actions and qualifications. - * There might be some work left. - * ---------- - */ - switch(nodeTag(node)) { - case T_TargetEntry: - { - TargetEntry *tle = (TargetEntry *)node; - - return get_rule_expr(rtable, rt_index, - (Node *)(tle->expr), varprefix); - } - break; - - case T_Aggreg: - { - Aggreg *agg = (Aggreg *)node; - - strcat(buf, agg->aggname); - strcat(buf, "("); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)(agg->target), varprefix)); - strcat(buf, ")"); - return pstrdup(buf); - } - break; - - case T_GroupClause: - { - GroupClause *grp = (GroupClause *)node; + /* ---------- + * Up to now I don't know if all the node types below + * can really occur in rules actions and qualifications. + * There might be some work left. + * ---------- + */ + switch (nodeTag(node)) + { + case T_TargetEntry: + { + TargetEntry *tle = (TargetEntry *) node; + + return get_rule_expr(rtable, rt_index, + (Node *) (tle->expr), varprefix); + } + break; - return get_rule_expr(rtable, rt_index, - (Node *)(grp->entry), varprefix); - } - break; + case T_Aggreg: + { + Aggreg *agg = (Aggreg *) node; - case T_Expr: - { - Expr *expr = (Expr *)node; - - /* ---------- - * Expr nodes have to be handled a bit detailed - * ---------- - */ - switch (expr->opType) { - case OP_EXPR: - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_leftop(expr), - varprefix)); - strcat(buf, " "); - strcat(buf, get_opname(((Oper *)expr->oper)->opno)); - strcat(buf, " "); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_rightop(expr), - varprefix)); - return pstrdup(buf); - break; - - case OR_EXPR: + strcat(buf, agg->aggname); strcat(buf, "("); strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_leftop(expr), - varprefix)); - strcat(buf, ") OR ("); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_rightop(expr), - varprefix)); + (Node *) (agg->target), varprefix)); strcat(buf, ")"); return pstrdup(buf); - break; - - case AND_EXPR: - strcat(buf, "("); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_leftop(expr), - varprefix)); - strcat(buf, ") AND ("); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_rightop(expr), - varprefix)); - strcat(buf, ")"); - return pstrdup(buf); - break; - - case NOT_EXPR: - strcat(buf, "NOT ("); - strcat(buf, get_rule_expr(rtable, rt_index, - (Node *)get_leftop(expr), - varprefix)); - strcat(buf, ")"); - return pstrdup(buf); - break; + } + break; - case FUNC_EXPR: - return get_func_expr(rtable, rt_index, - (Expr *)node, - varprefix); - break; + case T_GroupClause: + { + GroupClause *grp = (GroupClause *) node; - default: - printf("\n%s\n", nodeToString(node)); - elog(ERROR, "Expr not yet supported"); - } - } - break; + return get_rule_expr(rtable, rt_index, + (Node *) (grp->entry), varprefix); + } + break; - case T_Var: - { - Var *var = (Var *)node; - RangeTblEntry *rte = (RangeTblEntry *)nth(var->varno - 1, rtable); - - if (!strcmp(rte->refname, "*NEW*")) { - strcat(buf, "new."); - } else { - if (!strcmp(rte->refname, "*CURRENT*")) { - strcat(buf, "current."); - } else { - if (varprefix && var->varno != rt_index) { - strcat(buf, rte->refname); - strcat(buf, "."); + case T_Expr: + { + Expr *expr = (Expr *) node; + + /* ---------- + * Expr nodes have to be handled a bit detailed + * ---------- + */ + switch (expr->opType) + { + case OP_EXPR: + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_leftop(expr), + varprefix)); + strcat(buf, " "); + strcat(buf, get_opname(((Oper *) expr->oper)->opno)); + strcat(buf, " "); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_rightop(expr), + varprefix)); + return pstrdup(buf); + break; + + case OR_EXPR: + strcat(buf, "("); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_leftop(expr), + varprefix)); + strcat(buf, ") OR ("); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_rightop(expr), + varprefix)); + strcat(buf, ")"); + return pstrdup(buf); + break; + + case AND_EXPR: + strcat(buf, "("); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_leftop(expr), + varprefix)); + strcat(buf, ") AND ("); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_rightop(expr), + varprefix)); + strcat(buf, ")"); + return pstrdup(buf); + break; + + case NOT_EXPR: + strcat(buf, "NOT ("); + strcat(buf, get_rule_expr(rtable, rt_index, + (Node *) get_leftop(expr), + varprefix)); + strcat(buf, ")"); + return pstrdup(buf); + break; + + case FUNC_EXPR: + return get_func_expr(rtable, rt_index, + (Expr *) node, + varprefix); + break; + + default: + printf("\n%s\n", nodeToString(node)); + elog(ERROR, "Expr not yet supported"); } - } } - strcat(buf, get_attribute_name(rte->relid, var->varattno)); + break; - return pstrdup(buf); - } - break; + case T_Var: + { + Var *var = (Var *) node; + RangeTblEntry *rte = (RangeTblEntry *) nth(var->varno - 1, rtable); + + if (!strcmp(rte->refname, "*NEW*")) + strcat(buf, "new."); + else + { + if (!strcmp(rte->refname, "*CURRENT*")) + strcat(buf, "current."); + else + { + if (varprefix && var->varno != rt_index) + { + strcat(buf, rte->refname); + strcat(buf, "."); + } + } + } + strcat(buf, get_attribute_name(rte->relid, var->varattno)); - case T_List: - { - printf("\n%s\n", nodeToString(node)); - elog(ERROR, "List not yet supported"); - } - break; + return pstrdup(buf); + } + break; - case T_SubLink: - { - SubLink *sublink = (SubLink *)node; - Query *query = (Query *)(sublink->subselect); - List *l; - char *sep; - - if (sublink->lefthand != NULL) { - strcat(buf, "("); - sep = ""; - foreach (l, sublink->lefthand) { - strcat(buf, sep); sep = ", "; - strcat(buf, get_rule_expr(rtable, rt_index, - lfirst(l), varprefix)); - } - strcat(buf, ") IN "); + case T_List: + { + printf("\n%s\n", nodeToString(node)); + elog(ERROR, "List not yet supported"); } + break; - strcat(buf, "("); - strcat(buf, get_query_def(query)); - strcat(buf, ")"); + case T_SubLink: + { + SubLink *sublink = (SubLink *) node; + Query *query = (Query *) (sublink->subselect); + List *l; + char *sep; + + if (sublink->lefthand != NULL) + { + strcat(buf, "("); + sep = ""; + foreach(l, sublink->lefthand) + { + strcat(buf, sep); + sep = ", "; + strcat(buf, get_rule_expr(rtable, rt_index, + lfirst(l), varprefix)); + } + strcat(buf, ") IN "); + } - return pstrdup(buf); - } - break; + strcat(buf, "("); + strcat(buf, get_query_def(query)); + strcat(buf, ")"); - case T_Const: - { - return get_const_expr((Const *)node); - } - break; + return pstrdup(buf); + } + break; - default: - printf("\n%s\n", nodeToString(node)); - elog(ERROR, "get_ruledef of %s: unknown node type %d get_rule_expr()", - rulename, nodeTag(node)); - break; - } + case T_Const: + return get_const_expr((Const *) node); + break; - return FALSE; + default: + printf("\n%s\n", nodeToString(node)); + elog(ERROR, "get_ruledef of %s: unknown node type %d get_rule_expr()", + rulename, nodeTag(node)); + break; + } + + return FALSE; } @@ -1059,61 +1118,66 @@ get_rule_expr(List *rtable, int rt_index, Node *node, bool varprefix) static char * get_func_expr(List *rtable, int rt_index, Expr *expr, bool varprefix) { - char buf[8192]; - HeapTuple proctup; - Form_pg_proc procStruct; - List *l; - char *sep; - Func *func = (Func *)(expr->oper); - char *proname; - - /* ---------- - * Get the functions pg_proc tuple - * ---------- - */ - proctup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(func->funcid), 0, 0, 0); - if (!HeapTupleIsValid(proctup)) - elog(ERROR, "cache lookup for proc %d failed", func->funcid); - - procStruct = (Form_pg_proc) GETSTRUCT(proctup); - proname = nameout(&(procStruct->proname)); - - if (procStruct->pronargs == 1 && procStruct->proargtypes[0] == InvalidOid) { - if (!strcmp(proname, "nullvalue")) { - strcpy(buf, "("); - strcat(buf, get_rule_expr(rtable, rt_index, lfirst(expr->args), - varprefix)); - strcat(buf, ") ISNULL"); - return pstrdup(buf); + char buf[8192]; + HeapTuple proctup; + Form_pg_proc procStruct; + List *l; + char *sep; + Func *func = (Func *) (expr->oper); + char *proname; + + /* ---------- + * Get the functions pg_proc tuple + * ---------- + */ + proctup = SearchSysCacheTuple(PROOID, + ObjectIdGetDatum(func->funcid), 0, 0, 0); + if (!HeapTupleIsValid(proctup)) + elog(ERROR, "cache lookup for proc %d failed", func->funcid); + + procStruct = (Form_pg_proc) GETSTRUCT(proctup); + proname = nameout(&(procStruct->proname)); + + if (procStruct->pronargs == 1 && procStruct->proargtypes[0] == InvalidOid) + { + if (!strcmp(proname, "nullvalue")) + { + strcpy(buf, "("); + strcat(buf, get_rule_expr(rtable, rt_index, lfirst(expr->args), + varprefix)); + strcat(buf, ") ISNULL"); + return pstrdup(buf); + } + if (!strcmp(proname, "nonnullvalue")) + { + strcpy(buf, "("); + strcat(buf, get_rule_expr(rtable, rt_index, lfirst(expr->args), + varprefix)); + strcat(buf, ") NOTNULL"); + return pstrdup(buf); + } } - if (!strcmp(proname, "nonnullvalue")) { - strcpy(buf, "("); - strcat(buf, get_rule_expr(rtable, rt_index, lfirst(expr->args), - varprefix)); - strcat(buf, ") NOTNULL"); - return pstrdup(buf); + + /* ---------- + * Build a string of proname(args) + * ---------- + */ + strcpy(buf, proname); + strcat(buf, "("); + sep = ""; + foreach(l, expr->args) + { + strcat(buf, sep); + sep = ", "; + strcat(buf, get_rule_expr(rtable, rt_index, lfirst(l), varprefix)); } - } - - /* ---------- - * Build a string of proname(args) - * ---------- - */ - strcpy(buf, proname); - strcat(buf, "("); - sep = ""; - foreach (l, expr->args) { - strcat(buf, sep); sep = ", "; - strcat(buf, get_rule_expr(rtable, rt_index, lfirst(l), varprefix)); - } - strcat(buf, ")"); - - /* ---------- - * Copy the function call string into allocated space and return it - * ---------- - */ - return pstrdup(buf); + strcat(buf, ")"); + + /* ---------- + * Copy the function call string into allocated space and return it + * ---------- + */ + return pstrdup(buf); } @@ -1132,75 +1196,67 @@ get_func_expr(List *rtable, int rt_index, Expr *expr, bool varprefix) static char * get_tle_expr(List *rtable, int rt_index, TargetEntry *tle, bool varprefix) { - HeapTuple proctup; - Form_pg_proc procStruct; - Expr *expr; - Func *func; - Const *second_arg; - - /* ---------- - * Check if the result has an atttypmod and if the - * expression in the targetlist entry is a function call - * ---------- - */ - if (tle->resdom->restypmod < 0) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - if (nodeTag(tle->expr) != T_Expr) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - expr = (Expr *)(tle->expr); - if (expr->opType != FUNC_EXPR) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - - func = (Func *)(expr->oper); - - /* ---------- - * Get the functions pg_proc tuple - * ---------- - */ - proctup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(func->funcid), 0, 0, 0); - if (!HeapTupleIsValid(proctup)) - elog(ERROR, "cache lookup for proc %d failed", func->funcid); - - procStruct = (Form_pg_proc) GETSTRUCT(proctup); - - /* ---------- - * It must be a function with two arguments where the first - * is of the same type as the return value and the second is - * an int4. - * ---------- - */ - if (procStruct->pronargs != 2) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - if (procStruct->prorettype != procStruct->proargtypes[0]) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - if (procStruct->proargtypes[1] != INT4OID) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - - /* ---------- - * Finally (to be totally safe) the second argument must be a - * const and match the value in the results atttypmod. - * ---------- - */ - second_arg = (Const *)nth(1, expr->args); - if (nodeTag((Node *)second_arg) != T_Const) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - if ((int4)(second_arg->constvalue) != tle->resdom->restypmod) { - return get_rule_expr(rtable, rt_index, tle->expr, varprefix); - } - - /* ---------- - * Whow - got it. Now get rid of the padding function - * ---------- - */ - return get_rule_expr(rtable, rt_index, lfirst(expr->args), varprefix); + HeapTuple proctup; + Form_pg_proc procStruct; + Expr *expr; + Func *func; + Const *second_arg; + + /* ---------- + * Check if the result has an atttypmod and if the + * expression in the targetlist entry is a function call + * ---------- + */ + if (tle->resdom->restypmod < 0) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + if (nodeTag(tle->expr) != T_Expr) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + expr = (Expr *) (tle->expr); + if (expr->opType != FUNC_EXPR) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + + func = (Func *) (expr->oper); + + /* ---------- + * Get the functions pg_proc tuple + * ---------- + */ + proctup = SearchSysCacheTuple(PROOID, + ObjectIdGetDatum(func->funcid), 0, 0, 0); + if (!HeapTupleIsValid(proctup)) + elog(ERROR, "cache lookup for proc %d failed", func->funcid); + + procStruct = (Form_pg_proc) GETSTRUCT(proctup); + + /* ---------- + * It must be a function with two arguments where the first + * is of the same type as the return value and the second is + * an int4. + * ---------- + */ + if (procStruct->pronargs != 2) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + if (procStruct->prorettype != procStruct->proargtypes[0]) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + if (procStruct->proargtypes[1] != INT4OID) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + + /* ---------- + * Finally (to be totally safe) the second argument must be a + * const and match the value in the results atttypmod. + * ---------- + */ + second_arg = (Const *) nth(1, expr->args); + if (nodeTag((Node *) second_arg) != T_Const) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + if ((int4) (second_arg->constvalue) != tle->resdom->restypmod) + return get_rule_expr(rtable, rt_index, tle->expr, varprefix); + + /* ---------- + * Whow - got it. Now get rid of the padding function + * ---------- + */ + return get_rule_expr(rtable, rt_index, lfirst(expr->args), varprefix); } @@ -1212,29 +1268,29 @@ get_tle_expr(List *rtable, int rt_index, TargetEntry *tle, bool varprefix) char * get_const_expr(Const *constval) { - HeapTuple typetup; - Form_pg_type typeStruct; - FmgrInfo finfo_output; - char *extval; - bool isnull = FALSE; - char buf[8192]; + HeapTuple typetup; + Form_pg_type typeStruct; + FmgrInfo finfo_output; + char *extval; + bool isnull = FALSE; + char buf[8192]; - if (constval->constisnull) - return "NULL"; + if (constval->constisnull) + return "NULL"; - typetup = SearchSysCacheTuple(TYPOID, - ObjectIdGetDatum(constval->consttype), 0, 0, 0); - if (!HeapTupleIsValid(typetup)) - elog(ERROR, "cache lookup of type %d failed", constval->consttype); + typetup = SearchSysCacheTuple(TYPOID, + ObjectIdGetDatum(constval->consttype), 0, 0, 0); + if (!HeapTupleIsValid(typetup)) + elog(ERROR, "cache lookup of type %d failed", constval->consttype); - typeStruct = (Form_pg_type) GETSTRUCT(typetup); + typeStruct = (Form_pg_type) GETSTRUCT(typetup); - fmgr_info(typeStruct->typoutput, &finfo_output); - extval = (char *)(*fmgr_faddr(&finfo_output))(constval->constvalue, - &isnull, -1); + fmgr_info(typeStruct->typoutput, &finfo_output); + extval = (char *) (*fmgr_faddr(&finfo_output)) (constval->constvalue, + &isnull, -1); - sprintf(buf, "'%s'::%s", extval, nameout(&(typeStruct->typname))); - return pstrdup(buf); + sprintf(buf, "'%s'::%s", extval, nameout(&(typeStruct->typname))); + return pstrdup(buf); } @@ -1245,16 +1301,16 @@ get_const_expr(Const *constval) static char * get_relation_name(Oid relid) { - HeapTuple classtup; - Form_pg_class classStruct; + HeapTuple classtup; + Form_pg_class classStruct; - classtup = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(relid), 0, 0, 0); - if (!HeapTupleIsValid(classtup)) - elog(ERROR, "cache lookup of relation %d failed", relid); + classtup = SearchSysCacheTuple(RELOID, + ObjectIdGetDatum(relid), 0, 0, 0); + if (!HeapTupleIsValid(classtup)) + elog(ERROR, "cache lookup of relation %d failed", relid); - classStruct = (Form_pg_class) GETSTRUCT(classtup); - return nameout(&(classStruct->relname)); + classStruct = (Form_pg_class) GETSTRUCT(classtup); + return nameout(&(classStruct->relname)); } @@ -1266,17 +1322,17 @@ get_relation_name(Oid relid) static char * get_attribute_name(Oid relid, int2 attnum) { - HeapTuple atttup; - Form_pg_attribute attStruct; + HeapTuple atttup; + Form_pg_attribute attStruct; - atttup = SearchSysCacheTuple(ATTNUM, - ObjectIdGetDatum(relid), (Datum)attnum, 0, 0); - if (!HeapTupleIsValid(atttup)) - elog(ERROR, "cache lookup of attribute %d in relation %d failed", - attnum, relid); + atttup = SearchSysCacheTuple(ATTNUM, + ObjectIdGetDatum(relid), (Datum) attnum, 0, 0); + if (!HeapTupleIsValid(atttup)) + elog(ERROR, "cache lookup of attribute %d in relation %d failed", + attnum, relid); - attStruct = (Form_pg_attribute) GETSTRUCT(atttup); - return nameout(&(attStruct->attname)); + attStruct = (Form_pg_attribute) GETSTRUCT(atttup); + return nameout(&(attStruct->attname)); } @@ -1289,88 +1345,92 @@ get_attribute_name(Oid relid, int2 attnum) static bool check_if_rte_used(int rt_index, Node *node, int sup) { - if (node == NULL) - return FALSE; + if (node == NULL) + return FALSE; - switch(nodeTag(node)) { - case T_TargetEntry: - { - TargetEntry *tle = (TargetEntry *)node; + switch (nodeTag(node)) + { + case T_TargetEntry: + { + TargetEntry *tle = (TargetEntry *) node; - return check_if_rte_used(rt_index, - (Node *)(tle->expr), sup); - } - break; + return check_if_rte_used(rt_index, + (Node *) (tle->expr), sup); + } + break; - case T_Aggreg: - { - Aggreg *agg = (Aggreg *)node; - return check_if_rte_used(rt_index, - (Node *)(agg->target), sup); - } - break; + case T_Aggreg: + { + Aggreg *agg = (Aggreg *) node; - case T_GroupClause: - { - GroupClause *grp = (GroupClause *)node; - return check_if_rte_used(rt_index, - (Node *)(grp->entry), sup); - } - break; + return check_if_rte_used(rt_index, + (Node *) (agg->target), sup); + } + break; - case T_Expr: - { - Expr *expr = (Expr *)node; - return check_if_rte_used(rt_index, - (Node *)(expr->args), sup); - } - break; + case T_GroupClause: + { + GroupClause *grp = (GroupClause *) node; - case T_Var: - { - Var *var = (Var *)node; - return var->varno == rt_index && var->varlevelsup == sup; - } - break; + return check_if_rte_used(rt_index, + (Node *) (grp->entry), sup); + } + break; - case T_List: - { - List *l; + case T_Expr: + { + Expr *expr = (Expr *) node; - foreach (l, (List *)node) { - if (check_if_rte_used(rt_index, lfirst(l), sup)) - return TRUE; + return check_if_rte_used(rt_index, + (Node *) (expr->args), sup); } - return FALSE; - } - break; + break; - case T_SubLink: - { - SubLink *sublink = (SubLink *)node; - Query *query = (Query *)sublink->subselect; + case T_Var: + { + Var *var = (Var *) node; - if (check_if_rte_used(rt_index, (Node *)(query->qual), sup + 1)) - return TRUE; + return var->varno == rt_index && var->varlevelsup == sup; + } + break; - if (check_if_rte_used(rt_index, (Node *)(sublink->lefthand), sup)) - return TRUE; + case T_List: + { + List *l; - return FALSE; - } - break; + foreach(l, (List *) node) + { + if (check_if_rte_used(rt_index, lfirst(l), sup)) + return TRUE; + } + return FALSE; + } + break; - case T_Const: - return FALSE; - break; + case T_SubLink: + { + SubLink *sublink = (SubLink *) node; + Query *query = (Query *) sublink->subselect; - default: - elog(ERROR, "get_ruledef of %s: unknown node type %d in check_if_rte_used()", - rulename, nodeTag(node)); - break; - } + if (check_if_rte_used(rt_index, (Node *) (query->qual), sup + 1)) + return TRUE; - return FALSE; -} + if (check_if_rte_used(rt_index, (Node *) (sublink->lefthand), sup)) + return TRUE; + + return FALSE; + } + break; + case T_Const: + return FALSE; + break; + + default: + elog(ERROR, "get_ruledef of %s: unknown node type %d in check_if_rte_used()", + rulename, nodeTag(node)); + break; + } + return FALSE; +} diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 6389dc4b0d8..c8dfc204420 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.22 1998/09/01 03:26:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.23 1998/09/01 04:32:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,8 +41,7 @@ #define FunctionalSelectivity(nIndKeys,attNum) (attNum==InvalidAttrNumber) static float32data getattdisbursion(Oid relid, AttrNumber attnum); -static void -gethilokey(Oid relid, AttrNumber attnum, Oid opid, +static void gethilokey(Oid relid, AttrNumber attnum, Oid opid, char **high, char **low); diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index 588876dadde..54aadc407c5 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.17 1998/09/01 03:26:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.18 1998/09/01 04:32:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -112,8 +112,8 @@ SetDefine(char *querystr, char *typename) RelationSetLockForWrite(procrel); tup = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(setoid), - 0, 0, 0); + ObjectIdGetDatum(setoid), + 0, 0, 0); if (HeapTupleIsValid(tup)) { newtup = heap_modifytuple(tup, diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 9f76c7c61a7..6f8f82d8406 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.38 1998/09/01 03:26:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.39 1998/09/01 04:32:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -137,7 +137,8 @@ bpchar(char *s, int32 len) { char *result, *r; - int rlen, slen; + int rlen, + slen; int i; if (s == NULL) @@ -152,8 +153,8 @@ bpchar(char *s, int32 len) elog(ERROR, "bpchar: length of char() must be less than 4096"); #ifdef STRINGDEBUG -printf("bpchar- convert string length %d (%d) ->%d (%d)\n", - VARSIZE(s)-VARHDRSZ, VARSIZE(s), rlen, len); + printf("bpchar- convert string length %d (%d) ->%d (%d)\n", + VARSIZE(s) - VARHDRSZ, VARSIZE(s), rlen, len); #endif result = (char *) palloc(len); @@ -163,7 +164,7 @@ printf("bpchar- convert string length %d (%d) ->%d (%d)\n", s = VARDATA(s); #ifdef STRINGDEBUG -printf("bpchar- string is '"); + printf("bpchar- string is '"); #endif for (i = 0; (i < rlen) && (i < slen); i++) @@ -172,14 +173,14 @@ printf("bpchar- string is '"); break; #ifdef STRINGDEBUG -printf("%c", *s); + printf("%c", *s); #endif *r++ = *s++; } #ifdef STRINGDEBUG -printf("'\n"); + printf("'\n"); #endif /* blank pad the string if necessary */ @@ -187,7 +188,7 @@ printf("'\n"); *r++ = ' '; return result; -} /* bpchar() */ +} /* bpchar() */ /* bpchar_char() @@ -197,7 +198,7 @@ int32 bpchar_char(char *s) { return (int32) *VARDATA(s); -} /* bpchar_char() */ +} /* bpchar_char() */ /* char_bpchar() * Convert char to bpchar(1). @@ -205,21 +206,21 @@ bpchar_char(char *s) char * char_bpchar(int32 c) { - char *result; + char *result; - result = palloc(VARHDRSZ+1); + result = palloc(VARHDRSZ + 1); - VARSIZE(result) = VARHDRSZ+1; + VARSIZE(result) = VARHDRSZ + 1; *(VARDATA(result)) = (char) c; return result; -} /* char_bpchar() */ +} /* char_bpchar() */ /* bpchar_name() * Converts a bpchar() type to a NameData type. */ -NameData * +NameData * bpchar_name(char *s) { NameData *result; @@ -229,29 +230,33 @@ bpchar_name(char *s) return NULL; len = VARSIZE(s) - VARHDRSZ; - if (len > NAMEDATALEN) len = NAMEDATALEN; + if (len > NAMEDATALEN) + len = NAMEDATALEN; - while (len > 0) { - if (*(VARDATA(s)+len-1) != ' ') break; + while (len > 0) + { + if (*(VARDATA(s) + len - 1) != ' ') + break; len--; } #ifdef STRINGDEBUG -printf("bpchar- convert string length %d (%d) ->%d\n", - VARSIZE(s)-VARHDRSZ, VARSIZE(s), len); + printf("bpchar- convert string length %d (%d) ->%d\n", + VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); #endif result = (NameData *) palloc(NAMEDATALEN); StrNCpy(result->data, VARDATA(s), NAMEDATALEN); /* now null pad to full length... */ - while (len < NAMEDATALEN) { + while (len < NAMEDATALEN) + { *(result->data + len) = '\0'; len++; } return result; -} /* bpchar_name() */ +} /* bpchar_name() */ /* name_bpchar() * Converts a NameData type to a bpchar type. @@ -268,8 +273,8 @@ name_bpchar(NameData *s) len = strlen(s->data); #ifdef STRINGDEBUG -printf("bpchar- convert string length %d (%d) ->%d\n", - VARSIZE(s)-VARHDRSZ, VARSIZE(s), len); + printf("bpchar- convert string length %d (%d) ->%d\n", + VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); #endif result = (char *) palloc(VARHDRSZ + len); @@ -277,7 +282,7 @@ printf("bpchar- convert string length %d (%d) ->%d\n", VARSIZE(result) = len + VARHDRSZ; return result; -} /* name_bpchar() */ +} /* name_bpchar() */ /***************************************************************************** @@ -372,7 +377,7 @@ varchar(char *s, int32 slen) strncpy(VARDATA(result), VARDATA(s), len); return result; -} /* varchar() */ +} /* varchar() */ /***************************************************************************** @@ -400,7 +405,10 @@ bpcharlen(char *arg) { #ifdef MULTIBYTE unsigned char *s; - int len, l, wl; + int len, + l, + wl; + #endif if (!PointerIsValid(arg)) elog(ERROR, "Bad (null) char() external representation", NULL); @@ -408,13 +416,14 @@ bpcharlen(char *arg) l = bcTruelen(arg); len = 0; s = VARDATA(arg); - while (l > 0) { - wl = pg_mblen(s); - l -= wl; - s += wl; - len++; + while (l > 0) + { + wl = pg_mblen(s); + l -= wl; + s += wl; + len++; } - return(len); + return (len); #else return bcTruelen(arg); #endif @@ -565,7 +574,10 @@ varcharlen(char *arg) { #ifdef MULTIBYTE unsigned char *s; - int len, l, wl; + int len, + l, + wl; + #endif if (!PointerIsValid(arg)) elog(ERROR, "Bad (null) varchar() external representation", NULL); @@ -574,13 +586,14 @@ varcharlen(char *arg) len = 0; s = VARDATA(arg); l = VARSIZE(arg) - VARHDRSZ; - while (l > 0) { - wl = pg_mblen(s); - l -= wl; - s += wl; - len++; + while (l > 0) + { + wl = pg_mblen(s); + l -= wl; + s += wl; + len++; } - return(len); + return (len); #else return VARSIZE(arg) - VARHDRSZ; #endif diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 22e0e981240..4410aa1c9aa 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.41 1998/09/01 03:26:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.42 1998/09/01 04:32:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -208,9 +208,12 @@ textlen(text *t) { #ifdef MULTIBYTE unsigned char *s; - int len, l, wl; + int len, + l, + wl; + #endif - + if (!PointerIsValid(t)) elog(ERROR, "Null input to textlen"); @@ -218,17 +221,18 @@ textlen(text *t) len = 0; s = VARDATA(t); l = VARSIZE(t) - VARHDRSZ; - while (l > 0) { - wl = pg_mblen(s); - l -= wl; - s += wl; - len++; + while (l > 0) + { + wl = pg_mblen(s); + l -= wl; + s += wl; + len++; } - return(len); + return (len); #else return VARSIZE(t) - VARHDRSZ; #endif - + } /* textlen() */ /* @@ -322,9 +326,11 @@ text_substr(text *string, int32 m, int32 n) { text *ret; int len; + #ifdef MULTIBYTE - int i; - char *p; + int i; + char *p; + #endif if ((string == (text *) NULL) || (m <= 0)) @@ -332,7 +338,7 @@ text_substr(text *string, int32 m, int32 n) len = VARSIZE(string) - VARHDRSZ; #ifdef MULTIBYTE - len = pg_mbstrlen_with_len(VARDATA(string),len); + len = pg_mbstrlen_with_len(VARDATA(string), len); #endif /* m will now become a zero-based starting position */ @@ -350,13 +356,11 @@ text_substr(text *string, int32 m, int32 n) #ifdef MULTIBYTE p = VARDATA(string); - for (i=0;i<m;i++) { - p += pg_mblen(p); - } + for (i = 0; i < m; i++) + p += pg_mblen(p); m = p - VARDATA(string); - for (i=0;i<n;i++) { - p += pg_mblen(p); - } + for (i = 0; i < n; i++) + p += pg_mblen(p); n = p - (VARDATA(string) + m); #endif ret = (text *) palloc(VARHDRSZ + n); @@ -385,10 +389,13 @@ textpos(text *t1, text *t2) p; int len1, len2; - pg_wchar *p1, + pg_wchar *p1, *p2; + #ifdef MULTIBYTE - pg_wchar *ps1, *ps2; + pg_wchar *ps1, + *ps2; + #endif if (!PointerIsValid(t1) || !PointerIsValid(t2)) @@ -400,11 +407,11 @@ textpos(text *t1, text *t2) len1 = (VARSIZE(t1) - VARHDRSZ); len2 = (VARSIZE(t2) - VARHDRSZ); #ifdef MULTIBYTE - ps1 = p1 = (pg_wchar *) palloc((len1 + 1)*sizeof(pg_wchar)); - (void)pg_mb2wchar_with_len((unsigned char *)VARDATA(t1),p1,len1); + ps1 = p1 = (pg_wchar *) palloc((len1 + 1) * sizeof(pg_wchar)); + (void) pg_mb2wchar_with_len((unsigned char *) VARDATA(t1), p1, len1); len1 = pg_wchar_strlen(p1); - ps2 = p2 = (pg_wchar *) palloc((len2 + 1)*sizeof(pg_wchar)); - (void)pg_mb2wchar_with_len((unsigned char *)VARDATA(t2),p2,len2); + ps2 = p2 = (pg_wchar *) palloc((len2 + 1) * sizeof(pg_wchar)); + (void) pg_mb2wchar_with_len((unsigned char *) VARDATA(t2), p2, len2); len2 = pg_wchar_strlen(p2); #else p1 = VARDATA(t1); @@ -477,8 +484,9 @@ textne(text *arg1, text *arg2) int varstr_cmp(char *arg1, int len1, char *arg2, int len2) { - int result; - char *a1p, *a2p; + int result; + char *a1p, + *a2p; #ifdef USE_LOCALE a1p = (unsigned char *) palloc(len1 + 1); @@ -518,8 +526,10 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2) int text_cmp(text *arg1, text *arg2) { - char *a1p, *a2p; - int len1, len2; + char *a1p, + *a2p; + int len1, + len2; if (arg1 == NULL || arg2 == NULL) return (bool) FALSE; @@ -539,7 +549,7 @@ text_cmp(text *arg1, text *arg2) bool text_lt(text *arg1, text *arg2) { - return (bool)(text_cmp(arg1, arg2) < 0); + return (bool) (text_cmp(arg1, arg2) < 0); } /* text_lt() */ /* text_le() @@ -548,7 +558,7 @@ text_lt(text *arg1, text *arg2) bool text_le(text *arg1, text *arg2) { - return (bool)(text_cmp(arg1, arg2) <= 0); + return (bool) (text_cmp(arg1, arg2) <= 0); } /* text_le() */ bool @@ -725,7 +735,7 @@ byteaSetBit(text *v, int32 n, int32 newBit) /* text_name() * Converts a text() type to a NameData type. */ -NameData * +NameData * text_name(text *s) { NameData *result; @@ -735,24 +745,26 @@ text_name(text *s) return NULL; len = VARSIZE(s) - VARHDRSZ; - if (len > NAMEDATALEN) len = NAMEDATALEN; + if (len > NAMEDATALEN) + len = NAMEDATALEN; #ifdef STRINGDEBUG -printf("text- convert string length %d (%d) ->%d\n", - VARSIZE(s)-VARHDRSZ, VARSIZE(s), len); + printf("text- convert string length %d (%d) ->%d\n", + VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); #endif result = palloc(NAMEDATALEN); StrNCpy(result->data, VARDATA(s), NAMEDATALEN); /* now null pad to full length... */ - while (len < NAMEDATALEN) { + while (len < NAMEDATALEN) + { *(result->data + len) = '\0'; len++; } return result; -} /* text_name() */ +} /* text_name() */ /* name_text() * Converts a NameData type to a text type. @@ -769,8 +781,8 @@ name_text(NameData *s) len = strlen(s->data); #ifdef STRINGDEBUG -printf("text- convert string length %d (%d) ->%d\n", - VARSIZE(s)-VARHDRSZ, VARSIZE(s), len); + printf("text- convert string length %d (%d) ->%d\n", + VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); #endif result = palloc(VARHDRSZ + len); @@ -778,4 +790,4 @@ printf("text- convert string length %d (%d) ->%d\n", VARSIZE(result) = len + VARHDRSZ; return result; -} /* name_text() */ +} /* name_text() */ diff --git a/src/backend/utils/adt/version.c b/src/backend/utils/adt/version.c index e0af6b2d6df..f15e788bc80 100644 --- a/src/backend/utils/adt/version.c +++ b/src/backend/utils/adt/version.c @@ -1,11 +1,11 @@ /*------------------------------------------------------------------------- * * version.c-- - * Returns the version string + * Returns the version string * * IDENTIFICATION * - * $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.1 1998/04/29 12:38:05 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.2 1998/09/01 04:32:55 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -14,12 +14,13 @@ #include "version.h" -text* version(void); +text *version(void); -text* version(void) +text * +version(void) { - int n = strlen(PG_VERSION_STR) + VARHDRSZ; - text *ret = (text *) palloc(n); + int n = strlen(PG_VERSION_STR) + VARHDRSZ; + text *ret = (text *) palloc(n); VARSIZE(ret) = n; strcpy(VARDATA(ret), PG_VERSION_STR); |