-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ogr_fdw_version() to return fdw and GDAL versions ogr_fdw_drivers() to return array of driver names Closes #196
- Loading branch information
Showing
9 changed files
with
149 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "ogr_fdw", | ||
"abstract": "OGR foreign data wrapper", | ||
"description": "OGR FDW allows you to connect to any OGR supported data source.", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"maintainer": [ | ||
"Paul Ramsey <[email protected]>" | ||
], | ||
|
@@ -21,9 +21,9 @@ | |
}, | ||
"provides": { | ||
"ogr_fdw": { | ||
"file": "ogr_fdw--1.0.sql", | ||
"file": "ogr_fdw--1.1.sql", | ||
"docfile": "README.md", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"abstract": "OGR FDW wrapper" | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE OR REPLACE FUNCTION ogr_fdw_version() | ||
RETURNS text | ||
AS 'MODULE_PATHNAME', 'ogr_fdw_version' | ||
LANGUAGE 'c' | ||
IMMUTABLE STRICT | ||
PARALLEL SAFE; | ||
|
||
CREATE OR REPLACE FUNCTION ogr_fdw_drivers() | ||
RETURNS text[] | ||
AS 'MODULE_PATHNAME', 'ogr_fdw_drivers' | ||
LANGUAGE 'c' | ||
IMMUTABLE STRICT | ||
PARALLEL SAFE; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* ogr_fdw/ogr_fdw--1.1.sql */ | ||
|
||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
\echo Use "CREATE EXTENSION ogr_fdw" to load this file. \quit | ||
|
||
CREATE FUNCTION ogr_fdw_handler() | ||
RETURNS fdw_handler | ||
AS 'MODULE_PATHNAME' | ||
LANGUAGE 'c' STRICT; | ||
|
||
CREATE FUNCTION ogr_fdw_validator(text[], oid) | ||
RETURNS void | ||
AS 'MODULE_PATHNAME' | ||
LANGUAGE 'c' STRICT; | ||
|
||
CREATE FOREIGN DATA WRAPPER ogr_fdw | ||
HANDLER ogr_fdw_handler | ||
VALIDATOR ogr_fdw_validator; | ||
|
||
CREATE OR REPLACE FUNCTION ogr_fdw_version() | ||
RETURNS text | ||
AS 'MODULE_PATHNAME', 'ogr_fdw_version' | ||
LANGUAGE 'c' | ||
IMMUTABLE STRICT | ||
PARALLEL SAFE; | ||
|
||
CREATE OR REPLACE FUNCTION ogr_fdw_drivers() | ||
RETURNS text[] | ||
AS 'MODULE_PATHNAME', 'ogr_fdw_drivers' | ||
LANGUAGE 'c' | ||
IMMUTABLE STRICT | ||
PARALLEL SAFE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ogr_fdw extension | ||
comment = 'foreign-data wrapper for GIS data access' | ||
default_version = '1.0' | ||
default_version = '1.1' | ||
module_pathname = '$libdir/ogr_fdw' | ||
relocatable = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
#ifndef _OGR_FDW_H | ||
#define _OGR_FDW_H 1 | ||
|
||
#define OGR_FDW_RELEASE_NAME "1.1" | ||
|
||
/* | ||
* PostgreSQL | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
/*------------------------------------------------------------------------- | ||
* | ||
* ogr_fdw_func.c | ||
* Helper functions for OGR FDW | ||
* | ||
* Copyright (c) 2020, Paul Ramsey <[email protected]> | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "ogr_fdw.h" | ||
#include "ogr_fdw_gdal.h" | ||
|
||
#include <postgres.h> | ||
#include <fmgr.h> | ||
#include <funcapi.h> | ||
#include <catalog/pg_type_d.h> | ||
#include <utils/array.h> | ||
#include <utils/builtins.h> | ||
|
||
|
||
/** | ||
*/ | ||
Datum ogr_fdw_drivers(PG_FUNCTION_ARGS); | ||
PG_FUNCTION_INFO_V1(ogr_fdw_drivers); | ||
Datum ogr_fdw_drivers(PG_FUNCTION_ARGS) | ||
{ | ||
|
||
/* Array building */ | ||
size_t arr_nelems = 0; | ||
Datum *arr_elems; | ||
ArrayType *arr; | ||
Oid elem_type = TEXTOID; | ||
int16 elem_len; | ||
bool elem_byval; | ||
char elem_align; | ||
int num_drivers; | ||
|
||
if (GDALGetDriverCount() <= 0) | ||
GDALAllRegister(); | ||
|
||
num_drivers = GDALGetDriverCount(); | ||
if (num_drivers < 1) | ||
PG_RETURN_NULL(); | ||
|
||
arr_elems = palloc0(num_drivers * sizeof(Datum)); | ||
get_typlenbyvalalign(elem_type, &elem_len, &elem_byval, &elem_align); | ||
|
||
for (int i = 0; i < num_drivers; i++) { | ||
GDALDriverH hDriver = GDALGetDriver(i); | ||
if (GDALGetMetadataItem(hDriver, GDAL_DCAP_VECTOR, NULL) != NULL) { | ||
const char *strName = OGR_Dr_GetName(hDriver); | ||
text *txtName = cstring_to_text(strName); | ||
arr_elems[arr_nelems++] = PointerGetDatum(txtName); | ||
} | ||
} | ||
|
||
arr = construct_array(arr_elems, arr_nelems, elem_type, elem_len, elem_byval, elem_align); | ||
PG_RETURN_ARRAYTYPE_P(arr); | ||
} | ||
|
||
/** | ||
*/ | ||
Datum ogr_fdw_version(PG_FUNCTION_ARGS); | ||
PG_FUNCTION_INFO_V1(ogr_fdw_version); | ||
Datum ogr_fdw_version(PG_FUNCTION_ARGS) | ||
{ | ||
const char *gdal_ver = GDAL_RELEASE_NAME; | ||
const char *ogr_fdw_ver = OGR_FDW_RELEASE_NAME; | ||
char ver_str[256]; | ||
snprintf(ver_str, sizeof(ver_str), "OGR_FDW=\"%s\" GDAL=\"%s\"", ogr_fdw_ver, gdal_ver); | ||
text* ver_txt = cstring_to_text(ver_str); | ||
PG_RETURN_TEXT_P(ver_txt); | ||
} | ||
|
||
|