Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1031cd

Browse files
committed
Adjust date/time input parsing code to correctly distinguish the four
SQLSTATE error codes required by SQL99 (invalid format, datetime fieldoverflow, interval field overflow, invalid time zone displacement value).Also emit a HINT about DateStyle in cases where it seems appropriate.Per recent gripes.
1 parent3722226 commitd1031cd

File tree

13 files changed

+465
-307
lines changed

13 files changed

+465
-307
lines changed

‎src/backend/utils/adt/date.c

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.90 2003/08/08 00:10:31 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.91 2003/08/27 23:29:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -62,20 +62,19 @@ date_in(PG_FUNCTION_ARGS)
6262
inttzp;
6363
intdtype;
6464
intnf;
65+
intdterr;
6566
char*field[MAXDATEFIELDS];
6667
intftype[MAXDATEFIELDS];
6768
charlowstr[MAXDATELEN+1];
6869

6970
if (strlen(str) >=sizeof(lowstr))
70-
ereport(ERROR,
71-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
72-
errmsg("invalid input syntax for date: \"%s\"",str)));
73-
74-
if ((ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf)!=0)
75-
|| (DecodeDateTime(field,ftype,nf,&dtype,tm,&fsec,&tzp)!=0))
76-
ereport(ERROR,
77-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
78-
errmsg("invalid input syntax for date: \"%s\"",str)));
71+
dterr=DTERR_BAD_FORMAT;
72+
else
73+
dterr=ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf);
74+
if (dterr==0)
75+
dterr=DecodeDateTime(field,ftype,nf,&dtype,tm,&fsec,&tzp);
76+
if (dterr!=0)
77+
DateTimeParseError(dterr,str,"date");
7978

8079
switch (dtype)
8180
{
@@ -95,9 +94,8 @@ date_in(PG_FUNCTION_ARGS)
9594
break;
9695

9796
default:
98-
ereport(ERROR,
99-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
100-
errmsg("invalid input syntax for date: \"%s\"",str)));
97+
DateTimeParseError(DTERR_BAD_FORMAT,str,"date");
98+
break;
10199
}
102100

103101
date=date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)-POSTGRES_EPOCH_JDATE;
@@ -559,21 +557,20 @@ time_in(PG_FUNCTION_ARGS)
559557
*tm=&tt;
560558
inttz;
561559
intnf;
560+
intdterr;
562561
charlowstr[MAXDATELEN+1];
563562
char*field[MAXDATEFIELDS];
564563
intdtype;
565564
intftype[MAXDATEFIELDS];
566565

567566
if (strlen(str) >=sizeof(lowstr))
568-
ereport(ERROR,
569-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
570-
errmsg("invalid input syntax for time: \"%s\"",str)));
571-
572-
if ((ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf)!=0)
573-
|| (DecodeTimeOnly(field,ftype,nf,&dtype,tm,&fsec,&tz)!=0))
574-
ereport(ERROR,
575-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
576-
errmsg("invalid input syntax for time: \"%s\"",str)));
567+
dterr=DTERR_BAD_FORMAT;
568+
else
569+
dterr=ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf);
570+
if (dterr==0)
571+
dterr=DecodeTimeOnly(field,ftype,nf,&dtype,tm,&fsec,&tz);
572+
if (dterr!=0)
573+
DateTimeParseError(dterr,str,"time");
577574

578575
tm2time(tm,fsec,&result);
579576
AdjustTimeForTypmod(&result,typmod);
@@ -1424,23 +1421,20 @@ timetz_in(PG_FUNCTION_ARGS)
14241421
*tm=&tt;
14251422
inttz;
14261423
intnf;
1424+
intdterr;
14271425
charlowstr[MAXDATELEN+1];
14281426
char*field[MAXDATEFIELDS];
14291427
intdtype;
14301428
intftype[MAXDATEFIELDS];
14311429

14321430
if (strlen(str) >=sizeof(lowstr))
1433-
ereport(ERROR,
1434-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
1435-
errmsg("invalid input syntax for time with time zone: \"%s\"",
1436-
str)));
1437-
1438-
if ((ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf)!=0)
1439-
|| (DecodeTimeOnly(field,ftype,nf,&dtype,tm,&fsec,&tz)!=0))
1440-
ereport(ERROR,
1441-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
1442-
errmsg("invalid input syntax for time with time zone: \"%s\"",
1443-
str)));
1431+
dterr=DTERR_BAD_FORMAT;
1432+
else
1433+
dterr=ParseDateTime(str,lowstr,field,ftype,MAXDATEFIELDS,&nf);
1434+
if (dterr==0)
1435+
dterr=DecodeTimeOnly(field,ftype,nf,&dtype,tm,&fsec,&tz);
1436+
if (dterr!=0)
1437+
DateTimeParseError(dterr,str,"time with time zone");
14441438

14451439
result= (TimeTzADT*)palloc(sizeof(TimeTzADT));
14461440
tm2timetz(tm,fsec,tz,result);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp