Skip to content

Commit

Permalink
fix date handling in GDAL 3.7+
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Dec 12, 2023
1 parent bab22af commit b4e88c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions ogr_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit b4e88c7

Please sign in to comment.