From b4e88c78a4ae09e31eea07a9c617479156e3b91e Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 12 Dec 2023 15:04:43 -0800 Subject: [PATCH] fix date handling in GDAL 3.7+ --- Makefile | 1 + ogr_fdw.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 99fe305..79bc19f 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ REGRESS_OPTS = --encoding=UTF8 PG_CPPFLAGS += $(GDAL_CFLAGS) LIBS += $(GDAL_LIBS) SHLIB_LINK := $(LIBS) +SHLIB_LINK += -rpath /usr/local/lib PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) diff --git a/ogr_fdw.c b/ogr_fdw.c index cbb6cbd..233905f 100644 --- a/ogr_fdw.c +++ b/ogr_fdw.c @@ -1953,7 +1953,6 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot* slot, const OgrFdwExecS case OFTTime: case OFTDateTime: { -#if (GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,7,0)) /* * OGR date/times have a weird access method, so we use that to pull * out the raw data and turn it into a string for PgSQL's (very @@ -1975,11 +1974,13 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot* slot, const OgrFdwExecS } else { - snprintf(cstr, 256, "%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); - } +#if (GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,7,0)) + const char* tmp = OGR_F_GetFieldAsISO8601DateTime(feat, ogrfldnum, NULL); + strncpy(cstr, tmp, 256); #else - const char* cstr = OGR_F_GetFieldAsISO8601DateTime(feat, ogrfldnum, NULL); + snprintf(cstr, 256, "%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); #endif + } nulls[i] = false; values[i] = pgDatumFromCString(cstr, pgtype, pgtypmod, pginputfunc); break;