From 2c635c6214753aab952293ebebe77db0fed00205 Mon Sep 17 00:00:00 2001
From: Pavel Stehule <pavel.stehule@gmail.com>
Date: Sun, 24 Aug 2014 21:54:44 +0200
Subject: [PATCH] bugfix: to_date() crashes on 32 bit with certain date
formats #15
fix messy conversions between timestamp and datum
---
convert.c | 4 ++--
datefce.c | 12 +++++++-----
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/convert.c b/convert.c
index f7520c8..83bd020 100644
--- a/convert.c
+++ b/convert.c
@@ -125,14 +125,14 @@ orafce_to_char_numeric(PG_FUNCTION_ARGS)
Datum
orafce_to_char_timestamp(PG_FUNCTION_ARGS)
{
- Timestamp date_txt = PG_GETARG_TIMESTAMP(0);
+ Timestamp ts = PG_GETARG_TIMESTAMP(0);
text *result = NULL;
if(nls_date_format && strlen(nls_date_format))
{
/* it will return the DATE in nls_date_format*/
result = DatumGetTextP(DirectFunctionCall2(timestamp_to_char,
- CStringGetDatum(date_txt),
+ TimestampGetDatum(ts),
CStringGetDatum(cstring_to_text(nls_date_format))));
}
diff --git a/datefce.c b/datefce.c
index e228a12..1480fe0 100644
--- a/datefce.c
+++ b/datefce.c
@@ -590,15 +590,17 @@ _ora_date_round(DateADT day, int f)
Datum ora_to_date(PG_FUNCTION_ARGS)
{
text *date_txt = PG_GETARG_TEXT_P(0);
- Timestamp newDate, result;
+ Timestamp result;
if(nls_date_format && strlen(nls_date_format))
{
+ Datum newDate;
+
/* it will return timestamp at GMT */
- newDate = DatumGetTimestamp(DirectFunctionCall2(to_timestamp,
- CStringGetDatum(date_txt),
- CStringGetDatum(
- cstring_to_text(nls_date_format))));
+ newDate = DirectFunctionCall2(to_timestamp,
+ CStringGetDatum(date_txt),
+ CStringGetDatum(cstring_to_text(nls_date_format)));
+
/* convert to local timestamp */
result = DatumGetTimestamp(DirectFunctionCall1(timestamptz_timestamp, newDate));
}
--
2.1.0