Skip to content

Commit 0f65f9c

Browse files
committed
NLS refactor
1 parent b80aceb commit 0f65f9c

7 files changed

Lines changed: 151 additions & 180 deletions

File tree

‎contrib/ivorysql_ora/src/datatype/oradate.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*-------------------------------------------------------------------------
22
* Copyright 2025 IvorySQL Global Development Team
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -166,16 +166,16 @@ timestamp2timestamptz(Timestamp timestamp)
166166
Datum
167167
oradate_in(PG_FUNCTION_ARGS)
168168
{
169-
char *str = PG_GETARG_CSTRING(0);
170-
Oid collid = PG_GET_COLLATION();
169+
char *str = PG_GETARG_CSTRING(0);
170+
Oid collid = PG_GET_COLLATION();
171171
Timestamp result;
172-
struct pg_tm tm;
172+
struct pg_tm tm;
173173
fsec_t fsec;
174174

175175
if (strcmp(nls_date_format, "pg") == 0 || DATETIME_IGNORE_NLS(datetime_ignore_nls_mask, ORADATE_MASK))
176176
{
177177
return DirectFunctionCall1(date_timestamp,
178-
DirectFunctionCall1(date_in, CStringGetDatum(str)));
178+
DirectFunctionCall1(date_in, CStringGetDatum(str)));
179179
}
180180
else
181181
{
@@ -206,8 +206,8 @@ oradate_out(PG_FUNCTION_ARGS)
206206
text *date_str;
207207

208208
date_str = DatumGetTextP(DirectFunctionCall2(timestamp_to_char,
209-
TimestampGetDatum(timestamp),
210-
PointerGetDatum(cstring_to_text(nls_date_format))));
209+
TimestampGetDatum(timestamp),
210+
PointerGetDatum(cstring_to_text(nls_date_format))));
211211

212212
result = text_to_cstring(date_str);
213213
PG_RETURN_CSTRING(result);
@@ -589,7 +589,7 @@ oradate_cmp_oratimestampltz(PG_FUNCTION_ARGS)
589589
}
590590

591591
/*****************************************************************************
592-
* Hash index support procedure
592+
* Hash index support procedure
593593
*****************************************************************************/
594594
Datum
595595
oradate_hash(PG_FUNCTION_ARGS)
@@ -744,4 +744,3 @@ oradate_oratimestampltz(PG_FUNCTION_ARGS)
744744

745745
PG_RETURN_TIMESTAMPTZ(timestamp2timestamptz(timestamp));
746746
}
747-

‎contrib/ivorysql_ora/src/datatype/oratimestamp.c‎

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*-------------------------------------------------------------------------
22
* Copyright 2025 IvorySQL Global Development Team
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -163,8 +163,8 @@ OraAdjustTimestampForTypmod(Timestamp *time, int32 typmod)
163163
if (typmod < 0 || typmod > MAX_TIMESTAMP_PRECISION)
164164
ereport(ERROR,
165165
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
166-
errmsg("timestamp(%d) precision must be between %d and %d",
167-
typmod, 0, MAX_TIMESTAMP_PRECISION)));
166+
errmsg("timestamp(%d) precision must be between %d and %d",
167+
typmod, 0, MAX_TIMESTAMP_PRECISION)));
168168

169169
/*
170170
* Note: this round-to-nearest code is not completely consistent about
@@ -214,15 +214,15 @@ anytimestamp_typmodin(bool istz, ArrayType *ta)
214214
{
215215
ereport(WARNING,
216216
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
217-
errmsg("TIMESTAMP(%d)%s effective number of fractional seconds is 6,the part of excess is 0",
218-
*tl, (istz ? " WITH TIME ZONE" : ""))));
217+
errmsg("TIMESTAMP(%d)%s effective number of fractional seconds is 6,the part of excess is 0",
218+
*tl, (istz ? " WITH TIME ZONE" : ""))));
219219
typmod = *tl;
220220
}
221221
else if (*tl > ORACLE_MAX_TIMESTAMP_PRECISION)
222222
{
223223
ereport(ERROR,
224224
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
225-
errmsg("the precision of datetime out of rang")));
225+
errmsg("the precision of datetime out of rang")));
226226
}
227227
else
228228
typmod = *tl;
@@ -288,17 +288,17 @@ oratimestamp_in(PG_FUNCTION_ARGS)
288288
Oid typelem = PG_GETARG_OID(1);
289289
#endif
290290
int32 typmod = PG_GETARG_INT32(2);
291-
Oid collid = PG_GET_COLLATION();
291+
Oid collid = PG_GET_COLLATION();
292292
Timestamp result;
293293
struct pg_tm tm;
294294
fsec_t fsec;
295295

296296
if (strcmp(nls_timestamp_format, "pg") == 0 || DATETIME_IGNORE_NLS(datetime_ignore_nls_mask, ORATIMESTAMP_MASK))
297297
{
298298
return DirectFunctionCall3(timestamp_in,
299-
CStringGetDatum(str),
300-
ObjectIdGetDatum(InvalidOid),
301-
Int32GetDatum(typmod));
299+
CStringGetDatum(str),
300+
ObjectIdGetDatum(InvalidOid),
301+
Int32GetDatum(typmod));
302302
}
303303
else
304304
{
@@ -330,8 +330,8 @@ oratimestamp_out(PG_FUNCTION_ARGS)
330330
text *date_str;
331331

332332
date_str = DatumGetTextP(DirectFunctionCall2(timestamp_to_char,
333-
TimestampGetDatum(timestamp),
334-
PointerGetDatum(cstring_to_text(nls_timestamp_format))));
333+
TimestampGetDatum(timestamp),
334+
PointerGetDatum(cstring_to_text(nls_timestamp_format))));
335335

336336
result = text_to_cstring(date_str);
337337
PG_RETURN_CSTRING(result);
@@ -717,7 +717,7 @@ oratimestamp_cmp_oratimestampltz(PG_FUNCTION_ARGS)
717717
}
718718

719719
/*****************************************************************************
720-
* Hash index support procedure
720+
* Hash index support procedure
721721
*****************************************************************************/
722722
Datum
723723
oratimestamp_hash(PG_FUNCTION_ARGS)
@@ -775,7 +775,7 @@ oratimestamp(PG_FUNCTION_ARGS)
775775
/* No work if typmod is invalid */
776776
if (typmod == -1)
777777
PG_RETURN_TIMESTAMP(source);
778-
778+
779779
OraAdjustTimestampForTypmod(&source, typmod);
780780
PG_RETURN_TIMESTAMP(source);
781781
}
@@ -851,7 +851,7 @@ Datum
851851
oradate_mi_oratimestampltz(PG_FUNCTION_ARGS)
852852
{
853853
Timestamp dt1 = PG_GETARG_TIMESTAMP(0);
854-
TimestampTz dt2 = PG_GETARG_TIMESTAMP(1);
854+
TimestampTz dt2 = PG_GETARG_TIMESTAMP(1);
855855
Timestamp timestamp;
856856
struct pg_tm tt,
857857
*tm = &tt;
@@ -883,7 +883,7 @@ oradate_mi_oratimestampltz(PG_FUNCTION_ARGS)
883883
result->day = 0;
884884

885885
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
886-
IntervalPGetDatum(result)));
886+
IntervalPGetDatum(result)));
887887

888888
PG_RETURN_INTERVAL_P(result);
889889
}
@@ -897,7 +897,7 @@ oradate_mi_oratimestampltz(PG_FUNCTION_ARGS)
897897
Datum
898898
oratimestampltz_mi_oradate(PG_FUNCTION_ARGS)
899899
{
900-
TimestampTz dt1 = PG_GETARG_TIMESTAMP(0);
900+
TimestampTz dt1 = PG_GETARG_TIMESTAMP(0);
901901
Timestamp dt2 = PG_GETARG_TIMESTAMP(1);
902902
Timestamp timestamp;
903903
struct pg_tm tt,
@@ -930,7 +930,7 @@ oratimestampltz_mi_oradate(PG_FUNCTION_ARGS)
930930
result->day = 0;
931931

932932
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
933-
IntervalPGetDatum(result)));
933+
IntervalPGetDatum(result)));
934934

935935
PG_RETURN_INTERVAL_P(result);
936936
}
@@ -995,7 +995,7 @@ oratimestamp_mi(PG_FUNCTION_ARGS)
995995
result->day = 0;
996996

997997
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
998-
IntervalPGetDatum(result)));
998+
IntervalPGetDatum(result)));
999999

10001000
PG_RETURN_INTERVAL_P(result);
10011001
}
@@ -1050,7 +1050,7 @@ oradate_pl_interval(PG_FUNCTION_ARGS)
10501050

10511051
/* Compatible oracle oradate dont have fsec */
10521052
fsec = 0;
1053-
1053+
10541054
if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
10551055
ereport(ERROR,
10561056
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1076,7 +1076,7 @@ oradate_pl_interval(PG_FUNCTION_ARGS)
10761076

10771077
/* Compatible oracle oradate dont have fsec */
10781078
fsec = 0;
1079-
1079+
10801080
if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
10811081
ereport(ERROR,
10821082
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
@@ -1456,7 +1456,7 @@ oradate_mi_number(PG_FUNCTION_ARGS)
14561456
PG_RETURN_TIMESTAMP(result);
14571457
}
14581458

1459-
/*
1459+
/*
14601460
* Compatible oracle
14611461
* The arithmetic operation of oratimestamp plus number, Result
14621462
* type is oradate.
@@ -1481,7 +1481,7 @@ oratimestamp_pl_number(PG_FUNCTION_ARGS)
14811481
ereport(ERROR,
14821482
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
14831483
errmsg("timestamp out of range")));
1484-
1484+
14851485
/* Convert timestamp to date ignore time zone and fractional second */
14861486
if (tm2timestamp(tm, 0, NULL, &result) != 0)
14871487
ereport(ERROR,
@@ -1490,14 +1490,14 @@ oratimestamp_pl_number(PG_FUNCTION_ARGS)
14901490

14911491
addend = DatumGetFloat8(DirectFunctionCall1(numeric_float8, NumericGetDatum(num)));
14921492
addend = rint(addend * USECS_PER_DAY);
1493-
1493+
14941494
result = result + addend;
14951495
}
14961496

14971497
PG_RETURN_TIMESTAMP(result);
14981498
}
14991499

1500-
/*
1500+
/*
15011501
* Compatible oracle
15021502
* The arithmetic operation of number plus oratimestamp, Result
15031503
* type is oradate.
@@ -1531,7 +1531,7 @@ number_pl_oratimestamp(PG_FUNCTION_ARGS)
15311531

15321532
addend = DatumGetFloat8(DirectFunctionCall1(numeric_float8, NumericGetDatum(num)));
15331533
addend = rint(addend * USECS_PER_DAY);
1534-
1534+
15351535
result = result + addend;
15361536
}
15371537

@@ -1588,7 +1588,7 @@ oratimestamp_mi_number(PG_FUNCTION_ARGS)
15881588
Datum
15891589
oratimestamptz_mi_number(PG_FUNCTION_ARGS)
15901590
{
1591-
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
1591+
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
15921592
Numeric num = PG_GETARG_NUMERIC(1);
15931593
float8 mi;
15941594
Timestamp result;
@@ -1605,7 +1605,7 @@ oratimestamptz_mi_number(PG_FUNCTION_ARGS)
16051605
ereport(ERROR,
16061606
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
16071607
errmsg("timestamp out of range")));
1608-
1608+
16091609
/* Convert timestamp to date ignore fractional second */
16101610
if (tm2timestamp(tm, 0, NULL, &result) != 0)
16111611
ereport(ERROR,
@@ -1628,7 +1628,7 @@ oratimestamptz_mi_number(PG_FUNCTION_ARGS)
16281628
Datum
16291629
oratimestamptz_pl_number(PG_FUNCTION_ARGS)
16301630
{
1631-
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
1631+
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(0);
16321632
Numeric num = PG_GETARG_NUMERIC(1);
16331633
float8 addend;
16341634
Timestamp result;
@@ -1646,7 +1646,7 @@ oratimestamptz_pl_number(PG_FUNCTION_ARGS)
16461646
ereport(ERROR,
16471647
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
16481648
errmsg("timestamp out of range")));
1649-
1649+
16501650
/* Convert timestamp to date ignore time zone and fractional second */
16511651
if (tm2timestamp(tm, 0, NULL, &result) != 0)
16521652
ereport(ERROR,
@@ -1655,7 +1655,7 @@ oratimestamptz_pl_number(PG_FUNCTION_ARGS)
16551655

16561656
addend = DatumGetFloat8(DirectFunctionCall1(numeric_float8, NumericGetDatum(num)));
16571657
addend = rint(addend * USECS_PER_DAY);
1658-
1658+
16591659
result = result + addend;
16601660
}
16611661

@@ -1671,7 +1671,7 @@ Datum
16711671
number_pl_oratimestamptz(PG_FUNCTION_ARGS)
16721672
{
16731673
Numeric num = PG_GETARG_NUMERIC(0);
1674-
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(1);
1674+
TimestampTz timestamp = PG_GETARG_TIMESTAMPTZ(1);
16751675
float8 addend;
16761676
Timestamp result;
16771677
struct pg_tm tt,
@@ -1697,10 +1697,9 @@ number_pl_oratimestamptz(PG_FUNCTION_ARGS)
16971697

16981698
addend = DatumGetFloat8(DirectFunctionCall1(numeric_float8, NumericGetDatum(num)));
16991699
addend = rint(addend * USECS_PER_DAY);
1700-
1700+
17011701
result = result + addend;
17021702
}
17031703

17041704
PG_RETURN_TIMESTAMP(result);
17051705
}
1706-

0 commit comments

Comments
 (0)