Skip to content

Commit

Permalink
support for pg16
Browse files Browse the repository at this point in the history
  • Loading branch information
binaek authored and kaidaguerre committed Feb 1, 2024
1 parent 553cd9b commit 4082c57
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ install: build
if test -d ~/.steampipe/db/14.2.0; then \
cp ./build-$(PLATFORM)/steampipe_postgres_fdw--1.0.sql $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/share/postgresql/extension/; \
cp ./build-$(PLATFORM)/steampipe_postgres_fdw.control $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/share/postgresql/extension/; \
fi

if test -f ./build-$(PLATFORM)/steampipe_postgres_fdw.so; then \
cp ./build-$(PLATFORM)/steampipe_postgres_fdw.so $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/lib/postgresql/; \
fi
if test -f ./build-$(PLATFORM)/steampipe_postgres_fdw.dylib; then \
cp ./build-$(PLATFORM)/steampipe_postgres_fdw.dylib $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/lib/postgresql/; \
fi

# build standalone
standalone: validate_plugin prebuild.go
Expand Down
8 changes: 7 additions & 1 deletion fdw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ ifeq ($(shell uname -s),Darwin)
export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup
endif

# if we are building for pg16, we need to use the pg10 build tags
ifeq ($(shell $(PG_CONFIG) --version | cut -d' ' -f2 | cut -d'.' -f1), 14)
BUILD_TAGS := $(BUILD_TAGS),pg14
endif

go: ../fdw.go
@echo $(BUILD_TAGS)
# we are building with the net package from go
# this has the caveat that, since we are not binding to lresolv, DNS resolution may
# have some subtle differences from system DNS resolution
CGO_ENABLED=1 go build -v -x -o steampipe_postgres_fdw.a -tags "$(BUILD_TAGS)" -buildmode=c-archive ../*.go
CGO_ENABLED=1 go build -v -o steampipe_postgres_fdw.a -tags "$(BUILD_TAGS)" -buildmode=c-archive ../*.go

inst:
mkdir -p ../build-${PLATFORM}
Expand Down
11 changes: 9 additions & 2 deletions fdw/fdw_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ static inline void *fdw_getStruct(HeapTuple tuple) { return GETSTRUCT(tuple); }

static inline NodeTag fdw_nodeTag(Expr *node) { return nodeTag(node); }

static inline Datum fdw_boolGetDatum(bool b) { PG_RETURN_BOOL(b); }

#if PG_VERSION_NUM >= 160000
static inline Datum fdw_cStringGetDatum(const char *str) { PG_RETURN_DATUM(CStringGetTextDatum((char *)str)); }
static inline Datum fdw_jsonbGetDatum(const char *str) { PG_RETURN_JSONB_P((char *)DirectFunctionCall1(jsonb_in, CStringGetDatum(str))); }
#else
static inline Datum fdw_cStringGetDatum(const char *str) { PG_RETURN_TEXT_P(CStringGetTextDatum(str)); }
static inline Datum fdw_jsonbGetDatum(const char *str) { PG_RETURN_JSONB_P(DirectFunctionCall1(jsonb_in, CStringGetDatum(str))); }
#endif

static inline Datum fdw_boolGetDatum(bool b) { PG_RETURN_BOOL(b); }
static inline Datum fdw_numericGetDatum(int64_t num) { PG_RETURN_INT64(Int64GetDatum(num)); }
static inline Datum fdw_floatGetDatum(double num) { PG_RETURN_FLOAT8(Float8GetDatum(num)); }
static inline Datum fdw_pointerGetDatum(void *num) { PG_RETURN_DATUM(PointerGetDatum(num)); }
Expand All @@ -70,6 +70,13 @@ static inline char *valueString(String *v) { return strVal(v); }
#else
static inline char *valueString(Value *v) { return (((Value *)(v))->val.str); }
#endif

#if PG_VERSION_NUM >= 160000
static inline void fdw_appendBinaryStringInfo(StringInfo str, const char *data, int datalen) { appendBinaryStringInfo(str,(void *)data,datalen); }
#else
static inline void fdw_appendBinaryStringInfo(StringInfo str, const char *data, int datalen) { appendBinaryStringInfo(str,data,datalen); }
#endif

static inline char **incStringPointer(char **ptr) { return ++ptr; }
static inline unsigned char *incUcharPointer(unsigned char *ptr) { return ++ptr; }
static inline unsigned char *ipAddr(inet *i) { return ip_addr(i); }
Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func valToBuffer(val interface{}, oid C.Oid, buffer C.StringInfo) (err error) {
}

C.resetStringInfo(buffer)
C.appendBinaryStringInfo(buffer, unsafe.Pointer(C.CString(valueString)), C.int(len(valueString)))
C.fdw_appendBinaryStringInfo(buffer, C.CString(valueString), C.int(len(valueString)))
return
}

Expand Down

0 comments on commit 4082c57

Please sign in to comment.