mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Standard pgindent run for 8.1.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/* -----------------------------------------------------------------------
|
||||
* formatting.c
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.99 2005/08/18 13:43:08 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.100 2005/10/15 02:49:28 momjian Exp $
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1999-2005, PostgreSQL Global Development Group
|
||||
@ -135,9 +135,9 @@ typedef struct
|
||||
{
|
||||
const char *name; /* keyword */
|
||||
int len; /* keyword length */
|
||||
int (*action) (int arg, char *inout, /* action for keyword */
|
||||
int suf, bool is_to_char, bool is_interval,
|
||||
FormatNode *node, void *data);
|
||||
int (*action) (int arg, char *inout, /* action for keyword */
|
||||
int suf, bool is_to_char, bool is_interval,
|
||||
FormatNode *node, void *data);
|
||||
int id; /* keyword id */
|
||||
bool isitdigit; /* is expected output/input digit */
|
||||
} KeyWord;
|
||||
@ -252,7 +252,7 @@ static char *numth[] = {"st", "nd", "rd", "th", NULL};
|
||||
* Flags for DCH version
|
||||
* ----------
|
||||
*/
|
||||
static bool DCH_global_fx = false;
|
||||
static bool DCH_global_fx = false;
|
||||
|
||||
|
||||
/* ----------
|
||||
@ -379,7 +379,7 @@ typedef struct
|
||||
q,
|
||||
j,
|
||||
us,
|
||||
yysz; /* is it YY or YYYY ? */
|
||||
yysz; /* is it YY or YYYY ? */
|
||||
} TmFromChar;
|
||||
|
||||
#define ZERO_tmfc(_X) memset(_X, 0, sizeof(TmFromChar))
|
||||
@ -442,17 +442,17 @@ do { \
|
||||
errmsg("invalid format specification for an interval value"), \
|
||||
errhint("Intervals are not tied to specific calendar dates."))); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* KeyWords definition & action
|
||||
*****************************************************************************/
|
||||
|
||||
static int dch_global(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
static int dch_time(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
static int dch_date(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
static int dch_global(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
static int dch_time(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
static int dch_date(int arg, char *inout, int suf, bool is_to_char,
|
||||
bool is_interval, FormatNode *node, void *data);
|
||||
|
||||
/* ----------
|
||||
* Suffixes:
|
||||
@ -803,7 +803,7 @@ static const KeyWord NUM_keywords[] = {
|
||||
* KeyWords index for DATE-TIME version
|
||||
* ----------
|
||||
*/
|
||||
static const int DCH_index[KeyWord_INDEX_SIZE] = {
|
||||
static const int DCH_index[KeyWord_INDEX_SIZE] = {
|
||||
/*
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
*/
|
||||
@ -827,7 +827,7 @@ static const int DCH_index[KeyWord_INDEX_SIZE] = {
|
||||
* KeyWords index for NUMBER version
|
||||
* ----------
|
||||
*/
|
||||
static const int NUM_index[KeyWord_INDEX_SIZE] = {
|
||||
static const int NUM_index[KeyWord_INDEX_SIZE] = {
|
||||
/*
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
*/
|
||||
@ -871,8 +871,7 @@ typedef struct NUMProc
|
||||
*number_p, /* pointer to current number position */
|
||||
*inout, /* in / out buffer */
|
||||
*inout_p, /* pointer to current inout position */
|
||||
*last_relevant, /* last relevant number after decimal
|
||||
* point */
|
||||
*last_relevant, /* last relevant number after decimal point */
|
||||
|
||||
*L_negative_sign, /* Locale */
|
||||
*L_positive_sign,
|
||||
@ -887,13 +886,13 @@ typedef struct NUMProc
|
||||
* ----------
|
||||
*/
|
||||
static const KeyWord *index_seq_search(char *str, const KeyWord *kw,
|
||||
const int *index);
|
||||
const int *index);
|
||||
static KeySuffix *suff_search(char *str, KeySuffix *suf, int type);
|
||||
static void NUMDesc_prepare(NUMDesc *num, FormatNode *n);
|
||||
static void parse_format(FormatNode *node, char *str, const KeyWord *kw,
|
||||
KeySuffix *suf, const int *index, int ver, NUMDesc *Num);
|
||||
static char *DCH_processor(FormatNode *node, char *inout, bool is_to_char,
|
||||
bool is_interval, void *data);
|
||||
bool is_interval, void *data);
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
static void dump_index(const KeyWord *k, const int *index);
|
||||
@ -909,7 +908,7 @@ static char *str_tolower(char *buff);
|
||||
/* static int is_acdc(char *str, int *len); */
|
||||
static int seq_search(char *name, char **array, int type, int max, int *len);
|
||||
static void do_to_timestamp(text *date_txt, text *fmt,
|
||||
struct pg_tm *tm, fsec_t *fsec);
|
||||
struct pg_tm * tm, fsec_t *fsec);
|
||||
static char *fill_str(char *str, int c, int max);
|
||||
static FormatNode *NUM_cache(int len, NUMDesc *Num, char *pars_str, bool *shouldFree);
|
||||
static char *int_to_roman(int number);
|
||||
@ -1047,7 +1046,7 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
|
||||
NUM_cache_remove(last_NUMCacheEntry);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("cannot use \"V\" and decimal point together")));
|
||||
errmsg("cannot use \"V\" and decimal point together")));
|
||||
}
|
||||
num->flag |= NUM_F_DECIMAL;
|
||||
break;
|
||||
@ -1152,7 +1151,7 @@ NUMDesc_prepare(NUMDesc *num, FormatNode *n)
|
||||
NUM_cache_remove(last_NUMCacheEntry);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("cannot use \"V\" and decimal point together")));
|
||||
errmsg("cannot use \"V\" and decimal point together")));
|
||||
}
|
||||
num->flag |= NUM_F_MULTI;
|
||||
break;
|
||||
@ -1324,11 +1323,11 @@ DCH_processor(FormatNode *node, char *inout, bool is_to_char,
|
||||
if (!is_to_char && *s == '\0')
|
||||
|
||||
/*
|
||||
* The input string is shorter than format picture, so it's
|
||||
* good time to break this loop...
|
||||
* The input string is shorter than format picture, so it's good
|
||||
* time to break this loop...
|
||||
*
|
||||
* Note: this isn't relevant for TO_CHAR mode, beacuse it use
|
||||
* 'inout' allocated by format picture length.
|
||||
* Note: this isn't relevant for TO_CHAR mode, beacuse it use 'inout'
|
||||
* allocated by format picture length.
|
||||
*/
|
||||
break;
|
||||
|
||||
@ -1393,7 +1392,7 @@ dump_node(FormatNode *node, int max)
|
||||
{
|
||||
if (n->type == NODE_TYPE_ACTION)
|
||||
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_ACTION '%s'\t(%s,%s)",
|
||||
a, n->key->name, DUMP_THth(n->suffix), DUMP_FM(n->suffix));
|
||||
a, n->key->name, DUMP_THth(n->suffix), DUMP_FM(n->suffix));
|
||||
else if (n->type == NODE_TYPE_CHAR)
|
||||
elog(DEBUG_elog_output, "%d:\t NODE_TYPE_CHAR '%c'", a, n->character);
|
||||
else if (n->type == NODE_TYPE_END)
|
||||
@ -1578,8 +1577,8 @@ seq_search(char *name, char **array, int type, int max, int *len)
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
|
||||
/*
|
||||
* elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)", *n, *p,
|
||||
* *a, name);
|
||||
* elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)", *n, *p, *a,
|
||||
* name);
|
||||
*/
|
||||
#endif
|
||||
if (*n != *p)
|
||||
@ -1637,7 +1636,7 @@ dump_index(const KeyWord *k, const int *index)
|
||||
*/
|
||||
static int
|
||||
dch_global(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
FormatNode *node, void *data)
|
||||
FormatNode *node, void *data)
|
||||
{
|
||||
if (arg == DCH_FX)
|
||||
DCH_global_fx = true;
|
||||
@ -1704,7 +1703,7 @@ strdigits_len(char *str)
|
||||
*/
|
||||
static int
|
||||
dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
FormatNode *node, void *data)
|
||||
FormatNode *node, void *data)
|
||||
{
|
||||
char *p_inout = inout;
|
||||
struct pg_tm *tm = NULL;
|
||||
@ -1727,7 +1726,7 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
if (is_to_char)
|
||||
{
|
||||
strcpy(inout, ((tm->tm_hour > 11
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? P_M_STR : A_M_STR));
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? P_M_STR : A_M_STR));
|
||||
return strlen(p_inout);
|
||||
}
|
||||
else
|
||||
@ -1747,7 +1746,7 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
if (is_to_char)
|
||||
{
|
||||
strcpy(inout, ((tm->tm_hour > 11
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? PM_STR : AM_STR));
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? PM_STR : AM_STR));
|
||||
return strlen(p_inout);
|
||||
}
|
||||
else
|
||||
@ -1767,7 +1766,7 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
if (is_to_char)
|
||||
{
|
||||
strcpy(inout, ((tm->tm_hour > 11
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? p_m_STR : a_m_STR));
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? p_m_STR : a_m_STR));
|
||||
return strlen(p_inout);
|
||||
}
|
||||
else
|
||||
@ -1787,7 +1786,7 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
if (is_to_char)
|
||||
{
|
||||
strcpy(inout, ((tm->tm_hour > 11
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? pm_STR : am_STR));
|
||||
&& tm->tm_hour < HOURS_PER_DAY) ? pm_STR : am_STR));
|
||||
return strlen(p_inout);
|
||||
}
|
||||
else
|
||||
@ -1925,15 +1924,13 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
}
|
||||
|
||||
/*
|
||||
* 25 is 0.25 and 250 is 0.25 too; 025 is 0.025 and not
|
||||
* 0.25
|
||||
* 25 is 0.25 and 250 is 0.25 too; 025 is 0.025 and not 0.25
|
||||
*/
|
||||
tmfc->ms *= x == 1 ? 100 :
|
||||
x == 2 ? 10 : 1;
|
||||
|
||||
/*
|
||||
* elog(DEBUG3, "X: %d, MS: %d, LEN: %d", x, tmfc->ms,
|
||||
* len);
|
||||
* elog(DEBUG3, "X: %d, MS: %d, LEN: %d", x, tmfc->ms, len);
|
||||
*/
|
||||
return len + SKIP_THth(suf);
|
||||
}
|
||||
@ -1974,8 +1971,7 @@ dch_time(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
x == 5 ? 10 : 1;
|
||||
|
||||
/*
|
||||
* elog(DEBUG3, "X: %d, US: %d, LEN: %d", x, tmfc->us,
|
||||
* len);
|
||||
* elog(DEBUG3, "X: %d, US: %d, LEN: %d", x, tmfc->us, len);
|
||||
*/
|
||||
return len + SKIP_THth(suf);
|
||||
}
|
||||
@ -2049,7 +2045,7 @@ do { \
|
||||
*/
|
||||
static int
|
||||
dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
FormatNode *node, void *data)
|
||||
FormatNode *node, void *data)
|
||||
{
|
||||
char buff[DCH_CACHE_SIZE],
|
||||
workbuff[32],
|
||||
@ -2069,8 +2065,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
tmfc = (TmFromChar *) data;
|
||||
|
||||
/*
|
||||
* In the FROM-char is not difference between "January" or "JANUARY"
|
||||
* or "january", all is before search convert to "first-upper". This
|
||||
* In the FROM-char is not difference between "January" or "JANUARY" or
|
||||
* "january", all is before search convert to "first-upper". This
|
||||
* convention is used for MONTH, MON, DAY, DY
|
||||
*/
|
||||
if (!is_to_char)
|
||||
@ -2193,7 +2189,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_MON:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
if (!tm->tm_mon)
|
||||
return -1;
|
||||
strcpy(inout, months[tm->tm_mon - 1]);
|
||||
@ -2201,14 +2197,14 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_Mon:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
if (!tm->tm_mon)
|
||||
return -1;
|
||||
strcpy(inout, months[tm->tm_mon - 1]);
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_mon:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
if (!tm->tm_mon)
|
||||
return -1;
|
||||
strcpy(inout, months[tm->tm_mon - 1]);
|
||||
@ -2238,38 +2234,38 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
}
|
||||
break;
|
||||
case DCH_DAY:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
strcpy(workbuff, days[tm->tm_wday]);
|
||||
sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, str_toupper(workbuff));
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_Day:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]);
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_day:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
sprintf(inout, "%*s", S_FM(suf) ? 0 : -9, days[tm->tm_wday]);
|
||||
*inout = pg_tolower((unsigned char) *inout);
|
||||
return strlen(p_inout);
|
||||
|
||||
case DCH_DY:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
strcpy(inout, days[tm->tm_wday]);
|
||||
str_toupper(inout);
|
||||
return 3; /* truncate */
|
||||
return 3; /* truncate */
|
||||
|
||||
case DCH_Dy:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
strcpy(inout, days[tm->tm_wday]);
|
||||
return 3; /* truncate */
|
||||
return 3; /* truncate */
|
||||
|
||||
case DCH_dy:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
strcpy(inout, days[tm->tm_wday]);
|
||||
*inout = pg_tolower((unsigned char) *inout);
|
||||
return 3; /* truncate */
|
||||
return 3; /* truncate */
|
||||
|
||||
case DCH_DDD:
|
||||
if (is_to_char)
|
||||
@ -2316,7 +2312,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
}
|
||||
break;
|
||||
case DCH_D:
|
||||
INVALID_FOR_INTERVAL;
|
||||
INVALID_FOR_INTERVAL;
|
||||
if (is_to_char)
|
||||
{
|
||||
sprintf(inout, "%d", tm->tm_wday + 1);
|
||||
@ -2357,7 +2353,7 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
if (is_to_char)
|
||||
{
|
||||
sprintf(inout, "%0*d", S_FM(suf) ? 0 : 2,
|
||||
date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday));
|
||||
date2isoweek(tm->tm_year, tm->tm_mon, tm->tm_mday));
|
||||
if (S_THth(suf))
|
||||
str_numth(p_inout, inout, S_TH_TYPE(suf));
|
||||
return strlen(p_inout);
|
||||
@ -2447,17 +2443,17 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
arg == DCH_YYYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
else
|
||||
sprintf(inout, "%d",
|
||||
arg == DCH_YYYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
tm->tm_year,
|
||||
tm->tm_mon,
|
||||
tm->tm_mday), is_interval));
|
||||
if (S_THth(suf))
|
||||
str_numth(p_inout, inout, S_TH_TYPE(suf));
|
||||
return strlen(p_inout);
|
||||
@ -2486,8 +2482,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
arg == DCH_YYY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(inout, buff + (i - 3));
|
||||
if (S_THth(suf))
|
||||
@ -2518,8 +2514,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
arg == DCH_YY ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(inout, buff + (i - 2));
|
||||
if (S_THth(suf))
|
||||
@ -2531,8 +2527,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
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;
|
||||
@ -2550,8 +2546,8 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
|
||||
arg == DCH_Y ?
|
||||
ADJUST_YEAR(tm->tm_year, is_interval) :
|
||||
ADJUST_YEAR(date2isoyear(tm->tm_year,
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
tm->tm_mon, tm->tm_mday),
|
||||
is_interval));
|
||||
i = strlen(buff);
|
||||
strcpy(inout, buff + (i - 1));
|
||||
if (S_THth(suf))
|
||||
@ -2751,8 +2747,8 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
|
||||
result = palloc((fmt_len * DCH_MAX_ITEM_SIZ) + 1);
|
||||
|
||||
/*
|
||||
* Allocate new memory if format picture is bigger than static cache
|
||||
* and not use cache (call parser always)
|
||||
* Allocate new memory if format picture is bigger than static cache and
|
||||
* not use cache (call parser always)
|
||||
*/
|
||||
if (fmt_len > DCH_CACHE_SIZE)
|
||||
{
|
||||
@ -2778,8 +2774,8 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
|
||||
ent = DCH_cache_getnew(fmt_str);
|
||||
|
||||
/*
|
||||
* Not in the cache, must run parser and save a new
|
||||
* format-picture to the cache.
|
||||
* Not in the cache, must run parser and save a new format-picture
|
||||
* to the cache.
|
||||
*/
|
||||
parse_format(ent->format, fmt_str, DCH_keywords,
|
||||
DCH_suff, DCH_index, DCH_TYPE, NULL);
|
||||
@ -2802,8 +2798,8 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
|
||||
pfree(fmt_str);
|
||||
|
||||
/*
|
||||
* for result is allocated max memory, which current format-picture
|
||||
* needs, now it allocate result with real size
|
||||
* for result is allocated max memory, which current format-picture needs,
|
||||
* now it allocate result with real size
|
||||
*/
|
||||
if (result && *result)
|
||||
{
|
||||
@ -2965,7 +2961,7 @@ to_date(PG_FUNCTION_ARGS)
|
||||
*/
|
||||
static void
|
||||
do_to_timestamp(text *date_txt, text *fmt,
|
||||
struct pg_tm *tm, fsec_t *fsec)
|
||||
struct pg_tm * tm, fsec_t *fsec)
|
||||
{
|
||||
FormatNode *format;
|
||||
TmFromChar tmfc;
|
||||
@ -2990,8 +2986,8 @@ do_to_timestamp(text *date_txt, text *fmt,
|
||||
*(fmt_str + fmt_len) = '\0';
|
||||
|
||||
/*
|
||||
* Allocate new memory if format picture is bigger than static
|
||||
* cache and not use cache (call parser always)
|
||||
* Allocate new memory if format picture is bigger than static cache
|
||||
* and not use cache (call parser always)
|
||||
*/
|
||||
if (fmt_len > DCH_CACHE_SIZE)
|
||||
{
|
||||
@ -3059,8 +3055,8 @@ do_to_timestamp(text *date_txt, text *fmt,
|
||||
DEBUG_TMFC(&tmfc);
|
||||
|
||||
/*
|
||||
* Convert values that user define for FROM_CHAR
|
||||
* (to_date/to_timestamp) to standard 'tm'
|
||||
* Convert values that user define for FROM_CHAR (to_date/to_timestamp) to
|
||||
* standard 'tm'
|
||||
*/
|
||||
if (tmfc.ssss)
|
||||
{
|
||||
@ -3125,18 +3121,19 @@ do_to_timestamp(text *date_txt, text *fmt,
|
||||
|
||||
if (tmfc.year)
|
||||
{
|
||||
if (tmfc.yysz==2 && tmfc.cc)
|
||||
if (tmfc.yysz == 2 && tmfc.cc)
|
||||
{
|
||||
/* CC and YY defined
|
||||
* why -[2000|1900]? See dch_date() DCH_YY code.
|
||||
/*
|
||||
* CC and YY defined why -[2000|1900]? See dch_date() DCH_YY code.
|
||||
*/
|
||||
tm->tm_year = (tmfc.cc-1)*100 + (tmfc.year >= 2000 ? tmfc.year-2000 : tmfc.year-1900);
|
||||
tm->tm_year = (tmfc.cc - 1) * 100 + (tmfc.year >= 2000 ? tmfc.year - 2000 : tmfc.year - 1900);
|
||||
}
|
||||
else if (tmfc.yysz==1 && tmfc.cc)
|
||||
else if (tmfc.yysz == 1 && tmfc.cc)
|
||||
{
|
||||
/* CC and Y defined
|
||||
/*
|
||||
* CC and Y defined
|
||||
*/
|
||||
tm->tm_year = (tmfc.cc-1)*100 + tmfc.year-2000;
|
||||
tm->tm_year = (tmfc.cc - 1) * 100 + tmfc.year - 2000;
|
||||
}
|
||||
else
|
||||
/* set year (and ignore CC if defined) */
|
||||
@ -3184,7 +3181,7 @@ do_to_timestamp(text *date_txt, text *fmt,
|
||||
if (!tm->tm_year)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
|
||||
errmsg("cannot calculate day of year without year information")));
|
||||
errmsg("cannot calculate day of year without year information")));
|
||||
|
||||
y = ysum[isleap(tm->tm_year)];
|
||||
|
||||
@ -3369,9 +3366,9 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, bool *shouldFree)
|
||||
*(str + len) = '\0';
|
||||
|
||||
/*
|
||||
* Allocate new memory if format picture is bigger than static cache
|
||||
* and not use cache (call parser always). This branches sets
|
||||
* shouldFree to true, accordingly.
|
||||
* Allocate new memory if format picture is bigger than static cache and
|
||||
* not use cache (call parser always). This branches sets shouldFree to
|
||||
* true, accordingly.
|
||||
*/
|
||||
if (len > NUM_CACHE_SIZE)
|
||||
{
|
||||
@ -3402,8 +3399,8 @@ NUM_cache(int len, NUMDesc *Num, char *pars_str, bool *shouldFree)
|
||||
ent = NUM_cache_getnew(str);
|
||||
|
||||
/*
|
||||
* Not in the cache, must run parser and save a new
|
||||
* format-picture to the cache.
|
||||
* Not in the cache, must run parser and save a new format-picture
|
||||
* to the cache.
|
||||
*/
|
||||
parse_format(ent->format, str, NUM_keywords,
|
||||
NULL, NUM_index, NUM_TYPE, &ent->Num);
|
||||
@ -3591,18 +3588,18 @@ get_last_relevant_decnum(char *num)
|
||||
static void
|
||||
NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
{
|
||||
bool isread = FALSE;
|
||||
|
||||
bool isread = FALSE;
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, " --- scan start --- id=%s",
|
||||
(id==NUM_0 || id==NUM_9) ? "NUM_0/9" : id==NUM_DEC ? "NUM_DEC" : "???");
|
||||
(id == NUM_0 || id == NUM_9) ? "NUM_0/9" : id == NUM_DEC ? "NUM_DEC" : "???");
|
||||
#endif
|
||||
|
||||
if (*Np->inout_p == ' ')
|
||||
Np->inout_p++;
|
||||
|
||||
#define OVERLOAD_TEST (Np->inout_p >= Np->inout + plen)
|
||||
#define AMOUNT_TEST(_s) (plen-(Np->inout_p-Np->inout) >= _s)
|
||||
#define AMOUNT_TEST(_s) (plen-(Np->inout_p-Np->inout) >= _s)
|
||||
|
||||
if (*Np->inout_p == ' ')
|
||||
Np->inout_p++;
|
||||
@ -3613,13 +3610,13 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
/*
|
||||
* read sign before number
|
||||
*/
|
||||
if (*Np->number == ' ' && (id == NUM_0 || id == NUM_9 ) &&
|
||||
(Np->read_pre + Np->read_post)==0)
|
||||
if (*Np->number == ' ' && (id == NUM_0 || id == NUM_9) &&
|
||||
(Np->read_pre + Np->read_post) == 0)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Try read sign (%c), locale positive: %s, negative: %s",
|
||||
*Np->inout_p, Np->L_positive_sign, Np->L_negative_sign);
|
||||
elog(DEBUG_elog_output, "Try read sign (%c), locale positive: %s, negative: %s",
|
||||
*Np->inout_p, Np->L_positive_sign, Np->L_negative_sign);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -3627,20 +3624,21 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
*/
|
||||
if (IS_LSIGN(Np->Num) && Np->Num->lsign == NUM_LSIGN_PRE)
|
||||
{
|
||||
int x=0;
|
||||
int x = 0;
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Try read locale pre-sign (%c)", *Np->inout_p);
|
||||
#endif
|
||||
if ((x = strlen(Np->L_negative_sign)) &&
|
||||
if ((x = strlen(Np->L_negative_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_negative_sign, x)==0)
|
||||
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
|
||||
{
|
||||
Np->inout_p += x;
|
||||
*Np->number = '-';
|
||||
}
|
||||
else if ((x = strlen(Np->L_positive_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_positive_sign, x)==0)
|
||||
else if ((x = strlen(Np->L_positive_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
|
||||
{
|
||||
Np->inout_p += x;
|
||||
*Np->number = '+';
|
||||
@ -3651,6 +3649,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Try read simple sign (%c)", *Np->inout_p);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* simple + - < >
|
||||
*/
|
||||
@ -3658,14 +3657,14 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
*Np->inout_p == '<'))
|
||||
{
|
||||
|
||||
*Np->number = '-'; /* set - */
|
||||
*Np->number = '-'; /* set - */
|
||||
Np->inout_p++;
|
||||
|
||||
}
|
||||
else if (*Np->inout_p == '+')
|
||||
{
|
||||
|
||||
*Np->number = '+'; /* set + */
|
||||
*Np->number = '+'; /* set + */
|
||||
Np->inout_p++;
|
||||
}
|
||||
}
|
||||
@ -3673,11 +3672,11 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
|
||||
if (OVERLOAD_TEST)
|
||||
return;
|
||||
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Scan for numbers (%c), current number: '%s'", *Np->inout_p, Np->number);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* read digit
|
||||
*/
|
||||
@ -3696,13 +3695,14 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
Np->read_pre++;
|
||||
|
||||
isread = TRUE;
|
||||
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Read digit (%c)", *Np->inout_p);
|
||||
#endif
|
||||
/*
|
||||
* read decimal point
|
||||
*/
|
||||
|
||||
/*
|
||||
* read decimal point
|
||||
*/
|
||||
}
|
||||
else if (IS_DECIMAL(Np->Num) && Np->read_dec == FALSE)
|
||||
{
|
||||
@ -3726,7 +3726,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
elog(DEBUG_elog_output, "Try read locale point (%c)",
|
||||
*Np->inout_p);
|
||||
#endif
|
||||
if (x && AMOUNT_TEST(x) && strncmp(Np->inout_p, Np->decimal, x)==0)
|
||||
if (x && AMOUNT_TEST(x) && strncmp(Np->inout_p, Np->decimal, x) == 0)
|
||||
{
|
||||
Np->inout_p += x - 1;
|
||||
*Np->number_p = '.';
|
||||
@ -3739,69 +3739,68 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
|
||||
|
||||
if (OVERLOAD_TEST)
|
||||
return;
|
||||
|
||||
|
||||
/*
|
||||
* Read sign behind "last" number
|
||||
*
|
||||
* We need sign detection because determine exact position of
|
||||
* post-sign is difficult:
|
||||
* We need sign detection because determine exact position of post-sign is
|
||||
* difficult:
|
||||
*
|
||||
* FM9999.9999999S -> 123.001-
|
||||
* 9.9S -> .5-
|
||||
* FM9.999999MI -> 5.01-
|
||||
* FM9999.9999999S -> 123.001- 9.9S -> .5- FM9.999999MI
|
||||
* -> 5.01-
|
||||
*/
|
||||
if (*Np->number == ' ' && Np->read_pre + Np->read_post > 0)
|
||||
{
|
||||
/*
|
||||
* locale sign (NUM_S) is always anchored behind a last number, if:
|
||||
* - locale sign expected
|
||||
* - last read char was NUM_0/9 or NUM_DEC
|
||||
* - and next char is not digit
|
||||
*/
|
||||
if (IS_LSIGN(Np->Num) && isread &&
|
||||
(Np->inout_p+1) <= Np->inout + plen &&
|
||||
!isdigit((unsigned char) *(Np->inout_p+1)))
|
||||
* locale sign (NUM_S) is always anchored behind a last number, if: -
|
||||
* locale sign expected - last read char was NUM_0/9 or NUM_DEC - and
|
||||
* next char is not digit
|
||||
*/
|
||||
if (IS_LSIGN(Np->Num) && isread &&
|
||||
(Np->inout_p + 1) <= Np->inout + plen &&
|
||||
!isdigit((unsigned char) *(Np->inout_p + 1)))
|
||||
{
|
||||
int x;
|
||||
char *tmp = Np->inout_p++;
|
||||
|
||||
int x;
|
||||
char *tmp = Np->inout_p++;
|
||||
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Try read locale post-sign (%c)", *Np->inout_p);
|
||||
#endif
|
||||
if ((x = strlen(Np->L_negative_sign)) &&
|
||||
if ((x = strlen(Np->L_negative_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_negative_sign, x)==0)
|
||||
strncmp(Np->inout_p, Np->L_negative_sign, x) == 0)
|
||||
{
|
||||
Np->inout_p += x-1; /* -1 .. NUM_processor() do inout_p++ */
|
||||
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
|
||||
*Np->number = '-';
|
||||
}
|
||||
else if ((x = strlen(Np->L_positive_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_positive_sign, x)==0)
|
||||
else if ((x = strlen(Np->L_positive_sign)) &&
|
||||
AMOUNT_TEST(x) &&
|
||||
strncmp(Np->inout_p, Np->L_positive_sign, x) == 0)
|
||||
{
|
||||
Np->inout_p += x-1; /* -1 .. NUM_processor() do inout_p++ */
|
||||
Np->inout_p += x - 1; /* -1 .. NUM_processor() do inout_p++ */
|
||||
*Np->number = '+';
|
||||
}
|
||||
if (*Np->number == ' ')
|
||||
/* no sign read */
|
||||
Np->inout_p = tmp;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* try read non-locale sign, it's happen only if format is not exact
|
||||
* and we cannot determine sign position of MI/PL/SG, an example:
|
||||
*
|
||||
* FM9.999999MI -> 5.01-
|
||||
* FM9.999999MI -> 5.01-
|
||||
*
|
||||
* if (.... && IS_LSIGN(Np->Num)==FALSE) prevents read wrong formats
|
||||
* like to_number('1 -', '9S') where sign is not anchored to last number.
|
||||
* if (.... && IS_LSIGN(Np->Num)==FALSE) prevents read wrong formats like
|
||||
* to_number('1 -', '9S') where sign is not anchored to last number.
|
||||
*/
|
||||
else if (isread==FALSE && IS_LSIGN(Np->Num)==FALSE &&
|
||||
(IS_PLUS(Np->Num) || IS_MINUS(Np->Num)))
|
||||
else if (isread == FALSE && IS_LSIGN(Np->Num) == FALSE &&
|
||||
(IS_PLUS(Np->Num) || IS_MINUS(Np->Num)))
|
||||
{
|
||||
#ifdef DEBUG_TO_FROM_CHAR
|
||||
elog(DEBUG_elog_output, "Try read simple post-sign (%c)", *Np->inout_p);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* simple + -
|
||||
*/
|
||||
@ -3848,8 +3847,8 @@ NUM_numpart_to_char(NUMProc *Np, int id)
|
||||
Np->num_in = FALSE;
|
||||
|
||||
/*
|
||||
* Write sign if real number will write to output Note:
|
||||
* IS_PREDEC_SPACE() handle "9.9" --> " .1"
|
||||
* Write sign if real number will write to output Note: IS_PREDEC_SPACE()
|
||||
* handle "9.9" --> " .1"
|
||||
*/
|
||||
if (Np->sign_wrote == FALSE &&
|
||||
(Np->num_curr >= Np->num_pre || (IS_ZERO(Np->Num) && Np->Num->zero_start == Np->num_curr)) &&
|
||||
@ -4032,7 +4031,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
|
||||
Np->inout = inout;
|
||||
Np->last_relevant = NULL;
|
||||
Np->read_post = 0;
|
||||
Np->read_pre = 0;
|
||||
Np->read_pre = 0;
|
||||
Np->read_dec = FALSE;
|
||||
|
||||
if (Np->Num->zero_start)
|
||||
@ -4114,8 +4113,8 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
|
||||
if (IS_DECIMAL(Np->Num))
|
||||
Np->last_relevant = get_last_relevant_decnum(
|
||||
Np->number +
|
||||
((Np->Num->zero_end - Np->num_pre > 0) ?
|
||||
Np->Num->zero_end - Np->num_pre : 0));
|
||||
((Np->Num->zero_end - Np->num_pre > 0) ?
|
||||
Np->Num->zero_end - Np->num_pre : 0));
|
||||
}
|
||||
|
||||
if (Np->sign_wrote == FALSE && Np->num_pre == 0)
|
||||
@ -4185,10 +4184,10 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
|
||||
/*
|
||||
* Create/reading digit/zero/blank/sing
|
||||
*
|
||||
* 'NUM_S' note:
|
||||
* The locale sign is anchored to number and we read/write it
|
||||
* when we work with first or last number (NUM_0/NUM_9). This
|
||||
* is reason why NUM_S missing in follow switch().
|
||||
* 'NUM_S' note: The locale sign is anchored to number and we
|
||||
* read/write it when we work with first or last number
|
||||
* (NUM_0/NUM_9). This is reason why NUM_S missing in follow
|
||||
* switch().
|
||||
*/
|
||||
switch (n->key->id)
|
||||
{
|
||||
@ -4497,7 +4496,7 @@ numeric_to_number(PG_FUNCTION_ARGS)
|
||||
result = DirectFunctionCall3(numeric_in,
|
||||
CStringGetDatum(numstr),
|
||||
ObjectIdGetDatum(InvalidOid),
|
||||
Int32GetDatum(((precision << 16) | scale) + VARHDRSZ));
|
||||
Int32GetDatum(((precision << 16) | scale) + VARHDRSZ));
|
||||
pfree(numstr);
|
||||
return result;
|
||||
}
|
||||
@ -4536,7 +4535,7 @@ numeric_to_char(PG_FUNCTION_ARGS)
|
||||
Int32GetDatum(0)));
|
||||
numstr = orgnum =
|
||||
int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
|
||||
NumericGetDatum(x))));
|
||||
NumericGetDatum(x))));
|
||||
pfree(x);
|
||||
}
|
||||
else
|
||||
@ -4546,16 +4545,16 @@ numeric_to_char(PG_FUNCTION_ARGS)
|
||||
if (IS_MULTI(&Num))
|
||||
{
|
||||
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(10)));
|
||||
Int32GetDatum(10)));
|
||||
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(Num.multi)));
|
||||
Int32GetDatum(Num.multi)));
|
||||
|
||||
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
||||
NumericGetDatum(a),
|
||||
NumericGetDatum(b)));
|
||||
val = DatumGetNumeric(DirectFunctionCall2(numeric_mul,
|
||||
NumericGetDatum(value),
|
||||
NumericGetDatum(x)));
|
||||
NumericGetDatum(value),
|
||||
NumericGetDatum(x)));
|
||||
pfree(x);
|
||||
pfree(a);
|
||||
pfree(b);
|
||||
@ -4639,7 +4638,7 @@ int4_to_char(PG_FUNCTION_ARGS)
|
||||
else
|
||||
{
|
||||
orgnum = DatumGetCString(DirectFunctionCall1(int4out,
|
||||
Int32GetDatum(value)));
|
||||
Int32GetDatum(value)));
|
||||
}
|
||||
len = strlen(orgnum);
|
||||
|
||||
@ -4711,7 +4710,7 @@ int8_to_char(PG_FUNCTION_ARGS)
|
||||
{
|
||||
/* Currently don't support int8 conversion to roman... */
|
||||
numstr = orgnum = int_to_roman(DatumGetInt32(
|
||||
DirectFunctionCall1(int84, Int64GetDatum(value))));
|
||||
DirectFunctionCall1(int84, Int64GetDatum(value))));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4720,14 +4719,14 @@ int8_to_char(PG_FUNCTION_ARGS)
|
||||
double multi = pow((double) 10, (double) Num.multi);
|
||||
|
||||
value = DatumGetInt64(DirectFunctionCall2(int8mul,
|
||||
Int64GetDatum(value),
|
||||
DirectFunctionCall1(dtoi8,
|
||||
Float8GetDatum(multi))));
|
||||
Int64GetDatum(value),
|
||||
DirectFunctionCall1(dtoi8,
|
||||
Float8GetDatum(multi))));
|
||||
Num.pre += Num.multi;
|
||||
}
|
||||
|
||||
orgnum = DatumGetCString(DirectFunctionCall1(int8out,
|
||||
Int64GetDatum(value)));
|
||||
Int64GetDatum(value)));
|
||||
len = strlen(orgnum);
|
||||
|
||||
if (*orgnum == '-')
|
||||
|
Reference in New Issue
Block a user