1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

pgindent run.

This commit is contained in:
Bruce Momjian
2002-09-04 20:31:48 +00:00
parent c91ceec21d
commit e50f52a074
446 changed files with 14942 additions and 13363 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.78 2002/09/03 22:17:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.79 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -36,15 +36,15 @@ static const char *aclparse(const char *s, AclItem *aip, unsigned *modechg);
static bool aclitemeq(const AclItem *a1, const AclItem *a2);
static bool aclitemgt(const AclItem *a1, const AclItem *a2);
static Oid convert_table_name(text *tablename);
static Oid convert_table_name(text *tablename);
static AclMode convert_table_priv_string(text *priv_type_text);
static Oid convert_database_name(text *databasename);
static Oid convert_database_name(text *databasename);
static AclMode convert_database_priv_string(text *priv_type_text);
static Oid convert_function_name(text *functionname);
static Oid convert_function_name(text *functionname);
static AclMode convert_function_priv_string(text *priv_type_text);
static Oid convert_language_name(text *languagename);
static Oid convert_language_name(text *languagename);
static AclMode convert_language_priv_string(text *priv_type_text);
static Oid convert_schema_name(text *schemaname);
static Oid convert_schema_name(text *schemaname);
static AclMode convert_schema_priv_string(text *priv_type_text);
@@ -413,7 +413,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
owner_default = ACL_ALL_RIGHTS_RELATION;
break;
case ACL_OBJECT_DATABASE:
world_default = ACL_CREATE_TEMP; /* not NO_RIGHTS! */
world_default = ACL_CREATE_TEMP; /* not NO_RIGHTS! */
owner_default = ACL_ALL_RIGHTS_DATABASE;
break;
case ACL_OBJECT_FUNCTION:
@@ -430,7 +430,7 @@ acldefault(GrantObjectType objtype, AclId ownerid)
break;
default:
elog(ERROR, "acldefault: bogus objtype %d", (int) objtype);
world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
world_default = ACL_NO_RIGHTS; /* keep compiler quiet */
owner_default = ACL_NO_RIGHTS;
break;
}
@@ -819,7 +819,7 @@ convert_table_name(text *tablename)
RangeVar *relrv;
relrv = makeRangeVarFromNameList(textToQualifiedNameList(tablename,
"has_table_privilege"));
"has_table_privilege"));
return RangeVarGetRelid(relrv, false);
}
@@ -834,7 +834,7 @@ convert_table_priv_string(text *priv_type_text)
char *priv_type;
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
PointerGetDatum(priv_type_text)));
/*
* Return mode from priv_type string
@@ -1030,7 +1030,7 @@ convert_database_name(text *databasename)
Oid oid;
dbname = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(databasename)));
PointerGetDatum(databasename)));
oid = get_database_oid(dbname);
if (!OidIsValid(oid))
@@ -1049,7 +1049,7 @@ convert_database_priv_string(text *priv_type_text)
char *priv_type;
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
PointerGetDatum(priv_type_text)));
/*
* Return mode from priv_type string
@@ -1233,10 +1233,10 @@ convert_function_name(text *functionname)
Oid oid;
funcname = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(functionname)));
PointerGetDatum(functionname)));
oid = DatumGetObjectId(DirectFunctionCall1(regprocedurein,
CStringGetDatum(funcname)));
CStringGetDatum(funcname)));
if (!OidIsValid(oid))
elog(ERROR, "function \"%s\" does not exist", funcname);
@@ -1254,7 +1254,7 @@ convert_function_priv_string(text *priv_type_text)
char *priv_type;
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
PointerGetDatum(priv_type_text)));
/*
* Return mode from priv_type string
@@ -1432,7 +1432,7 @@ convert_language_name(text *languagename)
Oid oid;
langname = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(languagename)));
PointerGetDatum(languagename)));
oid = GetSysCacheOid(LANGNAME,
CStringGetDatum(langname),
@@ -1453,7 +1453,7 @@ convert_language_priv_string(text *priv_type_text)
char *priv_type;
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
PointerGetDatum(priv_type_text)));
/*
* Return mode from priv_type string
@@ -1631,7 +1631,7 @@ convert_schema_name(text *schemaname)
Oid oid;
nspname = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(schemaname)));
PointerGetDatum(schemaname)));
oid = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(nspname),
@@ -1652,7 +1652,7 @@ convert_schema_priv_string(text *priv_type_text)
char *priv_type;
priv_type = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(priv_type_text)));
PointerGetDatum(priv_type_text)));
/*
* Return mode from priv_type string

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.79 2002/08/26 17:53:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.80 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -80,27 +80,27 @@ 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);
static int ArrayCastAndSet(Datum src,
int typlen, bool typbyval, char typalign,
char *dest);
static int array_nelems_size(char *ptr, int nitems,
int typlen, bool typbyval, char typalign);
static int ArrayCastAndSet(Datum src,
int typlen, bool typbyval, char typalign,
char *dest);
static int array_nelems_size(char *ptr, int nitems,
int typlen, bool typbyval, char typalign);
static char *array_seek(char *ptr, int nitems,
int typlen, bool typbyval, char typalign);
static int array_copy(char *destptr, int nitems, char *srcptr,
int typlen, bool typbyval, char typalign);
int typlen, bool typbyval, char typalign);
static int array_copy(char *destptr, int nitems, char *srcptr,
int typlen, bool typbyval, char typalign);
static int array_slice_size(int ndim, int *dim, int *lb, char *arraydataptr,
int *st, int *endp,
int typlen, bool typbyval, char typalign);
int *st, int *endp,
int typlen, bool typbyval, char typalign);
static void array_extract_slice(int ndim, int *dim, int *lb,
char *arraydataptr,
int *st, int *endp, char *destPtr,
int typlen, bool typbyval, char typalign);
char *arraydataptr,
int *st, int *endp, char *destPtr,
int typlen, bool typbyval, char typalign);
static void array_insert_slice(int ndim, int *dim, int *lb,
char *origPtr, int origdatasize,
char *destPtr,
int *st, int *endp, char *srcPtr,
int typlen, bool typbyval, char typalign);
char *origPtr, int origdatasize,
char *destPtr,
int *st, int *endp, char *srcPtr,
int typlen, bool typbyval, char typalign);
/*---------------------------------------------------------------------
@@ -422,28 +422,28 @@ ReadArrayStr(char *arrayStr,
elog(ERROR, "malformed array constant: %s", arrayStr);
break;
case '\\':
{
char *cptr;
{
char *cptr;
/* Crunch the string on top of the backslash. */
for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1);
if (*ptr == '\0')
elog(ERROR, "malformed array constant: %s", arrayStr);
break;
}
/* Crunch the string on top of the backslash. */
for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1);
if (*ptr == '\0')
elog(ERROR, "malformed array constant: %s", arrayStr);
break;
}
case '\"':
{
char *cptr;
{
char *cptr;
scanning_string = !scanning_string;
/* Crunch the string on top of the quote. */
for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1);
/* Back up to not miss following character. */
ptr--;
break;
}
scanning_string = !scanning_string;
/* Crunch the string on top of the quote. */
for (cptr = ptr; *cptr != '\0'; cptr++)
*cptr = *(cptr + 1);
/* Back up to not miss following character. */
ptr--;
break;
}
case '{':
if (!scanning_string)
{
@@ -452,9 +452,9 @@ ReadArrayStr(char *arrayStr,
nest_level++;
indx[nest_level - 1] = 0;
/* skip leading whitespace */
while (isspace((unsigned char) *(ptr+1)))
while (isspace((unsigned char) *(ptr + 1)))
ptr++;
itemstart = ptr+1;
itemstart = ptr + 1;
}
break;
case '}':
@@ -471,11 +471,11 @@ ReadArrayStr(char *arrayStr,
else
{
/*
* tricky coding: terminate item value string at
* first '}', but don't process it till we see
* a typdelim char or end of array. This handles
* case where several '}'s appear successively
* in a multidimensional array.
* tricky coding: terminate item value string
* at first '}', but don't process it till we
* see a typdelim char or end of array. This
* handles case where several '}'s appear
* successively in a multidimensional array.
*/
*ptr = '\0';
indx[nest_level - 1]++;
@@ -641,8 +641,8 @@ array_out(PG_FUNCTION_ARGS)
/*
* Convert all values to string form, count total space needed
* (including any overhead such as escaping backslashes),
* and detect whether each item needs double quotes.
* (including any overhead such as escaping backslashes), and detect
* whether each item needs double quotes.
*/
values = (char **) palloc(nitems * sizeof(char *));
needquotes = (bool *) palloc(nitems * sizeof(bool));
@@ -665,7 +665,7 @@ array_out(PG_FUNCTION_ARGS)
nq = (values[i][0] == '\0'); /* force quotes for empty string */
for (tmp = values[i]; *tmp; tmp++)
{
char ch = *tmp;
char ch = *tmp;
overall_length += 1;
if (ch == '"' || ch == '\\')
@@ -716,7 +716,7 @@ array_out(PG_FUNCTION_ARGS)
#ifndef TCL_ARRAYS
for (tmp = values[k]; *tmp; tmp++)
{
char ch = *tmp;
char ch = *tmp;
if (ch == '"' || ch == '\\')
*p++ = '\\';
@@ -919,8 +919,8 @@ array_get_slice(ArrayType *array,
elog(ERROR, "Slices of fixed-length arrays not implemented");
/*
* fixed-length arrays -- these are assumed to be 1-d, 0-based
* XXX where would we get the correct ELEMTYPE from?
* fixed-length arrays -- these are assumed to be 1-d, 0-based XXX
* where would we get the correct ELEMTYPE from?
*/
ndim = 1;
fixedDim[0] = arraylen / elmlen;
@@ -980,8 +980,9 @@ array_get_slice(ArrayType *array,
newarray->flags = 0;
newarray->elemtype = ARR_ELEMTYPE(array);
memcpy(ARR_DIMS(newarray), span, ndim * sizeof(int));
/*
* Lower bounds of the new array are set to 1. Formerly (before 7.3)
* Lower bounds of the new array are set to 1. Formerly (before 7.3)
* we copied the given lowerIndx values ... but that seems confusing.
*/
newlb = ARR_LBOUND(newarray);
@@ -1513,9 +1514,7 @@ construct_array(Datum *elems, int nelems,
/* compute required space */
if (elmlen > 0)
{
nbytes = nelems * att_align(elmlen, elmalign);
}
else
{
Assert(!elmbyval);

View File

@@ -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.55 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.56 2002/09/04 20:31:27 momjian Exp $
*/
#include "postgres.h"
@@ -662,8 +662,8 @@ cash_words(PG_FUNCTION_ARGS)
m0 = val % 100; /* cents */
m1 = (val / 100) % 1000; /* hundreds */
m2 = (val / 100000) % 1000; /* thousands */
m3 = val / 100000000 % 1000; /* millions */
m2 = (val / 100000) % 1000; /* thousands */
m3 = val / 100000000 % 1000; /* millions */
if (m3)
{

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.71 2002/09/03 19:41:28 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.72 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,10 +28,10 @@
#include "utils/timestamp.h"
int time2tm(TimeADT time, struct tm * tm, fsec_t *fsec);
int timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp);
int tm2time(struct tm * tm, fsec_t fsec, TimeADT *result);
int tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
int time2tm(TimeADT time, struct tm * tm, fsec_t *fsec);
int timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp);
int tm2time(struct tm * tm, fsec_t fsec, TimeADT *result);
int tm2timetz(struct tm * tm, fsec_t fsec, int tz, TimeTzADT *result);
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
/*****************************************************************************
@@ -343,7 +343,7 @@ date_timestamptz(PG_FUNCTION_ARGS)
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
{
int tz;
int tz;
tm->tm_hour = 0;
tm->tm_min = 0;
@@ -494,6 +494,7 @@ Datum
time_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
#ifdef NOT_USED
Oid typelem = PG_GETARG_OID(1);
#endif
@@ -529,7 +530,7 @@ tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
{
#ifdef HAVE_INT64_TIMESTAMP
*result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
* INT64CONST(1000000)) + fsec);
#else
*result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
#endif
@@ -542,7 +543,7 @@ tm2time(struct tm * tm, fsec_t fsec, TimeADT *result)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
int
time2tm(TimeADT time, struct tm *tm, fsec_t *fsec)
time2tm(TimeADT time, struct tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
tm->tm_hour = (time / INT64CONST(3600000000));
@@ -610,7 +611,7 @@ static void
AdjustTimeForTypmod(TimeADT *time, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
static const int64 TimeScales[MAX_TIMESTAMP_PRECISION+1] = {
static const int64 TimeScales[MAX_TIMESTAMP_PRECISION + 1] = {
INT64CONST(1000000),
INT64CONST(100000),
INT64CONST(10000),
@@ -620,7 +621,7 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
INT64CONST(1)
};
static const int64 TimeOffsets[MAX_TIMESTAMP_PRECISION+1] = {
static const int64 TimeOffsets[MAX_TIMESTAMP_PRECISION + 1] = {
INT64CONST(-500000),
INT64CONST(-50000),
INT64CONST(-5000),
@@ -629,8 +630,9 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
INT64CONST(-5),
INT64CONST(0)
};
#else
static const double TimeScales[MAX_TIMESTAMP_PRECISION+1] = {
static const double TimeScales[MAX_TIMESTAMP_PRECISION + 1] = {
1,
10,
100,
@@ -640,7 +642,7 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
1000000
};
static const double TimeOffsets[MAX_TIMESTAMP_PRECISION+1] = {
static const double TimeOffsets[MAX_TIMESTAMP_PRECISION + 1] = {
0.5,
0.05,
0.005,
@@ -674,7 +676,10 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
}
else
{
/* Scale and truncate first, then add to help the rounding behavior */
/*
* Scale and truncate first, then add to help the rounding
* behavior
*/
*time = (rint((((double) *time) * TimeScales[typmod]) + TimeOffsets[typmod])
/ TimeScales[typmod]);
}
@@ -915,8 +920,10 @@ timestamp_time(PG_FUNCTION_ARGS)
elog(ERROR, "Unable to convert timestamp to time");
#ifdef HAVE_INT64_TIMESTAMP
/* Could also do this with
* time = (timestamp / 86400000000 * 86400000000) - timestamp;
/*
* Could also do this with time = (timestamp / 86400000000 *
* 86400000000) - timestamp;
*/
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
@@ -948,8 +955,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
elog(ERROR, "Unable to convert timestamptz to time");
#ifdef HAVE_INT64_TIMESTAMP
/* Could also do this with
* time = (timestamp / 86400000000 * 86400000000) - timestamp;
/*
* Could also do this with time = (timestamp / 86400000000 *
* 86400000000) - timestamp;
*/
result = ((((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec)
* INT64CONST(1000000)) + fsec);
@@ -1349,7 +1358,7 @@ timetz_out(PG_FUNCTION_ARGS)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
int
timetz2tm(TimeTzADT *time, struct tm *tm, fsec_t *fsec, int *tzp)
timetz2tm(TimeTzADT *time, struct tm * tm, fsec_t *fsec, int *tzp)
{
#ifdef HAVE_INT64_TIMESTAMP
tm->tm_hour = (time->time / INT64CONST(3600000000));
@@ -1537,6 +1546,7 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
Interval *span = PG_GETARG_INTERVAL_P(1);
TimeTzADT *result;
#ifndef HAVE_INT64_TIMESTAMP
TimeTzADT time1;
#endif
@@ -1569,6 +1579,7 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
Interval *span = PG_GETARG_INTERVAL_P(1);
TimeTzADT *result;
#ifndef HAVE_INT64_TIMESTAMP
TimeTzADT time1;
#endif
@@ -1798,7 +1809,7 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result = (((date * INT64CONST(86400000000)) + time->time)
+ (time->zone * INT64CONST(1000000)));
+ (time->zone * INT64CONST(1000000)));
#else
result = (((date * 86400.0) + time->time) + time->zone);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.24 2002/08/24 15:00:46 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datum.c,v 1.25 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -81,7 +81,7 @@ datumGetSize(Datum value, bool typByVal, int typLen)
else if (typLen == -2)
{
/* It is a cstring datatype */
char *s = (char *) DatumGetPointer(value);
char *s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s))
elog(ERROR, "datumGetSize: Invalid Datum Pointer");
@@ -175,9 +175,9 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
/*
* just compare the two datums. NOTE: just comparing "len" bytes
* will not do the work, because we do not know how these bytes
* are aligned inside the "Datum". We assume instead that any
* given datatype is consistent about how it fills extraneous
* bits in the Datum.
* are aligned inside the "Datum". We assume instead that any
* given datatype is consistent about how it fills extraneous bits
* in the Datum.
*/
res = (value1 == value2);
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.80 2002/08/26 17:53:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.81 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1515,7 +1515,7 @@ float8_accum(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), false /*float8 byval*/, 'd');
sizeof(float8), false /* float8 byval */ , 'd');
PG_RETURN_ARRAYTYPE_P(result);
}
@@ -1551,7 +1551,7 @@ float4_accum(PG_FUNCTION_ARGS)
result = construct_array(transdatums, 3,
FLOAT8OID,
sizeof(float8), false /*float8 byval*/, 'd');
sizeof(float8), false /* float8 byval */ , 'd');
PG_RETURN_ARRAYTYPE_P(result);
}

View File

@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.33 2002/08/29 07:22:26 ishii Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.34 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,8 +31,9 @@
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
static char *format_type_internal(Oid type_oid, int32 typemod,
bool typemod_given, bool allow_invalid);
static char *psnprintf(size_t len, const char *fmt, ...)
bool typemod_given, bool allow_invalid);
static char *
psnprintf(size_t len, const char *fmt,...)
/* This lets gcc check the format string for consistency. */
__attribute__((format(printf, 2, 3)));
@@ -47,14 +48,14 @@ __attribute__((format(printf, 2, 3)));
* double quoted if it contains funny characters or matches a keyword.
*
* If typemod is NULL then we are formatting a type name in a context where
* no typemod is available, eg a function argument or result type. This
* no typemod is available, eg a function argument or result type. This
* yields a slightly different result from specifying typemod = -1 in some
* cases. Given typemod = -1 we feel compelled to produce an output that
* the parser will interpret as having typemod -1, so that pg_dump will
* produce CREATE TABLE commands that recreate the original state. But
* produce CREATE TABLE commands that recreate the original state. But
* given NULL typemod, we assume that the parser's interpretation of
* typemod doesn't matter, and so we are willing to output a slightly
* "prettier" representation of the same type. For example, type = bpchar
* "prettier" representation of the same type. For example, type = bpchar
* and typemod = NULL gets you "character", whereas typemod = -1 gets you
* "bpchar" --- the former will be interpreted as character(1) by the
* parser, which does not yield typemod -1.
@@ -77,9 +78,7 @@ format_type(PG_FUNCTION_ARGS)
type_oid = PG_GETARG_OID(0);
if (PG_ARGISNULL(1))
{
result = format_type_internal(type_oid, -1, false, true);
}
else
{
typemod = PG_GETARG_INT32(1);
@@ -141,7 +140,7 @@ format_type_internal(Oid type_oid, int32 typemod,
/*
* Check if it's an array (and not a domain --- we don't want to show
* the substructure of a domain type). Fixed-length array types such
* the substructure of a domain type). Fixed-length array types such
* as "name" shouldn't get deconstructed either.
*/
array_base_type = typeform->typelem;
@@ -171,15 +170,15 @@ format_type_internal(Oid type_oid, int32 typemod,
is_array = false;
/*
* See if we want to special-case the output for certain built-in types.
* Note that these special cases should all correspond to special
* productions in gram.y, to ensure that the type name will be taken as
* a system type, not a user type of the same name.
* See if we want to special-case the output for certain built-in
* types. Note that these special cases should all correspond to
* special productions in gram.y, to ensure that the type name will be
* taken as a system type, not a user type of the same name.
*
* If we do not provide a special-case output here, the type name will
* be handled the same way as a user type name --- in particular, it
* will be double-quoted if it matches any lexer keyword. This behavior
* is essential for some cases, such as types "bit" and "char".
* If we do not provide a special-case output here, the type name will be
* handled the same way as a user type name --- in particular, it will
* be double-quoted if it matches any lexer keyword. This behavior is
* essential for some cases, such as types "bit" and "char".
*/
buf = NULL; /* flag for no special case */
@@ -277,36 +276,36 @@ format_type_internal(Oid type_oid, int32 typemod,
case INTERVAL_MASK(SECOND):
fieldstr = " second";
break;
case INTERVAL_MASK(YEAR)
| INTERVAL_MASK(MONTH):
case INTERVAL_MASK(YEAR)
| INTERVAL_MASK(MONTH):
fieldstr = " year to month";
break;
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR):
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR):
fieldstr = " day to hour";
break;
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE):
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE):
fieldstr = " day to minute";
break;
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
case INTERVAL_MASK(DAY)
| INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
fieldstr = " day to second";
break;
case INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE):
case INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE):
fieldstr = " hour to minute";
break;
case INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
case INTERVAL_MASK(HOUR)
| INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
fieldstr = " hour to second";
break;
case INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
case INTERVAL_MASK(MINUTE)
| INTERVAL_MASK(SECOND):
fieldstr = " minute to second";
break;
case INTERVAL_FULL_RANGE:
@@ -382,9 +381,9 @@ format_type_internal(Oid type_oid, int32 typemod,
{
/*
* Default handling: report the name as it appears in the catalog.
* Here, we must qualify the name if it is not visible in the search
* path, and we must double-quote it if it's not a standard identifier
* or if it matches any keyword.
* Here, we must qualify the name if it is not visible in the
* search path, and we must double-quote it if it's not a standard
* identifier or if it matches any keyword.
*/
char *nspname;
char *typname;
@@ -518,7 +517,7 @@ oidvectortypes(PG_FUNCTION_ARGS)
/* snprintf into a palloc'd string */
static char *
psnprintf(size_t len, const char *fmt, ...)
psnprintf(size_t len, const char *fmt,...)
{
va_list ap;
char *buf;

View File

@@ -1,7 +1,7 @@
/* -----------------------------------------------------------------------
* formatting.c
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.53 2002/04/21 19:48:12 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.54 2002/09/04 20:31:27 momjian Exp $
*
*
* Portions Copyright (c) 1999-2000, PostgreSQL Global Development Group
@@ -2438,9 +2438,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
sscanf(inout, "%03d", &tmfc->year);
/*
* 3-digit year:
* '100' ... '999' = 1100 ... 1999
* '000' ... '099' = 2000 ... 2099
* 3-digit year: '100' ... '999' = 1100 ... 1999 '000' ...
* '099' = 2000 ... 2099
*/
if (tmfc->year >= 100)
tmfc->year += 1000;
@@ -2469,9 +2468,8 @@ dch_date(int arg, char *inout, int suf, int flag, FormatNode *node, void *data)
sscanf(inout, "%02d", &tmfc->year);
/*
* 2-digit year:
* '00' ... '69' = 2000 ... 2069
* '70' ... '99' = 1970 ... 1999
* 2-digit year: '00' ... '69' = 2000 ... 2069 '70' ...
* '99' = 1970 ... 1999
*/
if (tmfc->year < 70)
tmfc->year += 2000;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.64 2002/08/29 23:05:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.65 2002/09/04 20:31:27 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1236,7 +1236,7 @@ path_in(PG_FUNCTION_ARGS)
depth++;
}
size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * npts;
size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts;
path = (PATH *) palloc(size);
path->size = size;
@@ -2155,8 +2155,8 @@ dist_ps_internal(Point *pt, LSEG *lseg)
#endif
/*
* Calculate distance to the line segment
* or to the endpoints of the segment.
* Calculate distance to the line segment or to the endpoints of the
* segment.
*/
/* intersection is on the line segment? */
@@ -2397,9 +2397,7 @@ interpt_sl(LSEG *lseg, LINE *line)
#endif
}
else
{
p = NULL;
}
}
return p;
@@ -3610,7 +3608,7 @@ path_add(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
base_size = sizeof(p1->p[0]) * (p1->npts + p2->npts);
size = offsetof(PATH, p[0]) + base_size;
size = offsetof(PATH, p[0]) +base_size;
/* Check for integer overflow */
if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) ||
@@ -4436,7 +4434,7 @@ circle_poly(PG_FUNCTION_ARGS)
elog(ERROR, "Unable to convert circle to polygon");
base_size = sizeof(poly->p[0]) * npts;
size = offsetof(POLYGON, p[0]) + base_size;
size = offsetof(POLYGON, p[0]) +base_size;
/* Check for integer overflow */
if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.40 2002/06/20 20:29:37 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.41 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -70,14 +70,16 @@ int8in(PG_FUNCTION_ARGS)
{
ptr++;
sign = -1;
/*
* Do an explicit check for INT64_MIN. Ugly though this is, it's
* cleaner than trying to get the loop below to handle it portably.
* Do an explicit check for INT64_MIN. Ugly though this is, it's
* cleaner than trying to get the loop below to handle it
* portably.
*/
#ifndef INT64_IS_BUSTED
if (strcmp(ptr, "9223372036854775808") == 0)
{
result = - INT64CONST(0x7fffffffffffffff) - 1;
result = -INT64CONST(0x7fffffffffffffff) - 1;
PG_RETURN_INT64(result);
}
#endif

View File

@@ -2,11 +2,11 @@
*
* lockfuncs.c
* Set-returning functions to view the state of locks within the DB.
*
*
* Copyright (c) 2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.6 2002/09/02 01:05:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.7 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,19 +33,22 @@ typedef struct
Datum
pg_lock_status(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
PG_Lock_Status *mystatus;
FuncCallContext *funcctx;
PG_Lock_Status *mystatus;
LockData *lockData;
if (SRF_IS_FIRSTCALL())
{
TupleDesc tupdesc;
MemoryContext oldcontext;
TupleDesc tupdesc;
MemoryContext oldcontext;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/* switch to memory context appropriate for multiple function calls */
/*
* switch to memory context appropriate for multiple function
* calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* build tupdesc for result tuples */
@@ -67,8 +70,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
funcctx->slot = TupleDescGetSlot(tupdesc);
/*
* Collect all the locking information that we will format
* and send out as a result set.
* Collect all the locking information that we will format and
* send out as a result set.
*/
mystatus = (PG_Lock_Status *) palloc(sizeof(PG_Lock_Status));
funcctx->user_fctx = (void *) mystatus;
@@ -79,25 +82,25 @@ pg_lock_status(PG_FUNCTION_ARGS)
MemoryContextSwitchTo(oldcontext);
}
funcctx = SRF_PERCALL_SETUP();
funcctx = SRF_PERCALL_SETUP();
mystatus = (PG_Lock_Status *) funcctx->user_fctx;
lockData = mystatus->lockData;
while (mystatus->currIdx < lockData->nelements)
{
PROCLOCK *holder;
LOCK *lock;
PGPROC *proc;
bool granted;
LOCKMODE mode;
Datum values[6];
char nulls[6];
HeapTuple tuple;
Datum result;
PROCLOCK *holder;
LOCK *lock;
PGPROC *proc;
bool granted;
LOCKMODE mode;
Datum values[6];
char nulls[6];
HeapTuple tuple;
Datum result;
holder = &(lockData->holders[mystatus->currIdx]);
lock = &(lockData->locks[mystatus->currIdx]);
proc = &(lockData->procs[mystatus->currIdx]);
holder = &(lockData->holders[mystatus->currIdx]);
lock = &(lockData->locks[mystatus->currIdx]);
proc = &(lockData->procs[mystatus->currIdx]);
/*
* Look to see if there are any held lock modes in this PROCLOCK.
@@ -116,8 +119,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
}
/*
* If no (more) held modes to report, see if PROC is waiting for
* a lock on this lock.
* If no (more) held modes to report, see if PROC is waiting for a
* lock on this lock.
*/
if (!granted)
{
@@ -125,6 +128,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
{
/* Yes, so report it with proper mode */
mode = proc->waitLockMode;
/*
* We are now done with this PROCLOCK, so advance pointer
* to continue with next one on next call.
@@ -134,8 +138,8 @@ pg_lock_status(PG_FUNCTION_ARGS)
else
{
/*
* Okay, we've displayed all the locks associated with this
* PROCLOCK, proceed to the next one.
* Okay, we've displayed all the locks associated with
* this PROCLOCK, proceed to the next one.
*/
mystatus->currIdx++;
continue;
@@ -166,7 +170,7 @@ pg_lock_status(PG_FUNCTION_ARGS)
values[3] = Int32GetDatum(proc->pid);
values[4] = DirectFunctionCall1(textin,
CStringGetDatum(GetLockmodeName(mode)));
CStringGetDatum(GetLockmodeName(mode)));
values[5] = BoolGetDatum(granted);
tuple = heap_formtuple(funcctx->slot->ttc_tupleDescriptor,

View File

@@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for MAC addresses.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.25 2002/08/28 20:46:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/mac.c,v 1.26 2002/09/04 20:31:28 momjian Exp $
*/
#include "postgres.h"
@@ -81,7 +81,7 @@ macaddr_out(PG_FUNCTION_ARGS)
result = (char *) palloc(32);
snprintf(result, 32, "%02x:%02x:%02x:%02x:%02x:%02x",
addr->a, addr->b, addr->c, addr->d, addr->e, addr->f);
addr->a, addr->b, addr->c, addr->d, addr->e, addr->f);
PG_RETURN_CSTRING(result);
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.26 2002/09/02 02:47:04 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.27 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -119,7 +119,7 @@ userfntest(PG_FUNCTION_ARGS)
Datum
current_database(PG_FUNCTION_ARGS)
{
Name db;
Name db;
db = (Name) palloc(NAMEDATALEN);

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.98 2002/09/02 02:47:04 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.99 2002/09/04 20:31:28 momjian Exp $
*
* NOTES
*
@@ -980,8 +980,10 @@ interval_reltime(PG_FUNCTION_ARGS)
RelativeTime time;
int year,
month;
#ifdef HAVE_INT64_TIMESTAMP
int64 span;
#else
double span;
#endif

View File

@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.40 2002/08/26 17:53:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.41 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -51,7 +51,7 @@ namein(PG_FUNCTION_ARGS)
if ((ermsg = pg_verifymbstr(s, len)))
elog(ERROR, "%s", ermsg);
len = pg_mbcliplen(s, len, NAMEDATALEN-1);
len = pg_mbcliplen(s, len, NAMEDATALEN - 1);
result = (NameData *) palloc(NAMEDATALEN);
/* always keep it null-padded */
@@ -240,8 +240,8 @@ session_user(PG_FUNCTION_ARGS)
Datum
current_schema(PG_FUNCTION_ARGS)
{
List *search_path = fetch_search_path(false);
char *nspname;
List *search_path = fetch_search_path(false);
char *nspname;
if (search_path == NIL)
PG_RETURN_NULL();
@@ -252,18 +252,18 @@ current_schema(PG_FUNCTION_ARGS)
Datum
current_schemas(PG_FUNCTION_ARGS)
{
List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
int nnames = length(search_path);
Datum *names;
int i;
ArrayType *array;
List *search_path = fetch_search_path(PG_GETARG_BOOL(0));
int nnames = length(search_path);
Datum *names;
int i;
ArrayType *array;
/* +1 here is just to avoid palloc(0) error */
names = (Datum *) palloc((nnames + 1) * sizeof(Datum));
i = 0;
while (search_path)
{
char *nspname;
char *nspname;
nspname = get_namespace_name((Oid) lfirsti(search_path));
names[i] = DirectFunctionCall1(namein, CStringGetDatum(nspname));
@@ -273,9 +273,9 @@ current_schemas(PG_FUNCTION_ARGS)
array = construct_array(names, nnames,
NAMEOID,
NAMEDATALEN, /* sizeof(Name) */
false, /* Name is not by-val */
'i'); /* alignment of Name */
NAMEDATALEN, /* sizeof(Name) */
false, /* Name is not by-val */
'i'); /* alignment of Name */
PG_RETURN_POINTER(array);
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.31 2002/08/02 18:15:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.32 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -60,8 +60,8 @@ int4notin(PG_FUNCTION_ARGS)
nnames = length(names);
if (nnames < 2)
elog(ERROR, "int4notin: must provide relationname.attributename");
attribute = strVal(nth(nnames-1, names));
names = ltruncate(nnames-1, names);
attribute = strVal(nth(nnames - 1, names));
names = ltruncate(nnames - 1, names);
relrv = makeRangeVarFromNameList(names);
/* Open the relation and get a relation descriptor */

View File

@@ -5,7 +5,7 @@
*
* 1998 Jan Wieck
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.52 2002/09/02 02:47:04 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.53 2002/09/04 20:31:28 momjian Exp $
*
* ----------
*/
@@ -152,7 +152,7 @@ static void add_var(NumericVar *var1, NumericVar *var2, NumericVar *result);
static void sub_var(NumericVar *var1, NumericVar *var2, NumericVar *result);
static void mul_var(NumericVar *var1, NumericVar *var2, NumericVar *result);
static void div_var(NumericVar *var1, NumericVar *var2, NumericVar *result);
static int select_div_scale(NumericVar *var1, NumericVar *var2);
static int select_div_scale(NumericVar *var1, NumericVar *var2);
static void mod_var(NumericVar *var1, NumericVar *var2, NumericVar *result);
static void ceil_var(NumericVar *var, NumericVar *result);
static void floor_var(NumericVar *var, NumericVar *result);
@@ -1906,7 +1906,7 @@ numeric_variance(PG_FUNCTION_ARGS)
}
else
{
mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */
mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */
div_dscale = select_div_scale(&vsumX2, &vNminus1);
div_var(&vsumX2, &vNminus1, &vsumX); /* variance */
vsumX.dscale = div_dscale;
@@ -1985,7 +1985,7 @@ numeric_stddev(PG_FUNCTION_ARGS)
}
else
{
mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */
mul_var(&vN, &vNminus1, &vNminus1); /* N * (N - 1) */
div_dscale = select_div_scale(&vsumX2, &vNminus1);
div_var(&vsumX2, &vNminus1, &vsumX); /* variance */
vsumX.dscale = div_dscale;

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.53 2002/08/27 20:54:47 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.54 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -63,8 +63,8 @@ pg_atoi(char *s, int size, int c)
errno = 0;
/*
* Some versions of strtol treat the empty string as an error, but some
* seem not to. Make an explicit test to be sure we catch it.
* Some versions of strtol treat the empty string as an error, but
* some seem not to. Make an explicit test to be sure we catch it.
*/
if (s == (char *) NULL)

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.42 2002/08/29 07:22:27 ishii Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.43 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -850,8 +850,8 @@ repeat(PG_FUNCTION_ARGS)
/* Check for integer overflow */
if (slen != 0 && count != 0)
{
int check = count * slen;
int check2 = check + VARHDRSZ;
int check = count * slen;
int check2 = check + VARHDRSZ;
if ((check / slen) != count || check2 <= check)
elog(ERROR, "Requested buffer is too large.");

View File

@@ -2,7 +2,7 @@
*
* PostgreSQL locale utilities
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.18 2002/08/09 22:52:04 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_locale.c,v 1.19 2002/09/04 20:31:28 momjian Exp $
*
* Portions Copyright (c) 2002, PostgreSQL Global Development Group
*
@@ -20,7 +20,7 @@
*
* The other categories, LC_MONETARY, LC_NUMERIC, and LC_TIME are also
* settable at run-time. However, we don't actually set those locale
* categories permanently. This would have bizzare effects like no
* categories permanently. This would have bizzare effects like no
* longer accepting standard floating-point literals in some locales.
* Instead, we only set the locales briefly when needed, cache the
* required information obtained from localeconv(), and set them back.
@@ -44,10 +44,10 @@ static bool CurrentLocaleConvValid = false;
/* GUC storage area */
char *locale_messages;
char *locale_monetary;
char *locale_numeric;
char *locale_time;
char *locale_messages;
char *locale_monetary;
char *locale_numeric;
char *locale_time;
/* GUC assign hooks */
@@ -60,7 +60,7 @@ char *locale_time;
static const char *
locale_xxx_assign(int category, const char *value, bool doit, bool interactive)
{
char *save;
char *save;
save = setlocale(category, NULL);
if (!save)
@@ -104,7 +104,10 @@ locale_time_assign(const char *value, bool doit, bool interactive)
const char *
locale_messages_assign(const char *value, bool doit, bool interactive)
{
/* LC_MESSAGES category does not exist everywhere, but accept it anyway */
/*
* LC_MESSAGES category does not exist everywhere, but accept it
* anyway
*/
#ifdef LC_MESSAGES
if (doit)
{
@@ -113,15 +116,15 @@ locale_messages_assign(const char *value, bool doit, bool interactive)
}
else
{
char *save;
char *save;
save = setlocale(LC_MESSAGES, NULL);
if (!save)
return NULL;
if (!setlocale(LC_MESSAGES, value))
return NULL;
setlocale(LC_MESSAGES, save);
}
#endif
@@ -161,7 +164,7 @@ lc_collate_is_c(void)
* itself.)
*/
static void
free_struct_lconv(struct lconv *s)
free_struct_lconv(struct lconv * s)
{
if (s == NULL)
return;

View File

@@ -1,7 +1,7 @@
/* ----------
* pg_lzcompress.c -
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.14 2001/11/17 06:09:30 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.15 2002/09/04 20:31:28 momjian Exp $
*
* This is an implementation of LZ compression for PostgreSQL.
* It uses a simple history table and generates 2-3 byte tags
@@ -184,7 +184,7 @@
* Local definitions
* ----------
*/
#define PGLZ_HISTORY_LISTS 8192 /* must be power of 2 */
#define PGLZ_HISTORY_LISTS 8192 /* must be power of 2 */
#define PGLZ_HISTORY_MASK (PGLZ_HISTORY_LISTS - 1)
#define PGLZ_HISTORY_SIZE 4096
#define PGLZ_MAX_MATCH 273
@@ -202,7 +202,7 @@
*/
typedef struct PGLZ_HistEntry
{
struct PGLZ_HistEntry *next; /* links for my hash key's list */
struct PGLZ_HistEntry *next; /* links for my hash key's list */
struct PGLZ_HistEntry *prev;
int hindex; /* my current hash key */
char *pos; /* my input position */
@@ -418,8 +418,8 @@ pglz_find_match(PGLZ_HistEntry **hstart, char *input, char *end,
* the best so far. And if we already have a match of 16 or more
* bytes, it's worth the call overhead to use memcmp() to check if
* this match is equal for the same size. After that we must
* fallback to character by character comparison to know the
* exact position where the diff occured.
* fallback to character by character comparison to know the exact
* position where the diff occured.
*/
thislen = 0;
if (len >= 16)
@@ -559,9 +559,8 @@ pglz_compress(char *source, int32 slen, PGLZ_Header *dest, PGLZ_Strategy *strate
good_drop = 100;
/*
* Initialize the history lists to empty. We do not need to zero
* the hist_entries[] array; its entries are initialized as they
* are used.
* Initialize the history lists to empty. We do not need to zero the
* hist_entries[] array; its entries are initialized as they are used.
*/
memset((void *) hist_start, 0, sizeof(hist_start));

View File

@@ -6,7 +6,7 @@
* A pseudo-type isn't really a type and never has any operations, but
* we do need to supply input and output functions to satisfy the links
* in the pseudo-type's entry in pg_type. In most cases the functions
* just throw an error if invoked. (XXX the error messages here cover
* just throw an error if invoked. (XXX the error messages here cover
* the most common case, but might be confusing in some contexts. Can
* we do better?)
*
@@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.3 2002/08/26 17:53:58 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pseudotypes.c,v 1.4 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -127,7 +127,7 @@ anyarray_out(PG_FUNCTION_ARGS)
* void_in - input routine for pseudo-type VOID.
*
* We allow this so that PL functions can return VOID without any special
* hack in the PL handler. Whatever value the PL thinks it's returning
* hack in the PL handler. Whatever value the PL thinks it's returning
* will just be ignored.
*/
Datum

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.41 2002/06/20 20:29:38 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regexp.c,v 1.42 2002/09/04 20:31:28 momjian Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
@@ -53,7 +53,7 @@ struct cached_re_str
static int rec = 0; /* # of cached re's */
static struct cached_re_str rev[MAX_CACHED_RES]; /* cached re's */
static unsigned long lru; /* system lru tag */
static int pg_lastrec = 0;
static int pg_lastrec = 0;
/* attempt to compile `re' as an re, then match it against text */
/* cflags - flag to regcomp indicates case sensitivity */
@@ -70,9 +70,9 @@ RE_compile_and_execute(text *text_re, char *text, int cflags,
re = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(text_re)));
/* Find a previously compiled regular expression.
* Run the cache as a ring buffer, starting the search
* from the previous match if any.
/*
* Find a previously compiled regular expression. Run the cache as a
* ring buffer, starting the search from the previous match if any.
*/
i = pg_lastrec;
while (i < rec)
@@ -92,19 +92,16 @@ RE_compile_and_execute(text *text_re, char *text, int cflags,
}
i++;
/* If we were not at the first slot to start,
* then think about wrapping if necessary.
/*
* If we were not at the first slot to start, then think about
* wrapping if necessary.
*/
if (pg_lastrec != 0)
{
if (i >= rec)
{
i = 0;
}
else if (i == pg_lastrec)
{
break;
}
}
}
@@ -119,9 +116,7 @@ RE_compile_and_execute(text *text_re, char *text, int cflags,
}
}
else
{
oldest = rec++;
}
/* if there was an old re, then de-allocate the space it used */
if (rev[oldest].cre_s != (char *) NULL)
@@ -148,6 +143,7 @@ RE_compile_and_execute(text *text_re, char *text, int cflags,
if (regcomp_result == 0)
{
pg_lastrec = oldest;
/*
* use malloc/free for the cre_s field because the storage has to
* persist across transactions
@@ -329,10 +325,11 @@ textregexsubstr(PG_FUNCTION_ARGS)
sterm = (char *) palloc(len + 1);
memcpy(sterm, VARDATA(s), len);
sterm[len] = '\0';
/* We need the match info back from the pattern match
* to be able to actually extract the substring.
* It seems to be adequate to pass in a structure to return
* only one result.
/*
* We need the match info back from the pattern match to be able to
* actually extract the substring. It seems to be adequate to pass in
* a structure to return only one result.
*/
match = RE_compile_and_execute(p, sterm, REG_EXTENDED, nmatch, &pmatch);
pfree(sterm);
@@ -342,8 +339,8 @@ textregexsubstr(PG_FUNCTION_ARGS)
{
return (DirectFunctionCall3(text_substr,
PointerGetDatum(s),
Int32GetDatum(pmatch.rm_so+1),
Int32GetDatum(pmatch.rm_eo-pmatch.rm_so)));
Int32GetDatum(pmatch.rm_so + 1),
Int32GetDatum(pmatch.rm_eo - pmatch.rm_so)));
}
PG_RETURN_NULL();

View File

@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.74 2002/09/02 01:05:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.75 2002/09/04 20:31:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -38,8 +38,8 @@
#include "utils/syscache.h"
static void parseNameAndArgTypes(const char *string, const char *caller,
bool allowNone,
List **names, int *nargs, Oid *argtypes);
bool allowNone,
List **names, int *nargs, Oid *argtypes);
/*****************************************************************************
@@ -87,7 +87,7 @@ regprocin(PG_FUNCTION_ARGS)
/*
* In bootstrap mode we assume the given name is not schema-qualified,
* and just search pg_proc for a unique match. This is needed for
* and just search pg_proc for a unique match. This is needed for
* initializing other system catalogs (pg_namespace may not exist yet,
* and certainly there are no schemas other than pg_catalog).
*/
@@ -96,7 +96,7 @@ regprocin(PG_FUNCTION_ARGS)
int matches = 0;
Relation hdesc;
ScanKeyData skey[1];
SysScanDesc sysscan;
SysScanDesc sysscan;
HeapTuple tuple;
ScanKeyEntryInitialize(&skey[0], 0x0,
@@ -127,8 +127,8 @@ regprocin(PG_FUNCTION_ARGS)
}
/*
* Normal case: parse the name into components and see if it
* matches any pg_proc entries in the current search path.
* Normal case: parse the name into components and see if it matches
* any pg_proc entries in the current search path.
*/
names = stringToQualifiedNameList(pro_name_or_oid, "regprocin");
clist = FuncnameGetCandidates(names, -1);
@@ -175,17 +175,15 @@ regprocout(PG_FUNCTION_ARGS)
* output anyway.)
*/
if (IsBootstrapProcessingMode())
{
result = pstrdup(proname);
}
else
{
char *nspname;
FuncCandidateList clist;
/*
* Would this proc be found (uniquely!) by regprocin?
* If not, qualify it.
* Would this proc be found (uniquely!) by regprocin? If not,
* qualify it.
*/
clist = FuncnameGetCandidates(makeList1(makeString(proname)), -1);
if (clist != NULL && clist->next == NULL &&
@@ -250,10 +248,10 @@ regprocedurein(PG_FUNCTION_ARGS)
}
/*
* Else it's a name and arguments. Parse the name and arguments,
* look up potential matches in the current namespace search list,
* and scan to see which one exactly matches the given argument
* types. (There will not be more than one match.)
* Else it's a name and arguments. Parse the name and arguments, look
* up potential matches in the current namespace search list, and scan
* to see which one exactly matches the given argument types. (There
* will not be more than one match.)
*
* XXX at present, this code will not work in bootstrap mode, hence this
* datatype cannot be used for any system column that needs to receive
@@ -308,8 +306,8 @@ format_procedure(Oid procedure_oid)
initStringInfo(&buf);
/*
* Would this proc be found (given the right args) by regprocedurein?
* If not, we need to qualify it.
* Would this proc be found (given the right args) by
* regprocedurein? If not, we need to qualify it.
*/
if (FunctionIsVisible(procedure_oid))
nspname = NULL;
@@ -320,7 +318,7 @@ format_procedure(Oid procedure_oid)
quote_qualified_identifier(nspname, proname));
for (i = 0; i < nargs; i++)
{
Oid thisargtype = procform->proargtypes[i];
Oid thisargtype = procform->proargtypes[i];
if (i > 0)
appendStringInfoChar(&buf, ',');
@@ -401,7 +399,7 @@ regoperin(PG_FUNCTION_ARGS)
/*
* In bootstrap mode we assume the given name is not schema-qualified,
* and just search pg_operator for a unique match. This is needed for
* and just search pg_operator for a unique match. This is needed for
* initializing other system catalogs (pg_namespace may not exist yet,
* and certainly there are no schemas other than pg_catalog).
*/
@@ -410,7 +408,7 @@ regoperin(PG_FUNCTION_ARGS)
int matches = 0;
Relation hdesc;
ScanKeyData skey[1];
SysScanDesc sysscan;
SysScanDesc sysscan;
HeapTuple tuple;
ScanKeyEntryInitialize(&skey[0], 0x0,
@@ -441,8 +439,8 @@ regoperin(PG_FUNCTION_ARGS)
}
/*
* Normal case: parse the name into components and see if it
* matches any pg_operator entries in the current search path.
* Normal case: parse the name into components and see if it matches
* any pg_operator entries in the current search path.
*/
names = stringToQualifiedNameList(opr_name_or_oid, "regoperin");
clist = OpernameGetCandidates(names, '\0');
@@ -489,16 +487,14 @@ regoperout(PG_FUNCTION_ARGS)
* output anyway.)
*/
if (IsBootstrapProcessingMode())
{
result = pstrdup(oprname);
}
else
{
FuncCandidateList clist;
/*
* Would this oper be found (uniquely!) by regoperin?
* If not, qualify it.
* Would this oper be found (uniquely!) by regoperin? If not,
* qualify it.
*/
clist = OpernameGetCandidates(makeList1(makeString(oprname)),
'\0');
@@ -511,7 +507,7 @@ regoperout(PG_FUNCTION_ARGS)
nspname = get_namespace_name(operform->oprnamespace);
nspname = quote_identifier(nspname);
result = (char *) palloc(strlen(nspname)+strlen(oprname)+2);
result = (char *) palloc(strlen(nspname) + strlen(oprname) + 2);
sprintf(result, "%s.%s", nspname, oprname);
}
}
@@ -520,7 +516,10 @@ regoperout(PG_FUNCTION_ARGS)
}
else
{
/* If OID doesn't match any pg_operator entry, return it numerically */
/*
* If OID doesn't match any pg_operator entry, return it
* numerically
*/
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", oprid);
}
@@ -570,10 +569,10 @@ regoperatorin(PG_FUNCTION_ARGS)
}
/*
* Else it's a name and arguments. Parse the name and arguments,
* look up potential matches in the current namespace search list,
* and scan to see which one exactly matches the given argument
* types. (There will not be more than one match.)
* Else it's a name and arguments. Parse the name and arguments, look
* up potential matches in the current namespace search list, and scan
* to see which one exactly matches the given argument types. (There
* will not be more than one match.)
*
* XXX at present, this code will not work in bootstrap mode, hence this
* datatype cannot be used for any system column that needs to receive
@@ -637,8 +636,8 @@ format_operator(Oid operator_oid)
initStringInfo(&buf);
/*
* Would this oper be found (given the right args) by regoperatorin?
* If not, we need to qualify it.
* Would this oper be found (given the right args) by
* regoperatorin? If not, we need to qualify it.
*/
if (!OperatorIsVisible(operator_oid))
{
@@ -667,7 +666,10 @@ format_operator(Oid operator_oid)
}
else
{
/* If OID doesn't match any pg_operator entry, return it numerically */
/*
* If OID doesn't match any pg_operator entry, return it
* numerically
*/
result = (char *) palloc(NAMEDATALEN);
snprintf(result, NAMEDATALEN, "%u", operator_oid);
}
@@ -715,12 +717,12 @@ regclassin(PG_FUNCTION_ARGS)
/* Numeric OID? */
if (class_name_or_oid[0] >= '0' &&
class_name_or_oid[0] <= '9' &&
strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))
{
Oid searchOid;
searchOid = DatumGetObjectId(DirectFunctionCall1(oidin,
CStringGetDatum(class_name_or_oid)));
CStringGetDatum(class_name_or_oid)));
result = GetSysCacheOid(RELOID,
ObjectIdGetDatum(searchOid),
0, 0, 0);
@@ -741,7 +743,7 @@ regclassin(PG_FUNCTION_ARGS)
{
Relation hdesc;
ScanKeyData skey[1];
SysScanDesc sysscan;
SysScanDesc sysscan;
HeapTuple tuple;
ScanKeyEntryInitialize(&skey[0], 0x0,
@@ -767,8 +769,8 @@ regclassin(PG_FUNCTION_ARGS)
}
/*
* Normal case: parse the name into components and see if it
* matches any pg_class entries in the current search path.
* Normal case: parse the name into components and see if it matches
* any pg_class entries in the current search path.
*/
names = stringToQualifiedNameList(class_name_or_oid, "regclassin");
@@ -808,16 +810,14 @@ regclassout(PG_FUNCTION_ARGS)
* output anyway.)
*/
if (IsBootstrapProcessingMode())
{
result = pstrdup(classname);
}
else
{
char *nspname;
/*
* Would this class be found by regclassin?
* If not, qualify it.
* Would this class be found by regclassin? If not, qualify
* it.
*/
if (RelationIsVisible(classid))
nspname = NULL;
@@ -894,7 +894,7 @@ regtypein(PG_FUNCTION_ARGS)
{
Relation hdesc;
ScanKeyData skey[1];
SysScanDesc sysscan;
SysScanDesc sysscan;
HeapTuple tuple;
ScanKeyEntryInitialize(&skey[0], 0x0,
@@ -920,8 +920,8 @@ regtypein(PG_FUNCTION_ARGS)
}
/*
* Normal case: invoke the full parser to deal with special cases
* such as array syntax.
* Normal case: invoke the full parser to deal with special cases such
* as array syntax.
*/
parseTypeString(typ_name_or_oid, &result, &typmod);
@@ -964,9 +964,7 @@ regtypeout(PG_FUNCTION_ARGS)
result = pstrdup(typname);
}
else
{
result = format_type_be(typid);
}
ReleaseSysCache(typetup);
}
@@ -1003,7 +1001,7 @@ stringToQualifiedNameList(const char *string, const char *caller)
foreach(l, namelist)
{
char *curname = (char *) lfirst(l);
char *curname = (char *) lfirst(l);
result = lappend(result, makeString(pstrdup(curname)));
}
@@ -1020,7 +1018,7 @@ stringToQualifiedNameList(const char *string, const char *caller)
/*
* Given a C string, parse it into a qualified function or operator name
* followed by a parenthesized list of type names. Reduce the
* followed by a parenthesized list of type names. Reduce the
* type names to an array of OIDs (returned into *nargs and *argtypes;
* the argtypes array should be of size FUNC_MAX_ARGS). The function or
* operator name is returned to *names as a List of Strings.

View File

@@ -17,7 +17,7 @@
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.41 2002/09/02 06:11:42 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.42 2002/09/04 20:31:28 momjian Exp $
*
* ----------
*/
@@ -131,9 +131,9 @@ static void ri_BuildQueryKeyFull(RI_QueryKey *key, Oid constr_id,
Relation fk_rel, Relation pk_rel,
int argc, char **argv);
static void ri_BuildQueryKeyPkCheck(RI_QueryKey *key, Oid constr_id,
int32 constr_queryno,
Relation pk_rel,
int argc, char **argv);
int32 constr_queryno,
Relation pk_rel,
int argc, char **argv);
static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup,
RI_QueryKey *key, int pairidx);
static bool ri_AllKeysUnequal(Relation rel, HeapTuple oldtup, HeapTuple newtup,
@@ -141,8 +141,8 @@ static bool ri_AllKeysUnequal(Relation rel, HeapTuple oldtup, HeapTuple newtup,
static bool ri_OneKeyEqual(Relation rel, int column, HeapTuple oldtup,
HeapTuple newtup, RI_QueryKey *key, int pairidx);
static bool ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue);
static bool ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row,
Oid tgoid, int match_type, int tgnargs, char **tgargs);
static bool ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row,
Oid tgoid, int match_type, int tgnargs, char **tgargs);
static void ri_InitHashTables(void);
static void *ri_FetchPreparedPlan(RI_QueryKey *key);
@@ -205,8 +205,8 @@ RI_FKey_check(PG_FUNCTION_ARGS)
* Get the relation descriptors of the FK and PK tables and the new
* tuple.
*
* pk_rel is opened in RowShareLock mode since that's what our
* eventual SELECT FOR UPDATE will get on it.
* pk_rel is opened in RowShareLock mode since that's what our eventual
* SELECT FOR UPDATE will get on it.
*/
fk_rel = trigdata->tg_relation;
pk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
@@ -223,11 +223,13 @@ RI_FKey_check(PG_FUNCTION_ARGS)
/*
* We should not even consider checking the row if it is no longer
* valid since it was either deleted (doesn't matter) or updated
* (in which case it'll be checked with its final values).
* valid since it was either deleted (doesn't matter) or updated (in
* which case it'll be checked with its final values).
*/
if (new_row) {
if (!HeapTupleSatisfiesItself(new_row->t_data)) {
if (new_row)
{
if (!HeapTupleSatisfiesItself(new_row->t_data))
{
heap_close(pk_rel, RowShareLock);
return PointerGetDatum(NULL);
}
@@ -263,7 +265,7 @@ RI_FKey_check(PG_FUNCTION_ARGS)
*/
quoteRelationName(pkrelname, pk_rel);
snprintf(querystr, sizeof(querystr), "SELECT 1 FROM ONLY %s x FOR UPDATE OF x",
pkrelname);
pkrelname);
/*
* Prepare, save and remember the new plan.
@@ -418,9 +420,9 @@ RI_FKey_check(PG_FUNCTION_ARGS)
for (i = 0; i < qkey.nkeypairs; i++)
{
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_PK_IDX]);
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_PK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(fk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_FK_IDX]);
@@ -521,32 +523,36 @@ RI_FKey_check_upd(PG_FUNCTION_ARGS)
/* ----------
* ri_Check_Pk_Match
*
* Check for matching value of old pk row in current state for
* Check for matching value of old pk row in current state for
* noaction triggers. Returns false if no row was found and a fk row
* could potentially be referencing this row, true otherwise.
* ----------
*/
static bool
ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type, int tgnargs, char **tgargs) {
void *qplan;
ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type, int tgnargs, char **tgargs)
{
void *qplan;
RI_QueryKey qkey;
bool isnull;
bool isnull;
Datum check_values[RI_MAX_NUMKEYS];
char check_nulls[RI_MAX_NUMKEYS + 1];
int i;
int i;
Oid save_uid;
bool result;
bool result;
save_uid = GetUserId();
ri_BuildQueryKeyPkCheck(&qkey, tgoid,
RI_PLAN_CHECK_LOOKUPPK, pk_rel,
tgnargs, tgargs);
RI_PLAN_CHECK_LOOKUPPK, pk_rel,
tgnargs, tgargs);
switch (ri_NullCheck(pk_rel, old_row, &qkey, RI_KEYPAIR_PK_IDX))
{
case RI_KEYS_ALL_NULL:
/*
* No check - nothing could have been referencing this row anyway.
* No check - nothing could have been referencing this row
* anyway.
*/
return true;
@@ -560,10 +566,10 @@ ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type,
{
case RI_MATCH_TYPE_FULL:
case RI_MATCH_TYPE_UNSPECIFIED:
/*
* MATCH <unspecified>/FULL - if ANY column is null, we
* can't be matching to this row already.
* MATCH <unspecified>/FULL - if ANY column is null,
* we can't be matching to this row already.
*/
return true;
@@ -619,9 +625,9 @@ ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type,
for (i = 0; i < qkey.nkeypairs; i++)
{
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_PK_IDX]);
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_PK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -644,7 +650,7 @@ ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type,
{
check_values[i] = SPI_getbinval(old_row,
pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX],
qkey.keypair[i][RI_KEYPAIR_PK_IDX],
&isnull);
if (isnull)
check_nulls[i] = 'n';
@@ -664,7 +670,7 @@ ri_Check_Pk_Match(Relation pk_rel, HeapTuple old_row, Oid tgoid, int match_type,
SetUserId(save_uid);
result = (SPI_processed!=0);
result = (SPI_processed != 0);
if (SPI_finish() != SPI_OK_FINISH)
elog(WARNING, "SPI_finish() failed in ri_Check_Pk_Match()");
@@ -736,8 +742,8 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
* Get the relation descriptors of the FK and PK tables and the old
* tuple.
*
* fk_rel is opened in RowShareLock mode since that's what our
* eventual SELECT FOR UPDATE will get on it.
* fk_rel is opened in RowShareLock mode since that's what our eventual
* SELECT FOR UPDATE will get on it.
*/
fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
pk_rel = trigdata->tg_relation;
@@ -745,10 +751,11 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]);
if (ri_Check_Pk_Match(pk_rel, old_row, trigdata->tg_trigger->tgoid,
match_type, tgnargs, tgargs)) {
/*
* There's either another row, or no row could match this
* one. In either case, we don't need to do the check.
match_type, tgnargs, tgargs))
{
/*
* There's either another row, or no row could match this one. In
* either case, we don't need to do the check.
*/
heap_close(fk_rel, RowShareLock);
return PointerGetDatum(NULL);
@@ -800,7 +807,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
const char *querysep;
@@ -823,7 +830,7 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -959,8 +966,8 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
* Get the relation descriptors of the FK and PK tables and the new
* and old tuple.
*
* fk_rel is opened in RowShareLock mode since that's what our
* eventual SELECT FOR UPDATE will get on it.
* fk_rel is opened in RowShareLock mode since that's what our eventual
* SELECT FOR UPDATE will get on it.
*/
fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
pk_rel = trigdata->tg_relation;
@@ -969,10 +976,11 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]);
if (ri_Check_Pk_Match(pk_rel, old_row, trigdata->tg_trigger->tgoid,
match_type, tgnargs, tgargs)) {
/*
* There's either another row, or no row could match this
* one. In either case, we don't need to do the check.
match_type, tgnargs, tgargs))
{
/*
* There's either another row, or no row could match this one. In
* either case, we don't need to do the check.
*/
heap_close(fk_rel, RowShareLock);
return PointerGetDatum(NULL);
@@ -1034,7 +1042,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
const char *querysep;
@@ -1057,7 +1065,7 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -1241,7 +1249,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
const char *querysep;
@@ -1264,7 +1272,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -1455,7 +1463,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
char qualstr[(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
@@ -1483,9 +1491,9 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
snprintf(qualstr + strlen(qualstr), sizeof(qualstr) - strlen(qualstr), " %s %s = $%d",
qualsep, attname, j+1);
qualsep, attname, j + 1);
querysep = ",";
qualsep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
@@ -1628,8 +1636,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
* Get the relation descriptors of the FK and PK tables and the old
* tuple.
*
* fk_rel is opened in RowShareLock mode since that's what our
* eventual SELECT FOR UPDATE will get on it.
* fk_rel is opened in RowShareLock mode since that's what our eventual
* SELECT FOR UPDATE will get on it.
*/
fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
pk_rel = trigdata->tg_relation;
@@ -1682,7 +1690,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
const char *querysep;
@@ -1705,7 +1713,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -1845,8 +1853,8 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
* Get the relation descriptors of the FK and PK tables and the new
* and old tuple.
*
* fk_rel is opened in RowShareLock mode since that's what our
* eventual SELECT FOR UPDATE will get on it.
* fk_rel is opened in RowShareLock mode since that's what our eventual
* SELECT FOR UPDATE will get on it.
*/
fk_rel = heap_open(trigdata->tg_trigger->tgconstrrelid, RowShareLock);
pk_rel = trigdata->tg_relation;
@@ -1910,7 +1918,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
const char *querysep;
@@ -1933,7 +1941,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), " %s %s = $%d",
querysep, attname, i+1);
querysep, attname, i + 1);
querysep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -2121,7 +2129,7 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
char qualstr[(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
@@ -2149,9 +2157,9 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%s %s = NULL",
querysep, attname);
querysep, attname);
snprintf(qualstr + strlen(qualstr), sizeof(qualstr) - strlen(qualstr), " %s %s = $%d",
qualsep, attname, i+1);
qualsep, attname, i + 1);
querysep = ",";
qualsep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
@@ -2365,7 +2373,7 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
(qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
char qualstr[(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
@@ -2392,6 +2400,7 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
{
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
/*
* MATCH <unspecified> - only change columns
* corresponding to changed columns in pk_rel's key
@@ -2401,11 +2410,11 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
RI_KEYPAIR_PK_IDX))
{
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%s %s = NULL",
querysep, attname);
querysep, attname);
querysep = ",";
}
snprintf(qualstr + strlen(qualstr), sizeof(qualstr) - strlen(qualstr), " %s %s = $%d",
qualsep, attname, i+1);
qualsep, attname, i + 1);
qualsep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -2592,7 +2601,7 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
*/
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
char qualstr[(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
@@ -2625,9 +2634,9 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%s %s = NULL",
querysep, attname);
querysep, attname);
snprintf(qualstr + strlen(qualstr), sizeof(qualstr) - strlen(qualstr), " %s %s = $%d",
qualsep, attname, i+1);
qualsep, attname, i + 1);
querysep = ",";
qualsep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
@@ -2861,7 +2870,7 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
*/
{
char querystr[MAX_QUOTED_REL_NAME_LEN + 100 +
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS * 2];
char qualstr[(MAX_QUOTED_NAME_LEN + 32) * RI_MAX_NUMKEYS];
char fkrelname[MAX_QUOTED_REL_NAME_LEN];
char attname[MAX_QUOTED_NAME_LEN];
@@ -2893,6 +2902,7 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
{
quoteOneName(attname,
tgargs[RI_FIRST_ATTNAME_ARGNO + i * 2 + RI_KEYPAIR_FK_IDX]);
/*
* MATCH <unspecified> - only change columns
* corresponding to changed columns in pk_rel's key
@@ -2902,11 +2912,11 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
new_row, &qkey, RI_KEYPAIR_PK_IDX))
{
snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%s %s = NULL",
querysep, attname);
querysep, attname);
querysep = ",";
}
snprintf(qualstr + strlen(qualstr), sizeof(qualstr) - strlen(qualstr), " %s %s = $%d",
qualsep, attname, i+1);
qualsep, attname, i + 1);
qualsep = "AND";
queryoids[i] = SPI_gettypeid(pk_rel->rd_att,
qkey.keypair[i][RI_KEYPAIR_PK_IDX]);
@@ -3245,8 +3255,8 @@ ri_BuildQueryKeyFull(RI_QueryKey *key, Oid constr_id, int32 constr_queryno,
*/
static void
ri_BuildQueryKeyPkCheck(RI_QueryKey *key, Oid constr_id, int32 constr_queryno,
Relation pk_rel,
int argc, char **argv)
Relation pk_rel,
int argc, char **argv)
{
int i;
int j;
@@ -3588,7 +3598,7 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue)
typeid, typeid, true);
if (!OidIsValid(opr_proc))
elog(ERROR,
"ri_AttributesEqual(): cannot find '=' operator for type %u",
"ri_AttributesEqual(): cannot find '=' operator for type %u",
typeid);
/*
@@ -3616,4 +3626,3 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue)
return DatumGetBool(FunctionCall2(&(entry->oprfmgrinfo),
oldvalue, newvalue));
}

View File

@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.120 2002/08/31 22:10:46 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.121 2002/09/04 20:31:28 momjian Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -124,29 +124,29 @@ static char *query_getviewrule = "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_c
*/
static text *pg_do_getviewdef(Oid viewoid);
static void decompile_column_index_array(Datum column_index_array, Oid relId,
StringInfo buf);
StringInfo buf);
static void make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
static void make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc);
static void get_query_def(Query *query, StringInfo buf, List *parentnamespace,
TupleDesc resultDesc);
TupleDesc resultDesc);
static void get_select_query_def(Query *query, deparse_context *context,
TupleDesc resultDesc);
TupleDesc resultDesc);
static void get_insert_query_def(Query *query, deparse_context *context);
static void get_update_query_def(Query *query, deparse_context *context);
static void get_delete_query_def(Query *query, deparse_context *context);
static void get_utility_query_def(Query *query, deparse_context *context);
static void get_basic_select_query(Query *query, deparse_context *context,
TupleDesc resultDesc);
TupleDesc resultDesc);
static void get_setop_query(Node *setOp, Query *query,
deparse_context *context,
TupleDesc resultDesc);
deparse_context *context,
TupleDesc resultDesc);
static Node *get_rule_sortgroupclause(SortClause *srt, List *tlist,
bool force_colno,
deparse_context *context);
static void get_names_for_var(Var *var, deparse_context *context,
char **schemaname, char **refname, char **attname);
static RangeTblEntry *find_rte_by_refname(const char *refname,
deparse_context *context);
deparse_context *context);
static void get_rule_expr(Node *node, deparse_context *context);
static void get_oper_expr(Expr *expr, deparse_context *context);
static void get_func_expr(Expr *expr, deparse_context *context);
@@ -159,7 +159,7 @@ static void get_from_clause(Query *query, deparse_context *context);
static void get_from_clause_item(Node *jtnode, Query *query,
deparse_context *context);
static void get_from_clause_coldeflist(List *coldeflist,
deparse_context *context);
deparse_context *context);
static void get_opclass_name(Oid opclass, Oid actual_datatype,
StringInfo buf);
static bool tleIsArrayAssign(TargetEntry *tle);
@@ -284,7 +284,7 @@ pg_get_viewdef_name(PG_FUNCTION_ARGS)
text *ruledef;
viewrel = makeRangeVarFromNameList(textToQualifiedNameList(viewname,
"get_viewdef"));
"get_viewdef"));
viewoid = RangeVarGetRelid(viewrel, false);
ruledef = pg_do_getviewdef(viewoid);
@@ -425,8 +425,8 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
amrec = (Form_pg_am) GETSTRUCT(ht_am);
/*
* Start the index definition. Note that the index's name should never
* be schema-qualified, but the indexed rel's name may be.
* Start the index definition. Note that the index's name should
* never be schema-qualified, but the indexed rel's name may be.
*/
initStringInfo(&buf);
appendStringInfo(&buf, "CREATE %sINDEX %s ON %s USING %s (",
@@ -551,15 +551,15 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
Datum
pg_get_constraintdef(PG_FUNCTION_ARGS)
{
Oid constraintId = PG_GETARG_OID(0);
text *result;
StringInfoData buf;
int len;
Relation conDesc;
SysScanDesc conscan;
ScanKeyData skey[1];
HeapTuple tup;
Form_pg_constraint conForm;
Oid constraintId = PG_GETARG_OID(0);
text *result;
StringInfoData buf;
int len;
Relation conDesc;
SysScanDesc conscan;
ScanKeyData skey[1];
HeapTuple tup;
Form_pg_constraint conForm;
/*
* Fetch the pg_constraint row. There's no syscache for pg_constraint
@@ -584,111 +584,111 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
switch (conForm->contype)
{
case CONSTRAINT_FOREIGN:
{
Datum val;
bool isnull;
const char *string;
{
Datum val;
bool isnull;
const char *string;
/* Start off the constraint definition */
appendStringInfo(&buf, "FOREIGN KEY (");
/* Start off the constraint definition */
appendStringInfo(&buf, "FOREIGN KEY (");
/* Fetch and build referencing-column list */
val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u",
constraintId);
/* Fetch and build referencing-column list */
val = heap_getattr(tup, Anum_pg_constraint_conkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
elog(ERROR, "pg_get_constraintdef: Null conkey for constraint %u",
constraintId);
decompile_column_index_array(val, conForm->conrelid, &buf);
decompile_column_index_array(val, conForm->conrelid, &buf);
/* add foreign relation name */
appendStringInfo(&buf, ") REFERENCES %s(",
/* add foreign relation name */
appendStringInfo(&buf, ") REFERENCES %s(",
generate_relation_name(conForm->confrelid));
/* Fetch and build referenced-column list */
val = heap_getattr(tup, Anum_pg_constraint_confkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
elog(ERROR, "pg_get_constraintdef: Null confkey for constraint %u",
constraintId);
/* Fetch and build referenced-column list */
val = heap_getattr(tup, Anum_pg_constraint_confkey,
RelationGetDescr(conDesc), &isnull);
if (isnull)
elog(ERROR, "pg_get_constraintdef: Null confkey for constraint %u",
constraintId);
decompile_column_index_array(val, conForm->confrelid, &buf);
decompile_column_index_array(val, conForm->confrelid, &buf);
appendStringInfo(&buf, ")");
appendStringInfo(&buf, ")");
/* Add match type */
switch (conForm->confmatchtype)
{
case FKCONSTR_MATCH_FULL:
string = " MATCH FULL";
break;
case FKCONSTR_MATCH_PARTIAL:
string = " MATCH PARTIAL";
break;
case FKCONSTR_MATCH_UNSPECIFIED:
string = "";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confmatchtype '%c' for constraint %u",
conForm->confmatchtype, constraintId);
string = ""; /* keep compiler quiet */
break;
/* Add match type */
switch (conForm->confmatchtype)
{
case FKCONSTR_MATCH_FULL:
string = " MATCH FULL";
break;
case FKCONSTR_MATCH_PARTIAL:
string = " MATCH PARTIAL";
break;
case FKCONSTR_MATCH_UNSPECIFIED:
string = "";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confmatchtype '%c' for constraint %u",
conForm->confmatchtype, constraintId);
string = ""; /* keep compiler quiet */
break;
}
appendStringInfo(&buf, "%s", string);
/* Add ON UPDATE and ON DELETE clauses */
switch (conForm->confupdtype)
{
case FKCONSTR_ACTION_NOACTION:
string = "NO ACTION";
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
break;
case FKCONSTR_ACTION_CASCADE:
string = "CASCADE";
break;
case FKCONSTR_ACTION_SETNULL:
string = "SET NULL";
break;
case FKCONSTR_ACTION_SETDEFAULT:
string = "SET DEFAULT";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confupdtype '%c' for constraint %u",
conForm->confupdtype, constraintId);
string = ""; /* keep compiler quiet */
break;
}
appendStringInfo(&buf, " ON UPDATE %s", string);
switch (conForm->confdeltype)
{
case FKCONSTR_ACTION_NOACTION:
string = "NO ACTION";
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
break;
case FKCONSTR_ACTION_CASCADE:
string = "CASCADE";
break;
case FKCONSTR_ACTION_SETNULL:
string = "SET NULL";
break;
case FKCONSTR_ACTION_SETDEFAULT:
string = "SET DEFAULT";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confdeltype '%c' for constraint %u",
conForm->confdeltype, constraintId);
string = ""; /* keep compiler quiet */
break;
}
appendStringInfo(&buf, " ON DELETE %s", string);
break;
}
appendStringInfo(&buf, "%s", string);
/* Add ON UPDATE and ON DELETE clauses */
switch (conForm->confupdtype)
{
case FKCONSTR_ACTION_NOACTION:
string = "NO ACTION";
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
break;
case FKCONSTR_ACTION_CASCADE:
string = "CASCADE";
break;
case FKCONSTR_ACTION_SETNULL:
string = "SET NULL";
break;
case FKCONSTR_ACTION_SETDEFAULT:
string = "SET DEFAULT";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confupdtype '%c' for constraint %u",
conForm->confupdtype, constraintId);
string = ""; /* keep compiler quiet */
break;
}
appendStringInfo(&buf, " ON UPDATE %s", string);
switch (conForm->confdeltype)
{
case FKCONSTR_ACTION_NOACTION:
string = "NO ACTION";
break;
case FKCONSTR_ACTION_RESTRICT:
string = "RESTRICT";
break;
case FKCONSTR_ACTION_CASCADE:
string = "CASCADE";
break;
case FKCONSTR_ACTION_SETNULL:
string = "SET NULL";
break;
case FKCONSTR_ACTION_SETDEFAULT:
string = "SET DEFAULT";
break;
default:
elog(ERROR, "pg_get_constraintdef: Unknown confdeltype '%c' for constraint %u",
conForm->confdeltype, constraintId);
string = ""; /* keep compiler quiet */
break;
}
appendStringInfo(&buf, " ON DELETE %s", string);
break;
}
/*
* XXX Add more code here for other contypes
@@ -735,7 +735,7 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
{
char *colName;
colName = get_attname(relId, DatumGetInt16(keys[j]));
colName = get_attname(relId, DatumGetInt16(keys[j]));
if (j == 0)
appendStringInfo(buf, "%s",
@@ -875,7 +875,7 @@ deparse_expression(Node *expr, List *dpcontext, bool forceprefix)
*
* Given the reference name (alias) and OID of a relation, build deparsing
* context for an expression referencing only that relation (as varno 1,
* varlevelsup 0). This is sufficient for many uses of deparse_expression.
* varlevelsup 0). This is sufficient for many uses of deparse_expression.
* ----------
*/
List *
@@ -972,7 +972,7 @@ deparse_context_for_subplan(const char *name, List *tlist,
foreach(tl, tlist)
{
TargetEntry *tle = lfirst(tl);
Resdom *resdom = tle->resdom;
Resdom *resdom = tle->resdom;
nattrs++;
Assert(resdom->resno == nattrs);
@@ -983,13 +983,13 @@ deparse_context_for_subplan(const char *name, List *tlist,
}
if (tle->expr && IsA(tle->expr, Var))
{
Var *var = (Var *) tle->expr;
Var *var = (Var *) tle->expr;
/* varno/varattno won't be any good, but varnoold might be */
if (var->varnoold > 0 && var->varnoold <= rtablelength)
{
RangeTblEntry *varrte = rt_fetch(var->varnoold, rtable);
char *varname;
char *varname;
varname = get_rte_attribute_name(varrte, var->varoattno);
attrs = lappend(attrs, makeString(varname));
@@ -1001,7 +1001,7 @@ deparse_context_for_subplan(const char *name, List *tlist,
attrs = lappend(attrs, makeString(pstrdup(buf)));
}
rte->rtekind = RTE_SPECIAL; /* XXX */
rte->rtekind = RTE_SPECIAL; /* XXX */
rte->relid = InvalidOid;
rte->eref = makeAlias(name, attrs);
rte->inh = false;
@@ -1127,9 +1127,9 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc)
query = (Query *) lfirst(actions);
/*
* If the action is INSERT...SELECT, OLD/NEW have been pushed
* down into the SELECT, and that's what we need to look at.
* (Ugly kluge ... try to fix this when we redesign querytrees.)
* If the action is INSERT...SELECT, OLD/NEW have been pushed down
* into the SELECT, and that's what we need to look at. (Ugly
* kluge ... try to fix this when we redesign querytrees.)
*/
query = getInsertSelectQuery(query, NULL);
@@ -1434,13 +1434,13 @@ get_basic_select_query(Query *query, deparse_context *context,
get_rule_expr(tle->expr, context);
/*
* Figure out what the result column should be called. In the
* Figure out what the result column should be called. In the
* context of a view, use the view's tuple descriptor (so as to
* pick up the effects of any column RENAME that's been done on the
* view). Otherwise, just use what we can find in the TLE.
* pick up the effects of any column RENAME that's been done on
* the view). Otherwise, just use what we can find in the TLE.
*/
if (resultDesc && colno <= resultDesc->natts)
colname = NameStr(resultDesc->attrs[colno-1]->attname);
colname = NameStr(resultDesc->attrs[colno - 1]->attname);
else
colname = tle->resdom->resname;
@@ -1751,8 +1751,8 @@ get_utility_query_def(Query *query, deparse_context *context)
NotifyStmt *stmt = (NotifyStmt *) query->utilityStmt;
appendStringInfo(buf, "NOTIFY %s",
quote_qualified_identifier(stmt->relation->schemaname,
stmt->relation->relname));
quote_qualified_identifier(stmt->relation->schemaname,
stmt->relation->relname));
}
else
elog(ERROR, "get_utility_query_def: unexpected statement type");
@@ -1762,7 +1762,7 @@ get_utility_query_def(Query *query, deparse_context *context)
/*
* Get the schemaname, refname and attname for a (possibly nonlocal) Var.
*
* schemaname is usually returned as NULL. It will be non-null only if
* schemaname is usually returned as NULL. It will be non-null only if
* use of the unqualified refname would find the wrong RTE.
*
* refname will be returned as NULL if the Var references an unnamed join.
@@ -1813,9 +1813,10 @@ get_names_for_var(Var *var, deparse_context *context,
if (rte->rtekind == RTE_RELATION)
{
/*
* It's possible that use of the bare refname would find another
* more-closely-nested RTE, or be ambiguous, in which case
* we need to specify the schemaname to avoid these errors.
* It's possible that use of the bare refname would find
* another more-closely-nested RTE, or be ambiguous, in which
* case we need to specify the schemaname to avoid these
* errors.
*/
if (find_rte_by_refname(rte->eref->aliasname, context) != rte)
*schemaname =
@@ -1864,7 +1865,7 @@ find_rte_by_refname(const char *refname, deparse_context *context)
if (strcmp(rte->eref->aliasname, refname) == 0)
{
if (result)
return NULL; /* it's ambiguous */
return NULL; /* it's ambiguous */
result = rte;
}
}
@@ -1964,8 +1965,8 @@ get_rule_expr(Node *node, deparse_context *context)
Assert(length(args) == 2);
{
/* binary operator */
Node *arg1 = (Node *) lfirst(args);
Node *arg2 = (Node *) lsecond(args);
Node *arg1 = (Node *) lfirst(args);
Node *arg2 = (Node *) lsecond(args);
get_rule_expr(arg1, context);
appendStringInfo(buf, " IS DISTINCT FROM ");
@@ -2007,10 +2008,11 @@ get_rule_expr(Node *node, deparse_context *context)
break;
case SUBPLAN_EXPR:
/*
* We cannot see an already-planned subplan in rule
* deparsing, only while EXPLAINing a query plan.
* For now, just punt.
* We cannot see an already-planned subplan in
* rule deparsing, only while EXPLAINing a query
* plan. For now, just punt.
*/
appendStringInfo(buf, "(subplan)");
break;
@@ -2089,6 +2091,7 @@ get_rule_expr(Node *node, deparse_context *context)
ReleaseSysCache(typetup);
fieldname = get_relid_attribute_name(typrelid,
fselect->fieldnum);
/*
* If the argument is simple enough, we could emit
* arg.fieldname, but most cases where FieldSelect is used
@@ -2108,7 +2111,7 @@ get_rule_expr(Node *node, deparse_context *context)
get_rule_expr(relabel->arg, context);
appendStringInfo(buf, ")::%s",
format_type_with_typemod(relabel->resulttype,
relabel->resulttypmod));
relabel->resulttypmod));
}
break;
@@ -2246,8 +2249,8 @@ get_oper_expr(Expr *expr, deparse_context *context)
if (length(args) == 2)
{
/* binary operator */
Node *arg1 = (Node *) lfirst(args);
Node *arg2 = (Node *) lsecond(args);
Node *arg1 = (Node *) lfirst(args);
Node *arg2 = (Node *) lsecond(args);
get_rule_expr(arg1, context);
appendStringInfo(buf, " %s ",
@@ -2332,9 +2335,9 @@ get_func_expr(Expr *expr, deparse_context *context)
/*
* Show typename with appropriate length decoration. Note that
* since exprIsLengthCoercion succeeded, the function's output
* type is the right thing to report. Also note we don't need
* to quote the result of format_type_with_typemod: it takes
* care of double-quoting any identifier that needs it.
* type is the right thing to report. Also note we don't need to
* quote the result of format_type_with_typemod: it takes care of
* double-quoting any identifier that needs it.
*/
typdesc = format_type_with_typemod(rettype, coercedTypmod);
appendStringInfo(buf, ")::%s", typdesc);
@@ -2344,8 +2347,8 @@ get_func_expr(Expr *expr, deparse_context *context)
}
/*
* Normal function: display as proname(args). First we need to extract
* the argument datatypes.
* Normal function: display as proname(args). First we need to
* extract the argument datatypes.
*/
nargs = 0;
foreach(l, expr->args)
@@ -2354,7 +2357,7 @@ get_func_expr(Expr *expr, deparse_context *context)
argtypes[nargs] = exprType((Node *) lfirst(l));
nargs++;
}
appendStringInfo(buf, "%s(",
generate_function_name(funcoid, nargs, argtypes));
@@ -2378,7 +2381,7 @@ get_agg_expr(Aggref *aggref, deparse_context *context)
Oid argtype = exprType(aggref->target);
appendStringInfo(buf, "%s(%s",
generate_function_name(aggref->aggfnoid, 1, &argtype),
generate_function_name(aggref->aggfnoid, 1, &argtype),
aggref->aggdistinct ? "DISTINCT " : "");
if (aggref->aggstar)
appendStringInfo(buf, "*");
@@ -2438,8 +2441,8 @@ strip_type_coercion(Node *expr, Oid resultType)
}
/* See if function has is actually declared as a cast */
castTuple = SearchSysCache(CASTSOURCETARGET,
ObjectIdGetDatum(procStruct->proargtypes[0]),
ObjectIdGetDatum(procStruct->prorettype),
ObjectIdGetDatum(procStruct->proargtypes[0]),
ObjectIdGetDatum(procStruct->prorettype),
0, 0);
if (!HeapTupleIsValid(castTuple))
{
@@ -2519,11 +2522,11 @@ get_const_expr(Const *constval, deparse_context *context)
if (constval->constisnull)
{
/*
* Always label the type of a NULL constant to prevent misdecisions
* about type when reparsing.
* Always label the type of a NULL constant to prevent
* misdecisions about type when reparsing.
*/
appendStringInfo(buf, "NULL::%s",
format_type_with_typemod(constval->consttype, -1));
format_type_with_typemod(constval->consttype, -1));
return;
}
@@ -2549,23 +2552,23 @@ get_const_expr(Const *constval, deparse_context *context)
case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
{
/*
* These types are printed without quotes unless they
* contain values that aren't accepted by the scanner
* unquoted (e.g., 'NaN'). Note that strtod() and friends
* might accept NaN, so we can't use that to test.
*
* In reality we only need to defend against infinity and
* NaN, so we need not get too crazy about pattern
* matching here.
*/
if (strspn(extval, "0123456789 +-eE.") == strlen(extval))
appendStringInfo(buf, extval);
else
appendStringInfo(buf, "'%s'", extval);
}
break;
{
/*
* These types are printed without quotes unless they
* contain values that aren't accepted by the scanner
* unquoted (e.g., 'NaN'). Note that strtod() and friends
* might accept NaN, so we can't use that to test.
*
* In reality we only need to defend against infinity and
* NaN, so we need not get too crazy about pattern
* matching here.
*/
if (strspn(extval, "0123456789 +-eE.") == strlen(extval))
appendStringInfo(buf, extval);
else
appendStringInfo(buf, "'%s'", extval);
}
break;
case BITOID:
case VARBITOID:
@@ -2573,13 +2576,14 @@ get_const_expr(Const *constval, deparse_context *context)
break;
case BOOLOID:
if (strcmp(extval, "t")==0)
if (strcmp(extval, "t") == 0)
appendStringInfo(buf, "true");
else
appendStringInfo(buf, "false");
break;
default:
/*
* We must quote any funny characters in the constant's
* representation. XXX Any MULTIBYTE considerations here?
@@ -2665,9 +2669,10 @@ get_sublink_expr(Node *node, deparse_context *context)
/*
* XXX we assume here that we can get away without qualifying the
* operator name. Since the name may imply multiple physical operators
* it's rather difficult to do otherwise --- in fact, if the operators
* are in different namespaces any attempt to qualify would surely fail.
* operator name. Since the name may imply multiple physical
* operators it's rather difficult to do otherwise --- in fact, if the
* operators are in different namespaces any attempt to qualify would
* surely fail.
*/
switch (sublink->subLinkType)
{
@@ -2812,13 +2817,13 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
}
}
else if (rte->rtekind == RTE_RELATION &&
strcmp(rte->eref->aliasname, get_rel_name(rte->relid)) != 0)
strcmp(rte->eref->aliasname, get_rel_name(rte->relid)) != 0)
{
/*
* Apparently the rel has been renamed since the rule was made.
* Emit a fake alias clause so that variable references will
* still work. This is not a 100% solution but should work in
* most reasonable situations.
* Apparently the rel has been renamed since the rule was
* made. Emit a fake alias clause so that variable references
* will still work. This is not a 100% solution but should
* work in most reasonable situations.
*/
appendStringInfo(buf, " %s",
quote_identifier(rte->eref->aliasname));
@@ -2981,7 +2986,7 @@ get_opclass_name(Oid opclass, Oid actual_datatype,
opcrec = (Form_pg_opclass) GETSTRUCT(ht_opc);
if (actual_datatype != opcrec->opcintype || !opcrec->opcdefault)
{
/* Okay, we need the opclass name. Do we need to qualify it? */
/* Okay, we need the opclass name. Do we need to qualify it? */
opcname = NameStr(opcrec->opcname);
if (OpclassIsVisible(opclass))
appendStringInfo(buf, " %s", quote_identifier(opcname));
@@ -3031,9 +3036,10 @@ const char *
quote_identifier(const char *ident)
{
/*
* Can avoid quoting if ident starts with a lowercase letter or underscore
* and contains only lowercase letters, digits, and underscores, *and* is
* not any SQL keyword. Otherwise, supply quotes.
* Can avoid quoting if ident starts with a lowercase letter or
* underscore and contains only lowercase letters, digits, and
* underscores, *and* is not any SQL keyword. Otherwise, supply
* quotes.
*/
int nquotes = 0;
bool safe;
@@ -3187,8 +3193,8 @@ generate_function_name(Oid funcid, int nargs, Oid *argtypes)
/*
* The idea here is to schema-qualify only if the parser would fail to
* resolve the correct function given the unqualified func name
* with the specified argtypes.
* resolve the correct function given the unqualified func name with
* the specified argtypes.
*/
p_result = func_get_detail(makeList1(makeString(proname)),
NIL, nargs, argtypes,
@@ -3239,8 +3245,8 @@ generate_operator_name(Oid operid, Oid arg1, Oid arg2)
/*
* The idea here is to schema-qualify only if the parser would fail to
* resolve the correct operator given the unqualified op name
* with the specified argtypes.
* resolve the correct operator given the unqualified op name with the
* specified argtypes.
*/
switch (operform->oprkind)
{

View File

@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.116 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.117 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -855,9 +855,12 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
return 0.0;
constval = ((Const *) other)->constvalue;
/* the right-hand const is type text or bytea for all supported operators */
/*
* the right-hand const is type text or bytea for all supported
* operators
*/
Assert(((Const *) other)->consttype == TEXTOID ||
((Const *) other)->consttype == BYTEAOID);
((Const *) other)->consttype == BYTEAOID);
/* divide pattern into fixed prefix and remainder */
patt = (Const *) other;
@@ -1860,11 +1863,12 @@ get_var_maximum(Query *root, Var *var, Oid sortop, Datum *max)
get_typlenbyval(var->vartype, &typLen, &typByVal);
/*
* If there is a histogram, grab the last or first value as appropriate.
* If there is a histogram, grab the last or first value as
* appropriate.
*
* If there is a histogram that is sorted with some other operator
* than the one we want, fail --- this suggests that there is data
* we can't use.
* If there is a histogram that is sorted with some other operator than
* the one we want, fail --- this suggests that there is data we can't
* use.
*/
if (get_attstatsslot(statsTuple, var->vartype, var->vartypmod,
STATISTIC_KIND_HISTOGRAM, sortop,
@@ -1873,14 +1877,14 @@ get_var_maximum(Query *root, Var *var, Oid sortop, Datum *max)
{
if (nvalues > 0)
{
tmax = datumCopy(values[nvalues-1], typByVal, typLen);
tmax = datumCopy(values[nvalues - 1], typByVal, typLen);
have_max = true;
}
free_attstatsslot(var->vartype, values, nvalues, NULL, 0);
}
else
{
Oid rsortop = get_commutator(sortop);
Oid rsortop = get_commutator(sortop);
if (OidIsValid(rsortop) &&
get_attstatsslot(statsTuple, var->vartype, var->vartypmod,
@@ -1907,8 +1911,8 @@ get_var_maximum(Query *root, Var *var, Oid sortop, Datum *max)
}
/*
* If we have most-common-values info, look for a large MCV. This
* is needed even if we also have a histogram, since the histogram
* If we have most-common-values info, look for a large MCV. This is
* needed even if we also have a histogram, since the histogram
* excludes the MCVs. However, usually the MCVs will not be the
* extreme values, so avoid unnecessary data copying.
*/
@@ -1917,7 +1921,7 @@ get_var_maximum(Query *root, Var *var, Oid sortop, Datum *max)
&values, &nvalues,
NULL, NULL))
{
bool large_mcv = false;
bool large_mcv = false;
FmgrInfo opproc;
fmgr_info(get_opcode(sortop), &opproc);
@@ -2724,7 +2728,7 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive,
patt = DatumGetCString(DirectFunctionCall1(byteaout, patt_const->constvalue));
pattlen = toast_raw_datum_size(patt_const->constvalue) - VARHDRSZ;
}
prefix = match = palloc(pattlen + 1);
match_pos = 0;
@@ -2760,8 +2764,8 @@ like_fixed_prefix(Const *patt_const, bool case_insensitive,
match[match_pos] = '\0';
rest = &patt[pos];
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
pfree(patt);
pfree(match);
@@ -2807,8 +2811,8 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
{
rest = patt;
*prefix_const = NULL;
*rest_const = string_to_const(rest, typeid);
*prefix_const = NULL;
*rest_const = string_to_const(rest, typeid);
return Pattern_Prefix_None;
}
@@ -2824,8 +2828,8 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
{
rest = patt;
*prefix_const = NULL;
*rest_const = string_to_const(rest, typeid);
*prefix_const = NULL;
*rest_const = string_to_const(rest, typeid);
return Pattern_Prefix_None;
}
@@ -2898,14 +2902,14 @@ regex_fixed_prefix(Const *patt_const, bool case_insensitive,
{
rest = &patt[pos + 1];
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
return Pattern_Prefix_Exact; /* pattern specifies exact match */
}
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
*prefix_const = string_to_const(prefix, typeid);
*rest_const = string_to_const(rest, typeid);
pfree(patt);
pfree(match);
@@ -3279,7 +3283,7 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
* we must be able to generate another string "fop" that is greater
* than all strings "foobar" starting with "foo". Unfortunately, a
* non-C locale may have arbitrary collation rules in which "fop" >
* "foo" is not sufficient to ensure "fop" > "foobar". Until we can
* "foo" is not sufficient to ensure "fop" > "foobar". Until we can
* come up with a more bulletproof way of generating the upper-bound
* string, the optimization is disabled in all non-C locales.
*
@@ -3356,8 +3360,8 @@ make_greater_string(const Const *str_const)
(*lastchar)++;
if (string_lessthan(str, workstr, datatype))
{
/* Success! */
Const *workstr_const = string_to_const(workstr, datatype);
/* Success! */
Const *workstr_const = string_to_const(workstr, datatype);
pfree(str);
pfree(workstr);
@@ -3372,7 +3376,7 @@ make_greater_string(const Const *str_const)
if (datatype != BYTEAOID && pg_database_encoding_max_length() > 1)
len = pg_mbcliplen((const unsigned char *) workstr, len, len - 1);
else
len -= - 1;
len -= -1;
if (datatype != BYTEAOID)
workstr[len] = '\0';

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.53 2002/09/02 01:05:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.54 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,19 +54,19 @@ SetDefine(char *querystr, Oid elemType)
char repl[Natts_pg_proc];
setoid = ProcedureCreate(procname, /* changed below, after oid known */
PG_CATALOG_NAMESPACE, /* XXX wrong */
PG_CATALOG_NAMESPACE, /* XXX wrong */
false, /* don't replace */
true, /* returnsSet */
elemType, /* returnType */
SQLlanguageId, /* language */
SQLlanguageId, /* language */
F_FMGR_SQL_VALIDATOR,
querystr, /* prosrc */
fileName, /* probin */
false, /* not aggregate */
false, /* security invoker */
false, /* isStrict (irrelevant, no args) */
PROVOLATILE_VOLATILE, /* assume unsafe */
0, /* parameterCount */
PROVOLATILE_VOLATILE, /* assume unsafe */
0, /* parameterCount */
NULL); /* parameterTypes */
/*

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.35 2002/08/29 00:17:05 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.36 2002/09/04 20:31:29 momjian Exp $
*
* NOTES
* input routine largely stolen from boxin().
@@ -154,14 +154,16 @@ setLastTid(const ItemPointer tid)
* correspond to the CTID of a base relation.
*/
static Datum
currtid_for_view(Relation viewrel, ItemPointer tid)
currtid_for_view(Relation viewrel, ItemPointer tid)
{
TupleDesc att = RelationGetDescr(viewrel);
RuleLock *rulelock;
RewriteRule *rewrite;
int i, natts = att->natts, tididx = -1;
RuleLock *rulelock;
RewriteRule *rewrite;
int i,
natts = att->natts,
tididx = -1;
for (i = 0; i < natts ; i++)
for (i = 0; i < natts; i++)
{
if (strcasecmp(NameStr(att->attrs[i]->attname), "ctid") == 0)
{
@@ -179,7 +181,7 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
rewrite = rulelock->rules[i];
if (rewrite->event == CMD_SELECT)
{
Query *query;
Query *query;
TargetEntry *tle;
if (length(rewrite->actions) != 1)
@@ -188,8 +190,9 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
tle = (TargetEntry *) nth(tididx, query->targetList);
if (tle && tle->expr && nodeTag(tle->expr) == T_Var)
{
Var *var = (Var *) tle->expr;
Var *var = (Var *) tle->expr;
RangeTblEntry *rte;
if (var->varno > 0 && var->varno < INNER && var->varattno == SelfItemPointerAttributeNumber)
{
rte = (RangeTblEntry *) nth(var->varno - 1, query->rtable);
@@ -244,7 +247,7 @@ currtid_byrelname(PG_FUNCTION_ARGS)
Relation rel;
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname,
"currtid_byrelname"));
"currtid_byrelname"));
rel = heap_openrv(relrv, AccessShareLock);
if (rel->rd_rel->relkind == RELKIND_VIEW)
return currtid_for_view(rel, tid);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.72 2002/09/03 22:55:54 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.73 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,6 +31,7 @@
#ifdef HAVE_INT64_TIMESTAMP
static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec);
#else
static double time2t(const int hour, const int min, const int sec, const fsec_t fsec);
#endif
@@ -155,7 +156,7 @@ static void
AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
static const int64 TimestampScales[MAX_TIMESTAMP_PRECISION+1] = {
static const int64 TimestampScales[MAX_TIMESTAMP_PRECISION + 1] = {
INT64CONST(1000000),
INT64CONST(100000),
INT64CONST(10000),
@@ -165,7 +166,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
INT64CONST(1)
};
static const int64 TimestampOffsets[MAX_TIMESTAMP_PRECISION+1] = {
static const int64 TimestampOffsets[MAX_TIMESTAMP_PRECISION + 1] = {
INT64CONST(-500000),
INT64CONST(-50000),
INT64CONST(-5000),
@@ -174,8 +175,9 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
INT64CONST(-5),
INT64CONST(0)
};
#else
static const double TimestampScales[MAX_TIMESTAMP_PRECISION+1] = {
static const double TimestampScales[MAX_TIMESTAMP_PRECISION + 1] = {
1,
10,
100,
@@ -185,7 +187,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
1000000
};
static const double TimestampOffsets[MAX_TIMESTAMP_PRECISION+1] = {
static const double TimestampOffsets[MAX_TIMESTAMP_PRECISION + 1] = {
0.5,
0.05,
0.005,
@@ -224,7 +226,10 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
}
else
{
/* Scale and truncate first, then add to help the rounding behavior */
/*
* Scale and truncate first, then add to help the rounding
* behavior
*/
*time = (rint((((double) *time) * TimestampScales[typmod]) + TimestampOffsets[typmod])
/ TimestampScales[typmod]);
}
@@ -450,7 +455,7 @@ static void
AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
static const int64 IntervalScales[MAX_INTERVAL_PRECISION+1] = {
static const int64 IntervalScales[MAX_INTERVAL_PRECISION + 1] = {
INT64CONST(1000000),
INT64CONST(100000),
INT64CONST(10000),
@@ -460,7 +465,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
INT64CONST(1)
};
static const int64 IntervalOffsets[MAX_INTERVAL_PRECISION+1] = {
static const int64 IntervalOffsets[MAX_INTERVAL_PRECISION + 1] = {
INT64CONST(-500000),
INT64CONST(-50000),
INT64CONST(-5000),
@@ -469,8 +474,9 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
INT64CONST(-5),
INT64CONST(0)
};
#else
static const double IntervalScales[MAX_INTERVAL_PRECISION+1] = {
static const double IntervalScales[MAX_INTERVAL_PRECISION + 1] = {
1,
10,
100,
@@ -480,7 +486,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
1000000
};
static const double IntervalOffsets[MAX_INTERVAL_PRECISION+1] = {
static const double IntervalOffsets[MAX_INTERVAL_PRECISION + 1] = {
0.5,
0.05,
0.005,
@@ -491,7 +497,8 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
};
#endif
/* Unspecified range and precision? Then not necessary to adjust.
/*
* Unspecified range and precision? Then not necessary to adjust.
* Setting typmod to -1 is the convention for all types.
*/
if (typmod != -1)
@@ -515,9 +522,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
}
/* YEAR TO MONTH */
else if (range == (INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH)))
{
interval->time = 0;
}
else if (range == INTERVAL_MASK(DAY))
{
interval->month = 0;
@@ -532,6 +537,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 day;
#else
double day;
#endif
@@ -551,6 +557,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 hour;
#else
double hour;
#endif
@@ -570,6 +577,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 minute;
#else
double minute;
#endif
@@ -613,15 +621,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
INTERVAL_MASK(HOUR) |
INTERVAL_MASK(MINUTE) |
INTERVAL_MASK(SECOND)))
{
interval->month = 0;
}
/* HOUR TO MINUTE */
else if (range == (INTERVAL_MASK(HOUR) |
INTERVAL_MASK(MINUTE)))
{
#ifdef HAVE_INT64_TIMESTAMP
int64 day;
#else
double day;
#endif
@@ -644,6 +651,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 day;
#else
double day;
#endif
@@ -662,6 +670,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 hour;
#else
double hour;
#endif
@@ -706,7 +715,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
else
{
interval->time = (rint((((double) interval->time) + IntervalOffsets[precision])
* IntervalScales[precision]) / IntervalScales[precision]);
* IntervalScales[precision]) / IntervalScales[precision]);
}
#endif
}
@@ -756,6 +765,7 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
#else
double time;
#endif
@@ -794,18 +804,19 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27
*/
int
timestamp2tm(Timestamp dt, int *tzp, struct tm *tm, fsec_t *fsec, char **tzn)
timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
{
#ifdef HAVE_INT64_TIMESTAMP
int date,
date0;
int64 time;
int date,
date0;
int64 time;
#else
double date,
date0;
double time;
double date,
date0;
double time;
#endif
time_t utime;
time_t utime;
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
struct tm *tx;
@@ -880,7 +891,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct tm *tm, fsec_t *fsec, char **tzn)
{
#ifdef HAVE_INT64_TIMESTAMP
utime = ((dt / INT64CONST(1000000))
+ ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400)));
+ ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400)));
#else
utime = (dt + ((date0 - date2j(1970, 1, 1)) * 86400));
#endif
@@ -963,8 +974,9 @@ int
tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
{
#ifdef HAVE_INT64_TIMESTAMP
int date;
int64 time;
int date;
int64 time;
#else
double date,
time;
@@ -996,6 +1008,7 @@ interval2tm(Interval span, struct tm * tm, fsec_t *fsec)
{
#ifdef HAVE_INT64_TIMESTAMP
int64 time;
#else
double time;
#endif
@@ -1040,9 +1053,9 @@ tm2interval(struct tm * tm, fsec_t fsec, Interval *span)
span->month = ((tm->tm_year * 12) + tm->tm_mon);
#ifdef HAVE_INT64_TIMESTAMP
span->time = ((((((((tm->tm_mday * INT64CONST(24))
+ tm->tm_hour) * INT64CONST(60))
+ tm->tm_min) * INT64CONST(60))
+ tm->tm_sec) * INT64CONST(1000000)) + fsec);
+ tm->tm_hour) * INT64CONST(60))
+ tm->tm_min) * INT64CONST(60))
+ tm->tm_sec) * INT64CONST(1000000)) + fsec);
#else
span->time = ((((((tm->tm_mday * 24.0)
+ tm->tm_hour) * 60.0)
@@ -1060,6 +1073,7 @@ time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
return ((((((hour * 60) + min) * 60) + sec) * INT64CONST(1000000)) + fsec);
} /* time2t() */
#else
static double
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
@@ -1226,6 +1240,7 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
#ifdef HAVE_INT64_TIMESTAMP
int64 span1,
span2;
#else
double span1,
span2;
@@ -1532,9 +1547,7 @@ timestamp_pl_span(PG_FUNCTION_ARGS)
Timestamp result;
if (TIMESTAMP_NOT_FINITE(timestamp))
{
result = timestamp;
}
else
{
if (span->month != 0)
@@ -1702,9 +1715,11 @@ interval_smaller(PG_FUNCTION_ARGS)
Interval *interval1 = PG_GETARG_INTERVAL_P(0);
Interval *interval2 = PG_GETARG_INTERVAL_P(1);
Interval *result;
#ifdef HAVE_INT64_TIMESTAMP
int64 span1,
span2;
#else
double span1,
span2;
@@ -1746,9 +1761,11 @@ interval_larger(PG_FUNCTION_ARGS)
Interval *interval1 = PG_GETARG_INTERVAL_P(0);
Interval *interval2 = PG_GETARG_INTERVAL_P(1);
Interval *result;
#ifdef HAVE_INT64_TIMESTAMP
int64 span1,
span2;
#else
double span1,
span2;
@@ -1828,8 +1845,10 @@ interval_mul(PG_FUNCTION_ARGS)
Interval *span1 = PG_GETARG_INTERVAL_P(0);
float8 factor = PG_GETARG_FLOAT8(1);
Interval *result;
#ifdef HAVE_INT64_TIMESTAMP
int64 months;
#else
double months;
#endif
@@ -1868,6 +1887,7 @@ interval_div(PG_FUNCTION_ARGS)
Interval *span = PG_GETARG_INTERVAL_P(0);
float8 factor = PG_GETARG_FLOAT8(1);
Interval *result;
#ifndef HAVE_INT64_TIMESTAMP
double months;
#endif
@@ -1882,7 +1902,7 @@ interval_div(PG_FUNCTION_ARGS)
result->time = (span->time / factor);
/* evaluate fractional months as 30 days */
result->time += (((span->month - (result->month * factor))
* INT64CONST(30) * INT64CONST(86400000000)) / factor);
* INT64CONST(30) * INT64CONST(86400000000)) / factor);
#else
months = (span->month / factor);
result->month = rint(months);
@@ -1928,8 +1948,8 @@ interval_accum(PG_FUNCTION_ARGS)
* objects on machines where double requires 8-byte alignment. That
* should be fixed, but in the meantime...
*
* Note: must use DatumGetPointer here, not DatumGetIntervalP,
* else some compilers optimize into double-aligned load/store anyway.
* Note: must use DatumGetPointer here, not DatumGetIntervalP, else some
* compilers optimize into double-aligned load/store anyway.
*/
memcpy((void *) &sumX, DatumGetPointer(transdatums[0]), sizeof(Interval));
memcpy((void *) &N, DatumGetPointer(transdatums[1]), sizeof(Interval));
@@ -1970,8 +1990,8 @@ interval_avg(PG_FUNCTION_ARGS)
* objects on machines where double requires 8-byte alignment. That
* should be fixed, but in the meantime...
*
* Note: must use DatumGetPointer here, not DatumGetIntervalP,
* else some compilers optimize into double-aligned load/store anyway.
* Note: must use DatumGetPointer here, not DatumGetIntervalP, else some
* compilers optimize into double-aligned load/store anyway.
*/
memcpy((void *) &sumX, DatumGetPointer(transdatums[0]), sizeof(Interval));
memcpy((void *) &N, DatumGetPointer(transdatums[1]), sizeof(Interval));
@@ -3131,29 +3151,29 @@ interval_part(PG_FUNCTION_ARGS)
{
switch (val)
{
case DTK_MICROSEC:
case DTK_MICROSEC:
#ifdef HAVE_INT64_TIMESTAMP
result = ((tm->tm_sec * 1000000e0) + fsec);
result = ((tm->tm_sec * 1000000e0) + fsec);
#else
result = (tm->tm_sec + fsec) * 1000000;
result = (tm->tm_sec + fsec) * 1000000;
#endif
break;
break;
case DTK_MILLISEC:
case DTK_MILLISEC:
#ifdef HAVE_INT64_TIMESTAMP
result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
result = ((tm->tm_sec * 1000e0) + (fsec / 1000e0));
#else
result = (tm->tm_sec + fsec) * 1000;
result = (tm->tm_sec + fsec) * 1000;
#endif
break;
break;
case DTK_SECOND:
case DTK_SECOND:
#ifdef HAVE_INT64_TIMESTAMP
result = (tm->tm_sec + (fsec / 1000000e0));
result = (tm->tm_sec + (fsec / 1000000e0));
#else
result = (tm->tm_sec + fsec);
result = (tm->tm_sec + fsec);
#endif
break;
break;
case DTK_MINUTE:
result = tm->tm_min;
@@ -3234,7 +3254,7 @@ interval_part(PG_FUNCTION_ARGS)
/* timestamp_zone()
* Encode timestamp type with specified time zone.
* Returns timestamp with time zone, with the input
* rotated from local time to the specified zone.
* rotated from local time to the specified zone.
*/
Datum
timestamp_zone(PG_FUNCTION_ARGS)

View File

@@ -9,7 +9,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.24 2002/08/26 17:53:59 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.25 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1138,8 +1138,8 @@ bitfromint8(PG_FUNCTION_ARGS)
VARBITLEN(result) = sizeof(a) * BITS_PER_BYTE;
/*
* masks and shifts here are just too painful and we know that an int64
* has got 8 bytes
* masks and shifts here are just too painful and we know that an
* int64 has got 8 bytes
*/
r = VARBITS(result);
r[0] = (bits8) ((a >> (7 * BITS_PER_BYTE)) & BITMASK);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.93 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.94 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -182,6 +182,7 @@ bpchar(PG_FUNCTION_ARGS)
int charlen; /* number of charcters in the input string
* + VARHDRSZ */
len = VARSIZE(source);
charlen = pg_mbstrlen_with_len(VARDATA(source), len - VARHDRSZ) + VARHDRSZ;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.91 2002/09/03 21:45:42 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92 2002/09/04 20:31:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -30,11 +30,11 @@ typedef struct varlena unknown;
#define PG_GETARG_UNKNOWN_P(n) DatumGetUnknownP(PG_GETARG_DATUM(n))
#define PG_RETURN_UNKNOWN_P(x) PG_RETURN_POINTER(x)
#define PG_TEXTARG_GET_STR(arg_) \
DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(arg_)))
DatumGetCString(DirectFunctionCall1(textout, PG_GETARG_DATUM(arg_)))
#define PG_TEXT_GET_STR(textp_) \
DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
#define PG_STR_GET_TEXT(str_) \
DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(str_)))
DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(str_)))
#define TEXTLEN(textp) \
text_length(PointerGetDatum(textp))
#define TEXTPOS(buf_text, from_sub_text) \
@@ -54,9 +54,9 @@ static int text_cmp(text *arg1, text *arg2);
static int32 text_length(Datum str);
static int32 text_position(Datum str, Datum search_str, int matchnum);
static text *text_substring(Datum str,
int32 start,
int32 length,
bool length_not_specified);
int32 start,
int32 length,
bool length_not_specified);
/*****************************************************************************
@@ -266,7 +266,7 @@ Datum
unknownin(PG_FUNCTION_ARGS)
{
char *inputStr = PG_GETARG_CSTRING(0);
unknown *result;
unknown *result;
int len;
len = strlen(inputStr) + VARHDRSZ;
@@ -286,7 +286,7 @@ unknownin(PG_FUNCTION_ARGS)
Datum
unknownout(PG_FUNCTION_ARGS)
{
unknown *t = PG_GETARG_UNKNOWN_P(0);
unknown *t = PG_GETARG_UNKNOWN_P(0);
int len;
char *result;
@@ -330,12 +330,12 @@ text_length(Datum str)
text *t = DatumGetTextP(str);
PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA(t),
VARSIZE(t) - VARHDRSZ));
VARSIZE(t) - VARHDRSZ));
}
/* should never get here */
elog(ERROR, "Invalid backend encoding; encoding max length "
"is less than one.");
"is less than one.");
/* not reached: suppress compiler warning */
return 0;
@@ -425,7 +425,7 @@ textcat(PG_FUNCTION_ARGS)
* behaviors conflicting with SQL92 to meet SQL92 (if E = S + L < S throw
* error; if E < 1, return '', not entire string). Fixed MB related bug when
* S > LC and < LC + 4 sometimes garbage characters are returned.
* - Joe Conway 2002-08-10
* - Joe Conway 2002-08-10
*/
Datum
text_substr(PG_FUNCTION_ARGS)
@@ -455,25 +455,26 @@ text_substr_no_len(PG_FUNCTION_ARGS)
* This is broken out so it can be called directly by other string processing
* functions.
*/
static text*
static text *
text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
{
int32 eml = pg_database_encoding_max_length();
int32 S = start; /* start position */
int32 S1; /* adjusted start position */
int32 L1; /* adjusted substring length */
int32 S = start; /* start position */
int32 S1; /* adjusted start position */
int32 L1; /* adjusted substring length */
/* life is easy if the encoding max length is 1 */
if (eml == 1)
{
S1 = Max(S, 1);
if (length_not_specified) /* special case - get length to end of string */
if (length_not_specified) /* special case - get length to
* end of string */
L1 = -1;
else
{
/* end position */
int E = S + length;
int E = S + length;
/*
* A negative value for L is the only way for the end position
@@ -482,9 +483,10 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
if (E < S)
elog(ERROR, "negative substring length not allowed");
/*
* A zero or negative value for the end position can happen if the start
* was negative or one. SQL99 says to return a zero-length string.
/*
* A zero or negative value for the end position can happen if
* the start was negative or one. SQL99 says to return a
* zero-length string.
*/
if (E < 1)
return PG_STR_GET_TEXT("");
@@ -492,11 +494,10 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
L1 = E - S1;
}
/*
* If the start position is past the end of the string,
* SQL99 says to return a zero-length string --
* PG_GETARG_TEXT_P_SLICE() will do that for us.
* Convert to zero-based starting position
/*
* If the start position is past the end of the string, SQL99 says
* to return a zero-length string -- PG_GETARG_TEXT_P_SLICE() will
* do that for us. Convert to zero-based starting position
*/
return DatumGetTextPSlice(str, S1 - 1, L1);
}
@@ -504,13 +505,13 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
{
/*
* When encoding max length is > 1, we can't get LC without
* detoasting, so we'll grab a conservatively large slice
* now and go back later to do the right thing
* detoasting, so we'll grab a conservatively large slice now and
* go back later to do the right thing
*/
int32 slice_start;
int32 slice_size;
int32 slice_strlen;
text *slice;
text *slice;
int32 E1;
int32 i;
char *p;
@@ -518,23 +519,24 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
text *ret;
/*
* if S is past the end of the string, the tuple toaster
* will return a zero-length string to us
* if S is past the end of the string, the tuple toaster will
* return a zero-length string to us
*/
S1 = Max(S, 1);
/*
* We need to start at position zero because there is no
* way to know in advance which byte offset corresponds to
* the supplied start position.
* We need to start at position zero because there is no way to
* know in advance which byte offset corresponds to the supplied
* start position.
*/
slice_start = 0;
if (length_not_specified) /* special case - get length to end of string */
if (length_not_specified) /* special case - get length to
* end of string */
slice_size = L1 = -1;
else
{
int E = S + length;
int E = S + length;
/*
* A negative value for L is the only way for the end position
@@ -543,22 +545,24 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
if (E < S)
elog(ERROR, "negative substring length not allowed");
/*
* A zero or negative value for the end position can happen if the start
* was negative or one. SQL99 says to return a zero-length string.
/*
* A zero or negative value for the end position can happen if
* the start was negative or one. SQL99 says to return a
* zero-length string.
*/
if (E < 1)
return PG_STR_GET_TEXT("");
/*
* if E is past the end of the string, the tuple toaster
* will truncate the length for us
* if E is past the end of the string, the tuple toaster will
* truncate the length for us
*/
L1 = E - S1;
/*
* Total slice size in bytes can't be any longer than the start
* position plus substring length times the encoding max length.
* Total slice size in bytes can't be any longer than the
* start position plus substring length times the encoding max
* length.
*/
slice_size = (S1 + L1) * eml;
}
@@ -569,9 +573,10 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
return PG_STR_GET_TEXT("");
/* Now we can get the actual length of the slice in MB characters */
slice_strlen = pg_mbstrlen_with_len (VARDATA(slice), VARSIZE(slice) - VARHDRSZ);
slice_strlen = pg_mbstrlen_with_len(VARDATA(slice), VARSIZE(slice) - VARHDRSZ);
/* Check that the start position wasn't > slice_strlen. If so,
/*
* Check that the start position wasn't > slice_strlen. If so,
* SQL99 says to return a zero-length string.
*/
if (S1 > slice_strlen)
@@ -579,16 +584,17 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
/*
* Adjust L1 and E1 now that we know the slice string length.
* Again remember that S1 is one based, and slice_start is zero based.
* Again remember that S1 is one based, and slice_start is zero
* based.
*/
if (L1 > -1)
E1 = Min(S1 + L1 , slice_start + 1 + slice_strlen);
E1 = Min(S1 + L1, slice_start + 1 + slice_strlen);
else
E1 = slice_start + 1 + slice_strlen;
/*
* Find the start position in the slice;
* remember S1 is not zero based
* Find the start position in the slice; remember S1 is not zero
* based
*/
p = VARDATA(slice);
for (i = 0; i < S1 - 1; i++)
@@ -598,8 +604,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
s = p;
/*
* Count the actual bytes used by the substring of
* the requested length.
* Count the actual bytes used by the substring of the requested
* length.
*/
for (i = S1; i < E1; i++)
p += pg_mblen(p);
@@ -612,7 +618,7 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
}
else
elog(ERROR, "Invalid backend encoding; encoding max length "
"is less than one.");
"is less than one.");
/* not reached: suppress compiler warning */
return PG_STR_GET_TEXT("");
@@ -650,8 +656,8 @@ text_position(Datum str, Datum search_str, int matchnum)
len1,
len2;
if(matchnum == 0)
return 0; /* result for 0th match */
if (matchnum == 0)
return 0; /* result for 0th match */
if (VARSIZE(t2) <= VARHDRSZ)
PG_RETURN_INT32(1); /* result for empty pattern */
@@ -662,10 +668,10 @@ text_position(Datum str, Datum search_str, int matchnum)
/* no use in searching str past point where search_str will fit */
px = (len1 - len2);
if (eml == 1) /* simple case - single byte encoding */
if (eml == 1) /* simple case - single byte encoding */
{
char *p1,
*p2;
char *p1,
*p2;
p1 = VARDATA(t1);
p2 = VARDATA(t2);
@@ -683,7 +689,7 @@ text_position(Datum str, Datum search_str, int matchnum)
p1++;
}
}
else if (eml > 1) /* not as simple - multibyte encoding */
else if (eml > 1) /* not as simple - multibyte encoding */
{
pg_wchar *p1,
*p2,
@@ -715,7 +721,7 @@ text_position(Datum str, Datum search_str, int matchnum)
}
else
elog(ERROR, "Invalid backend encoding; encoding max length "
"is less than one.");
"is less than one.");
PG_RETURN_INT32(pos);
}
@@ -734,10 +740,10 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2)
*a2p;
/*
* Unfortunately, there is no strncoll(), so in the non-C locale
* case we have to do some memory copying. This turns out to be
* significantly slower, so we optimize the case where LC_COLLATE
* is C.
* Unfortunately, there is no strncoll(), so in the non-C locale case
* we have to do some memory copying. This turns out to be
* significantly slower, so we optimize the case where LC_COLLATE is
* C.
*/
if (!lc_collate_is_c())
{
@@ -990,7 +996,7 @@ byteacat(PG_FUNCTION_ARGS)
}
#define PG_STR_GET_BYTEA(str_) \
DatumGetByteaP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
DatumGetByteaP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
/*
* bytea_substr()
* Return a substring starting at the specified position.
@@ -1009,36 +1015,37 @@ byteacat(PG_FUNCTION_ARGS)
Datum
bytea_substr(PG_FUNCTION_ARGS)
{
int S = PG_GETARG_INT32(1); /* start position */
int S1; /* adjusted start position */
int L1; /* adjusted substring length */
int S = PG_GETARG_INT32(1); /* start position */
int S1; /* adjusted start position */
int L1; /* adjusted substring length */
S1 = Max(S, 1);
if (fcinfo->nargs == 2)
{
/*
* Not passed a length - PG_GETARG_BYTEA_P_SLICE()
* grabs everything to the end of the string if we pass it
* a negative value for length.
* Not passed a length - PG_GETARG_BYTEA_P_SLICE() grabs
* everything to the end of the string if we pass it a negative
* value for length.
*/
L1 = -1;
}
else
{
/* end position */
int E = S + PG_GETARG_INT32(2);
int E = S + PG_GETARG_INT32(2);
/*
* A negative value for L is the only way for the end position
* to be before the start. SQL99 says to throw an error.
* A negative value for L is the only way for the end position to
* be before the start. SQL99 says to throw an error.
*/
if (E < S)
elog(ERROR, "negative substring length not allowed");
/*
* A zero or negative value for the end position can happen if the start
* was negative or one. SQL99 says to return a zero-length string.
/*
* A zero or negative value for the end position can happen if the
* start was negative or one. SQL99 says to return a zero-length
* string.
*/
if (E < 1)
PG_RETURN_BYTEA_P(PG_STR_GET_BYTEA(""));
@@ -1046,13 +1053,12 @@ bytea_substr(PG_FUNCTION_ARGS)
L1 = E - S1;
}
/*
* If the start position is past the end of the string,
* SQL99 says to return a zero-length string --
* PG_GETARG_TEXT_P_SLICE() will do that for us.
* Convert to zero-based starting position
/*
* If the start position is past the end of the string, SQL99 says to
* return a zero-length string -- PG_GETARG_TEXT_P_SLICE() will do
* that for us. Convert to zero-based starting position
*/
PG_RETURN_BYTEA_P(PG_GETARG_BYTEA_P_SLICE (0, S1 - 1, L1));
PG_RETURN_BYTEA_P(PG_GETARG_BYTEA_P_SLICE(0, S1 - 1, L1));
}
/*
@@ -1343,7 +1349,7 @@ textToQualifiedNameList(text *textval, const char *caller)
/* Convert to C string (handles possible detoasting). */
/* Note we rely on being able to modify rawname below. */
rawname = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(textval)));
PointerGetDatum(textval)));
if (!SplitIdentifierString(rawname, '.', &namelist))
elog(ERROR, "%s: invalid name syntax", caller);
@@ -1353,7 +1359,7 @@ textToQualifiedNameList(text *textval, const char *caller)
foreach(l, namelist)
{
char *curname = (char *) lfirst(l);
char *curname = (char *) lfirst(l);
result = lappend(result, makeString(pstrdup(curname)));
}
@@ -1368,15 +1374,15 @@ textToQualifiedNameList(text *textval, const char *caller)
* SplitIdentifierString --- parse a string containing identifiers
*
* This is the guts of textToQualifiedNameList, and is exported for use in
* other situations such as parsing GUC variables. In the GUC case, it's
* other situations such as parsing GUC variables. In the GUC case, it's
* important to avoid memory leaks, so the API is designed to minimize the
* amount of stuff that needs to be allocated and freed.
*
* Inputs:
* rawstring: the input string; must be overwritable! On return, it's
* rawstring: the input string; must be overwritable! On return, it's
* been modified to contain the separated identifiers.
* separator: the separator punctuation expected between identifiers
* (typically '.' or ','). Whitespace may also appear around
* (typically '.' or ','). Whitespace may also appear around
* identifiers.
* Outputs:
* namelist: filled with a palloc'd list of pointers to identifiers within
@@ -1417,11 +1423,11 @@ SplitIdentifierString(char *rawstring, char separator,
{
endp = strchr(nextp + 1, '\"');
if (endp == NULL)
return false; /* mismatched quotes */
return false; /* mismatched quotes */
if (endp[1] != '\"')
break; /* found end of quoted name */
/* Collapse adjacent quotes into one quote, and look again */
memmove(endp, endp+1, strlen(endp));
memmove(endp, endp + 1, strlen(endp));
nextp = endp;
}
/* endp now points at the terminating quote */
@@ -1435,8 +1441,8 @@ SplitIdentifierString(char *rawstring, char separator,
!isspace((unsigned char) *nextp))
{
/*
* It's important that this match the identifier downcasing
* code used by backend/parser/scan.l.
* It's important that this match the identifier
* downcasing code used by backend/parser/scan.l.
*/
if (isupper((unsigned char) *nextp))
*nextp = tolower((unsigned char) *nextp);
@@ -1647,24 +1653,24 @@ byteacmp(PG_FUNCTION_ARGS)
* replace_text
* replace all occurences of 'old_sub_str' in 'orig_str'
* with 'new_sub_str' to form 'new_str'
*
*
* returns 'orig_str' if 'old_sub_str' == '' or 'orig_str' == ''
* otherwise returns 'new_str'
* otherwise returns 'new_str'
*/
Datum
replace_text(PG_FUNCTION_ARGS)
{
text *left_text;
text *right_text;
text *buf_text;
text *ret_text;
text *left_text;
text *right_text;
text *buf_text;
text *ret_text;
int curr_posn;
text *src_text = PG_GETARG_TEXT_P(0);
text *src_text = PG_GETARG_TEXT_P(0);
int src_text_len = TEXTLEN(src_text);
text *from_sub_text = PG_GETARG_TEXT_P(1);
text *from_sub_text = PG_GETARG_TEXT_P(1);
int from_sub_text_len = TEXTLEN(from_sub_text);
text *to_sub_text = PG_GETARG_TEXT_P(2);
char *to_sub_str = PG_TEXT_GET_STR(to_sub_text);
text *to_sub_text = PG_GETARG_TEXT_P(2);
char *to_sub_str = PG_TEXT_GET_STR(to_sub_text);
StringInfo str = makeStringInfo();
if (src_text_len == 0 || from_sub_text_len == 0)
@@ -1713,7 +1719,7 @@ split_text(PG_FUNCTION_ARGS)
int fldnum = PG_GETARG_INT32(2);
int start_posn = 0;
int end_posn = 0;
text *result_text;
text *result_text;
/* return empty string for empty input string */
if (inputstring_len < 1)
@@ -1722,9 +1728,11 @@ split_text(PG_FUNCTION_ARGS)
/* empty field separator */
if (fldsep_len < 1)
{
if (fldnum == 1) /* first field - just return the input string */
if (fldnum == 1) /* first field - just return the input
* string */
PG_RETURN_TEXT_P(inputstring);
else /* otherwise return an empty string */
else
/* otherwise return an empty string */
PG_RETURN_TEXT_P(PG_STR_GET_TEXT(""));
}
@@ -1733,17 +1741,19 @@ split_text(PG_FUNCTION_ARGS)
elog(ERROR, "field position must be > 0");
start_posn = text_position(PointerGetDatum(inputstring),
PointerGetDatum(fldsep),
fldnum - 1);
PointerGetDatum(fldsep),
fldnum - 1);
end_posn = text_position(PointerGetDatum(inputstring),
PointerGetDatum(fldsep),
fldnum);
PointerGetDatum(fldsep),
fldnum);
if ((start_posn == 0) && (end_posn == 0)) /* fldsep not found */
{
if (fldnum == 1) /* first field - just return the input string */
if (fldnum == 1) /* first field - just return the input
* string */
PG_RETURN_TEXT_P(inputstring);
else /* otherwise return an empty string */
else
/* otherwise return an empty string */
PG_RETURN_TEXT_P(PG_STR_GET_TEXT(""));
}
else if ((start_posn != 0) && (end_posn == 0))
@@ -1774,11 +1784,11 @@ split_text(PG_FUNCTION_ARGS)
Datum
to_hex32(PG_FUNCTION_ARGS)
{
static char digits[] = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text;
int32 value = PG_GETARG_INT32(0);
static char digits[] = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text;
int32 value = PG_GETARG_INT32(0);
ptr = buf + sizeof(buf) - 1;
*ptr = '\0';
@@ -1800,11 +1810,11 @@ to_hex32(PG_FUNCTION_ARGS)
Datum
to_hex64(PG_FUNCTION_ARGS)
{
static char digits[] = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text;
int64 value = PG_GETARG_INT64(0);
static char digits[] = "0123456789abcdef";
char buf[32]; /* bigger than needed, but reasonable */
char *ptr;
text *result_text;
int64 value = PG_GETARG_INT64(0);
ptr = buf + sizeof(buf) - 1;
*ptr = '\0';
@@ -1818,4 +1828,3 @@ to_hex64(PG_FUNCTION_ARGS)
result_text = PG_STR_GET_TEXT(ptr);
PG_RETURN_TEXT_P(result_text);
}