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

Commit0ab2921

Browse files
committed
Change time function names to be more consistent, and check for zero divides, from Michael Reifenberg.
1 parent23cce4a commit0ab2921

File tree

7 files changed

+68
-37
lines changed

7 files changed

+68
-37
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.7 1997/04/28 16:15:13 scrappy Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.8 1997/08/21 23:56:37 momjian Exp $
1313
*/
1414

1515
#include<stdio.h>
@@ -371,6 +371,9 @@ cash_div(Cash *c, float8 *f)
371371
if (!PointerIsValid(result=PALLOCTYPE(Cash)))
372372
elog(WARN,"Memory allocation failed, can't divide cash",NULL);
373373

374+
if (*f==0.0)
375+
elog(WARN,"cash_div: divide by 0.0 error");
376+
374377
*result=rint(*c /*f);
375378

376379
return(result);

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.32 1997/08/19 21:34:34 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.33 1997/08/21 23:56:40 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -645,7 +645,7 @@ datetime_larger(DateTime *datetime1, DateTime *datetime2)
645645

646646

647647
TimeSpan*
648-
datetime_sub(DateTime*datetime1,DateTime*datetime2)
648+
datetime_mi(DateTime*datetime1,DateTime*datetime2)
649649
{
650650
TimeSpan*result;
651651

@@ -672,10 +672,10 @@ datetime_sub(DateTime *datetime1, DateTime *datetime2)
672672
result->month=0;
673673

674674
return(result);
675-
}/*datetime_sub() */
675+
}/*datetime_mi() */
676676

677677

678-
/*datetime_add_span()
678+
/*datetime_pl_span()
679679
* Add a timespan to a datetime data type.
680680
* Note that timespan has provisions for qualitative year/month
681681
* units, so try to do the right thing with them.
@@ -684,7 +684,7 @@ datetime_sub(DateTime *datetime1, DateTime *datetime2)
684684
* to the last day of month.
685685
*/
686686
DateTime*
687-
datetime_add_span(DateTime*datetime,TimeSpan*span)
687+
datetime_pl_span(DateTime*datetime,TimeSpan*span)
688688
{
689689
DateTime*result;
690690
DateTimedt;
@@ -697,7 +697,7 @@ datetime_add_span(DateTime *datetime, TimeSpan *span)
697697
result=PALLOCTYPE(DateTime);
698698

699699
#ifdefDATEDEBUG
700-
printf("datetime_add_span- add %f to %d %f\n",*datetime,span->month,span->time);
700+
printf("datetime_pl_span- add %f to %d %f\n",*datetime,span->month,span->time);
701701
#endif
702702

703703
if (DATETIME_NOT_FINITE(*datetime)) {
@@ -721,7 +721,7 @@ printf( "datetime_add_span- add %f to %d %f\n", *datetime, span->month, span->ti
721721

722722
if (datetime2tm(dt,&tz,tm,&fsec,&tzn)==0) {
723723
#ifdefDATEDEBUG
724-
printf("datetime_add_span- date was %04d-%02d-%02d %02d:%02d:%02d\n",
724+
printf("datetime_pl_span- date was %04d-%02d-%02d %02d:%02d:%02d\n",
725725
tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
726726
#endif
727727
tm->tm_mon+=span->month;
@@ -743,7 +743,7 @@ printf( "datetime_add_span- date was %04d-%02d-%02d %02d:%02d:%02d\n",
743743
};
744744

745745
#ifdefDATEDEBUG
746-
printf("datetime_add_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
746+
printf("datetime_pl_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
747747
tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
748748
#endif
749749
if (tm2datetime(tm,fsec,&tz,&dt)!=0)
@@ -758,10 +758,10 @@ printf( "datetime_add_span- date becomes %04d-%02d-%02d %02d:%02d:%02d\n",
758758
};
759759

760760
return(result);
761-
}/*datetime_add_span() */
761+
}/*datetime_pl_span() */
762762

763763
DateTime*
764-
datetime_sub_span(DateTime*datetime,TimeSpan*span)
764+
datetime_mi_span(DateTime*datetime,TimeSpan*span)
765765
{
766766
DateTime*result;
767767
TimeSpantspan;
@@ -772,10 +772,10 @@ datetime_sub_span(DateTime *datetime, TimeSpan *span)
772772
tspan.month=-span->month;
773773
tspan.time=-span->time;
774774

775-
result=datetime_add_span(datetime,&tspan);
775+
result=datetime_pl_span(datetime,&tspan);
776776

777777
return(result);
778-
}/*datetime_sub_span() */
778+
}/*datetime_mi_span() */
779779

780780

781781
TimeSpan*
@@ -885,7 +885,7 @@ printf( "timespan_larger- months %d %d times %f %f spans %f %f\n",
885885

886886

887887
TimeSpan*
888-
timespan_add(TimeSpan*span1,TimeSpan*span2)
888+
timespan_pl(TimeSpan*span1,TimeSpan*span2)
889889
{
890890
TimeSpan*result;
891891

@@ -898,10 +898,10 @@ timespan_add(TimeSpan *span1, TimeSpan *span2)
898898
result->time=JROUND(span1->time+span2->time);
899899

900900
return(result);
901-
}/*timespan_add() */
901+
}/*timespan_pl() */
902902

903903
TimeSpan*
904-
timespan_sub(TimeSpan*span1,TimeSpan*span2)
904+
timespan_mi(TimeSpan*span1,TimeSpan*span2)
905905
{
906906
TimeSpan*result;
907907

@@ -914,8 +914,27 @@ timespan_sub(TimeSpan *span1, TimeSpan *span2)
914914
result->time=JROUND(span1->time-span2->time);
915915

916916
return(result);
917-
}/*timespan_sub() */
917+
}/*timespan_mi() */
918918

919+
TimeSpan*
920+
timespan_div(TimeSpan*span1,float8*arg2)
921+
{
922+
TimeSpan*result;
923+
924+
if ((!PointerIsValid(span1))|| (!PointerIsValid(arg2)))
925+
returnNULL;
926+
927+
if (!PointerIsValid(result=PALLOCTYPE(TimeSpan)))
928+
elog(WARN,"Memory allocation failed, can't subtract timespans",NULL);
929+
930+
if (*arg2==0.0)
931+
elog(WARN,"timespan_div: divide by 0.0 error");
932+
933+
result->month=rint(span1->month /*arg2);
934+
result->time=JROUND(span1->time /*arg2);
935+
936+
return(result);
937+
}/* timespan_div() */
919938

920939
/* datetime_age()
921940
* Calculate time difference while retaining year/month fields.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.15 1997/08/19 21:34:39 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.16 1997/08/21 23:56:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2555,6 +2555,9 @@ point_div(Point *p1, Point *p2)
25552555

25562556
div= (p2->x*p2->x)+ (p2->y*p2->y);
25572557

2558+
if (div==0.0)
2559+
elog(WARN,"point_div: divide by 0.0 error");
2560+
25582561
result->x= ((p1->x*p2->x)+ (p1->y*p2->y)) /div;
25592562
result->y= ((p2->x*p1->y)- (p2->y*p1->x)) /div;
25602563

‎src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_aggregate.h,v 1.7 1997/04/27 19:22:36 thomas Exp $
10+
* $Id: pg_aggregate.h,v 1.8 1997/08/21 23:56:45 momjian Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -92,12 +92,14 @@ DATA(insert OID = 0 ( avg PGUID int2pl int2inc int2div 21 21 21
9292
DATA(insertOID=0 (avgPGUIDfloat4plfloat4incfloat4div700700700700_null_0.0 ));
9393
DATA(insertOID=0 (avgPGUIDfloat8plfloat8incfloat8div701701701701_null_0.0 ));
9494
DATA(insertOID=0 (avgPGUIDcash_plfloat8inccash_div790790701790_null_0.0 ));
95+
DATA(insertOID=0 (avgPGUIDtimespan_plfloat8inctimespan_div118611867011186_null_0.0 ));
9596

9697
DATA(insertOID=0 (sumPGUIDint4pl--2323023_null__null_ ));
9798
DATA(insertOID=0 (sumPGUIDint2pl--2121021_null__null_ ));
9899
DATA(insertOID=0 (sumPGUIDfloat4pl--7007000700_null__null_ ));
99100
DATA(insertOID=0 (sumPGUIDfloat8pl--7017010701_null__null_ ));
100101
DATA(insertOID=0 (sumPGUIDcash_pl--7907900790_null__null_ ));
102+
DATA(insertOID=0 (sumPGUIDtimespan_pl--1186118601186_null__null_ ));
101103

102104
DATA(insertOID=0 (maxPGUIDint4larger--2323023_null__null_ ));
103105
DATA(insertOID=0 (maxPGUIDint2larger--2121021_null__null_ ));

‎src/include/catalog/pg_operator.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_operator.h,v 1.12 1997/07/29 16:17:50 thomas Exp $
10+
* $Id: pg_operator.h,v 1.13 1997/08/21 23:56:48 momjian Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -487,9 +487,9 @@ DATA(insert OID = 1323 ( "<=" PGUID 0 b t f 1184 1184 16 1324 1324 0 0 da
487487
DATA(insertOID=1324 (">"PGUID0btf11841184161323132300datetime_gtintltselintltjoinsel ));
488488
DATA(insertOID=1325 (">="PGUID0btf11841184161322132200datetime_geintltselintltjoinsel ));
489489

490-
DATA(insertOID=1327 ("+"PGUID0btf1184118611841327000datetime_add_span-- ));
491-
DATA(insertOID=1328 ("-"PGUID0btf1184118411860000datetime_sub-- ));
492-
DATA(insertOID=1329 ("-"PGUID0btf1184118611840000datetime_sub_span-- ));
490+
DATA(insertOID=1327 ("+"PGUID0btf1184118611841327000datetime_pl_span-- ));
491+
DATA(insertOID=1328 ("-"PGUID0btf1184118411860000datetime_mi-- ));
492+
DATA(insertOID=1329 ("-"PGUID0btf1184118611840000datetime_mi_span-- ));
493493

494494
/* timespan operators */
495495
DATA(insertOID=1330 ("="PGUID0btf11861186161330133113321332timespan_eqeqseleqjoinsel ));
@@ -500,8 +500,8 @@ DATA(insert OID = 1334 ( ">" PGUID 0 b t f 1186 1186 16 1333 1333 0 0 ti
500500
DATA(insertOID=1335 (">="PGUID0btf11861186161332133200timespan_geintltselintltjoinsel ));
501501

502502
DATA(insertOID=1336 ("-"PGUID0ltf0118611860000timespan_um00 ));
503-
DATA(insertOID=1337 ("+"PGUID0btf1186118611861337000timespan_add-- ));
504-
DATA(insertOID=1338 ("-"PGUID0btf1186118611860000timespan_sub-- ));
503+
DATA(insertOID=1337 ("+"PGUID0btf1186118611861337000timespan_pl-- ));
504+
DATA(insertOID=1338 ("-"PGUID0btf1186118611860000timespan_mi-- ));
505505

506506
/* float48 operators */
507507
DATA(insertOID=1116 ("+"PGUID0btf7007017011116000float48pl-- ));
@@ -628,6 +628,7 @@ DATA(insert OID = 1559 ( "##" PGUID 0 b t f 600 603 600 0 0 0 0 close
628628
DATA(insertOID=1566 ("##"PGUID0btf6016286000000close_sl-- ));
629629
DATA(insertOID=1567 ("##"PGUID0btf6016036000000close_sb-- ));
630630
DATA(insertOID=1568 ("##"PGUID0btf6286036000000close_lb-- ));
631+
DATA(insertOID=1585 ("/"PGUID0btf1186118611860000timespan_div-- ));
631632

632633
/*
633634
* function prototypes

‎src/include/catalog/pg_proc.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.24 1997/07/29 16:17:52 thomas Exp $
9+
* $Id: pg_proc.h,v 1.25 1997/08/21 23:56:51 momjian Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -828,8 +828,8 @@ DATA(insert OID = 1165 ( timespan_le PGUID 11 f t f 2 f 16 "1186 1186" 100
828828
DATA(insertOID=1166 (timespan_gePGUID11ftf2f16"1186 1186"10000100foobar ));
829829
DATA(insertOID=1167 (timespan_gtPGUID11ftf2f16"1186 1186"10000100foobar ));
830830
DATA(insertOID=1168 (timespan_umPGUID11ftf1f1186"1186"10000100foobar ));
831-
DATA(insertOID=1169 (timespan_addPGUID11ftf2f1186"1186 1186"10000100foobar ));
832-
DATA(insertOID=1170 (timespan_subPGUID11ftf2f1186"1186 1186"10000100foobar ));
831+
DATA(insertOID=1169 (timespan_plPGUID11ftf2f1186"1186 1186"10000100foobar ));
832+
DATA(insertOID=1170 (timespan_miPGUID11ftf2f1186"1186 1186"10000100foobar ));
833833
DATA(insertOID=1171 (datetime_partPGUID11ftf2f701"25 1184"10000100foobar ));
834834
DATA(insertOID=1172 (timespan_partPGUID11ftf2f701"25 1186"10000100foobar ));
835835

@@ -842,9 +842,9 @@ DATA(insert OID = 1178 ( datetime_date PGUID 11 f t f 1 f 1082 "1184" 100
842842
DATA(insertOID=1179 (abstime_datePGUID11ftf1f1082"702"10000100foobar ));
843843
DATA(insertOID=1180 (datetime_abstimePGUID11ftf1f702"1184"10000100foobar ));
844844

845-
DATA(insertOID=1188 (datetime_subPGUID11ftf2f1186"1184 1184"10000100foobar ));
846-
DATA(insertOID=1189 (datetime_add_spanPGUID11ftf2f1184"1184 1186"10000100foobar ));
847-
DATA(insertOID=1190 (datetime_sub_spanPGUID11ftf2f1184"1184 1186"10000100foobar ));
845+
DATA(insertOID=1188 (datetime_miPGUID11ftf2f1186"1184 1184"10000100foobar ));
846+
DATA(insertOID=1189 (datetime_pl_spanPGUID11ftf2f1184"1184 1186"10000100foobar ));
847+
DATA(insertOID=1190 (datetime_mi_spanPGUID11ftf2f1184"1184 1186"10000100foobar ));
848848
DATA(insertOID=1191 (text_datetimePGUID11ftf1f1184"25"10000100foobar ));
849849
DATA(insertOID=1192 (datetime_textPGUID11ftf1f25"1184"10000100foobar ));
850850
DATA(insertOID=1193 (timespan_textPGUID11ftf1f1186"25"10000100foobar ));
@@ -1088,6 +1088,8 @@ DATA(insert OID = 882 ( rtrim PGUID 14 f t f 1 f 25 "25" 100 0 0 100 "
10881088
DATA(insertOID=883 (substrPGUID14ftf2f25"25 23"10000100"select substr($1, $2, 10000)"- ));
10891089
DATA(insertOID=884 (btrimPGUID11ftf2f25"25 25"10000100foobar ));
10901090
DATA(insertOID=885 (btrimPGUID14ftf1f25"25"10000100"select btrim($1, \' \')"- ));
1091+
/* XXX Help, where should I go to */
1092+
DATA(insertOID=1586 (timespan_divPGUID11ftf2f1186"1186 701"10000100foobar ));
10911093

10921094
/* SEQUENCEs nextval & currval functions */
10931095
DATA(insertOID=1317 (nextvalPGUID11ftf1f23"25"10000100foobar ));

‎src/include/utils/dt.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: dt.h,v 1.16 1997/08/19 21:40:30 momjian Exp $
11+
* $Id: dt.h,v 1.17 1997/08/21 23:57:00 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -283,12 +283,13 @@ extern float64 timespan_part(text *units, TimeSpan *timespan);
283283
externtext*datetime_zone(text*zone,DateTime*datetime);
284284

285285
externTimeSpan*timespan_um(TimeSpan*span);
286-
externTimeSpan*timespan_add(TimeSpan*span1,TimeSpan*span2);
287-
externTimeSpan*timespan_sub(TimeSpan*span1,TimeSpan*span2);
286+
externTimeSpan*timespan_pl(TimeSpan*span1,TimeSpan*span2);
287+
externTimeSpan*timespan_mi(TimeSpan*span1,TimeSpan*span2);
288+
externTimeSpan*timespan_div(TimeSpan*span1,float8*arg2);
288289

289-
externTimeSpan*datetime_sub(DateTime*dt1,DateTime*dt2);
290-
externDateTime*datetime_add_span(DateTime*dt,TimeSpan*span);
291-
externDateTime*datetime_sub_span(DateTime*dt,TimeSpan*span);
290+
externTimeSpan*datetime_mi(DateTime*dt1,DateTime*dt2);
291+
externDateTime*datetime_pl_span(DateTime*dt,TimeSpan*span);
292+
externDateTime*datetime_mi_span(DateTime*dt,TimeSpan*span);
292293
externTimeSpan*datetime_age(DateTime*dt1,DateTime*dt2);
293294

294295
externvoidGetCurrentTime(structtm*tm);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp