Skip to content
Commits on Source (5)
--style=allman
--indent=tab=4
--max-code-length=120
--lineend=linux
--unpad-paren
--pad-oper
--pad-header
--align-pointer=type
--align-reference=type
--break-closing-braces
--add-braces
--break-return-type
--break-after-logical
......@@ -7,10 +7,19 @@ root = true
[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true
# Test files need kid gloves
[*.source]
insert_final_newline = false
trim_trailing_whitespace = false
# C files want tab indentation
[*.{c,h}]
[*.{c,h,md}]
indent_style = tab
indent_size = 4
# Makefiles want tab indentation
[Makefile]
indent_style = tab
......@@ -14,10 +14,11 @@ addons:
- gnupg-curl
env:
- PG_VERSION=9.6 GDAL_VERSION=1.1
- PG_VERSION=9.6 GDAL_VERSION=1.11
- PG_VERSION=9.6 GDAL_VERSION=2.2.4
- PG_VERSION=9.6 GDAL_VERSION=2.3.1
- PG_VERSION=10 GDAL_VERSION=2.3.1
- PG_VERSION=10 GDAL_VERSION=2.3.3
- PG_VERSION=10 GDAL_VERSION=2.4.1
- PG_VERSION=11 GDAL_VERSION=2.4.1
before_script:
- sudo /etc/init.d/postgresql stop
......@@ -27,6 +28,9 @@ before_script:
- sudo apt-get -y --purge remove postgresql-9.4
- sudo apt-get -y --purge remove postgresql-9.5
- sudo apt-get -y --purge remove postgresql-9.6
- sudo apt-get -y --purge remove postgresql-10
- sudo apt-get -y --purge remove postgresql-11
- sudo apt-get -y --purge remove postgresql-common
- sudo apt-get -y autoremove
- sudo rm -rf /var/lib/postgresql
- apt-key adv --fetch-keys https://www.postgresql.org/media/keys/ACCC4CF8.asc
......@@ -40,8 +44,6 @@ before_script:
- if [[ $GDAL_VERSION == 2* ]]; then wget http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.xz; tar xJf gdal-$GDAL_VERSION.tar.xz; cd gdal-$GDAL_VERSION; ./configure --prefix=/usr --enable-debug --without-libtool; make -j4 >/dev/null; sudo make install >/dev/null; cd ..; gdalinfo --version; fi
script:
- make
- sudo make install
- sudo chmod 755 $HOME
- PGUSER=postgres make installcheck || (cat regression.diffs && /bin/false)
- make && sudo make install && sudo chmod 755 $HOME && (PGUSER=postgres make installcheck || (cat regression.diffs && /bin/false))
......@@ -100,41 +100,42 @@ Since we can access any OGR data source as a table, how about a public WFS serve
CREATE EXTENSION postgis;
CREATE EXTENSION ogr_fdw;
CREATE SERVER opengeo
CREATE SERVER geoserver
FOREIGN DATA WRAPPER ogr_fdw
OPTIONS (
datasource 'WFS:http://demo.opengeo.org/geoserver/wfs',
datasource 'WFS:https://demo.geo-solutions.it/geoserver/wfs',
format 'WFS' );
CREATE FOREIGN TABLE topp_states (
fid integer,
geom geometry,
fid bigint,
the_geom Geometry(MultiSurface,4326),
gml_id varchar,
state_name varchar,
state_fips varchar,
sub_region varchar,
state_abbr varchar,
land_km real,
water_km real,
persons real,
families real,
houshold real,
male real,
female real,
workers real,
drvalone real,
carpool real,
pubtrans real,
employed real,
unemploy real,
service real,
manual real,
p_male real,
p_female real,
samp_pop real )
SERVER opengeo
land_km double precision,
water_km double precision,
persons double precision,
families double precision,
houshold double precision,
male double precision,
female double precision,
workers double precision,
drvalone double precision,
carpool double precision,
pubtrans double precision,
employed double precision,
unemploy double precision,
service double precision,
manual double precision,
p_male double precision,
p_female double precision,
samp_pop double precision
) SERVER "geoserver"
OPTIONS (layer 'topp:states');
### FGDB FDW
Unzip the `Querying.zip` file from the `data` directory to get a `Querying.gdb` file, and put it somewhere public (like `/tmp`). Now run the `ogr_fdw_info` tool on it to get a table definition.
......
pgsql-ogr-fdw (1.0.7-3) UNRELEASED; urgency=medium
pgsql-ogr-fdw (1.0.8-1~exp1) experimental; urgency=medium
* Team upload.
* New upstream release.
* Bump Standards-Version to 4.3.0, no changes.
* Add lintian overrides for file-references-package-build-path.
-- Bas Couwenberg <sebastic@debian.org> Tue, 25 Dec 2018 22:56:13 +0100
-- Bas Couwenberg <sebastic@debian.org> Thu, 02 May 2019 07:04:51 +0200
pgsql-ogr-fdw (1.0.7-2) unstable; urgency=medium
......
# Cannot easily be fixed
file-references-package-build-path *
......@@ -14,7 +14,7 @@ CREATE FOREIGN TABLE pt_1 (
geom bytea,
name varchar,
age integer,
height real,
height double precision,
birthdate date )
SERVER myserver
OPTIONS ( layer 'pt_two' );
......@@ -41,6 +41,19 @@ CREATE FOREIGN TABLE pt_3 (
SELECT * FROM pt_3 ORDER BY name;
------------------------------------------------
CREATE FOREIGN TABLE poly_1 (
fid bigint,
geom bytea,
id double precision,
name varchar(5)
) SERVER myserver
OPTIONS (layer 'poly');
SELECT length(geom) FROM poly_1 WHERE name = 'Three';
------------------------------------------------
-- Laundering and explicit column naming test
......
This diff is collapsed.
......@@ -14,6 +14,7 @@
/*
* PostgreSQL
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
......@@ -37,13 +38,11 @@
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "nodes/relation.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/var.h"
#include "parser/parsetree.h"
#include "storage/ipc.h"
#include "utils/builtins.h"
......@@ -55,6 +54,13 @@
#include "utils/syscache.h"
#include "utils/timestamp.h"
#if PG_VERSION_NUM < 120000
#include "nodes/relation.h"
#include "optimizer/var.h"
#else
#include "executor/tuptable.h"
#endif
/* GDAL/OGR includes and compat */
#include "ogr_fdw_gdal.h"
#include "ogr_fdw_common.h"
......@@ -78,7 +84,8 @@ typedef enum
typedef enum {
OGR_UPDATEABLE_FALSE,
OGR_UPDATEABLE_TRUE,
OGR_UPDATEABLE_UNSET
OGR_UPDATEABLE_UNSET,
OGR_UPDATEABLE_TRY
} OgrUpdateable;
typedef struct OgrFdwColumn
......@@ -117,13 +124,13 @@ typedef struct OgrFdwTable
typedef struct OgrConnection
{
char *ds_str; /* datasource connection string */
char *dr_str; /* driver (format) name */
const char *ds_str; /* datasource connection string */
const char *dr_str; /* driver (format) name */
char *lyr_str; /* layer name */
char *config_options; /* GDAL config options */
char *open_options; /* GDAL open options */
bool ds_updateable;
bool lyr_updateable;
const char *config_options; /* GDAL config options */
const char *open_options; /* GDAL open options */
OgrUpdateable ds_updateable;
OgrUpdateable lyr_updateable;
bool lyr_utf8; /* OGR layer will return UTF8 strings */
GDALDatasetH ds; /* GDAL datasource handle */
OGRLayerH lyr; /* OGR layer handle */
......
......@@ -86,8 +86,8 @@ ogrStringLaunder(char *str)
}
static char *
ogrTypeToPgType(OGRFieldDefnH ogr_fld)
static void
ogrTypeToPgType(OGRFieldDefnH ogr_fld, char *pgtype, size_t width)
{
OGRFieldType ogr_type = OGR_Fld_GetType(ogr_fld);
switch(ogr_type)
......@@ -95,39 +95,59 @@ ogrTypeToPgType(OGRFieldDefnH ogr_fld)
case OFTInteger:
#if GDAL_VERSION_MAJOR >= 2
if( OGR_Fld_GetSubType(ogr_fld) == OFSTBoolean )
return "boolean";
{
snprintf(pgtype, width, "boolean");
break;
}
else
#endif
return "integer";
snprintf(pgtype, width, "integer");
break;
case OFTReal:
return "real";
snprintf(pgtype, width, "double precision");
break;
case OFTString:
return "varchar";
{
int ogr_fld_width = OGR_Fld_GetWidth(ogr_fld);
if (ogr_fld_width > 0)
snprintf(pgtype, width, "varchar(%d)", ogr_fld_width);
else
snprintf(pgtype, width, "varchar");
break;
}
case OFTBinary:
return "bytea";
snprintf(pgtype, width, "bytea");
break;
case OFTDate:
return "date";
snprintf(pgtype, width, "date");
break;
case OFTTime:
return "time";
snprintf(pgtype, width, "time");
break;
case OFTDateTime:
return "timestamp";
snprintf(pgtype, width, "timestamp");
break;
case OFTIntegerList:
return "integer[]";
snprintf(pgtype, width, "integer[]");
break;
case OFTRealList:
return "real[]";
snprintf(pgtype, width, "double precision[]");
break;
case OFTStringList:
return "varchar[]";
snprintf(pgtype, width, "varchar[]");
break;
#if GDAL_VERSION_MAJOR >= 2
case OFTInteger64:
return "bigint";
snprintf(pgtype, width, "bigint");
break;
#endif
default:
CPLError(CE_Failure, CPLE_AssertionFailed,
"unsupported GDAL type '%s'",
OGR_GetFieldTypeName(ogr_type));
return NULL;
return;
}
return NULL;
return;
}
static void
......@@ -226,6 +246,7 @@ ogrColumnNameToSQL (const char *ogrcolname, const char *pgtype, int launder_colu
return OGRERR_NONE;
}
OGRErr
ogrLayerToSQL (const OGRLayerH ogr_lyr, const char *fdw_server,
int launder_table_names, int launder_column_names,
......@@ -340,17 +361,17 @@ ogrLayerToSQL (const OGRLayerH ogr_lyr, const char *fdw_server,
/* Write out attribute fields */
for ( i = 0; i < OGR_FD_GetFieldCount(ogr_fd); i++ )
{
char pgtype[128];
OGRFieldDefnH ogr_fld = OGR_FD_GetFieldDefn(ogr_fd, i);
ogrColumnNameToSQL(OGR_Fld_GetNameRef(ogr_fld),
ogrTypeToPgType(ogr_fld),
launder_column_names, buf);
ogrTypeToPgType(ogr_fld, pgtype, 128);
ogrColumnNameToSQL(OGR_Fld_GetNameRef(ogr_fld), pgtype, launder_column_names, buf);
}
/*
* Add server name and layer-level options. We specify remote
* layer name as option
*/
stringbuffer_aprintf(buf, "\n) SERVER %s\nOPTIONS (", quote_identifier(fdw_server));
stringbuffer_aprintf(buf, "\n) SERVER \"%s\"\nOPTIONS (", quote_identifier(fdw_server));
stringbuffer_append(buf, "layer ");
ogrDeparseStringLiteral(buf, OGR_L_GetName(ogr_lyr));
stringbuffer_append(buf, ");\n");
......
......@@ -11,8 +11,6 @@
*/
#include "postgres.h"
/*
* Local structures
*/
......@@ -521,9 +519,15 @@ ogrDeparseExpr(Expr *node, OgrDeparseCtx *context)
/* TODO: Handle this to support the "IN" operator */
elog(NOTICE, "unsupported OGR FDW expression type, T_ScalarArrayOpExpr");
return false;
#if PG_VERSION_NUM < 120000
case T_ArrayRef:
elog(NOTICE, "unsupported OGR FDW expression type, T_ArrayRef");
return false;
#else
case T_SubscriptingRef:
elog(NOTICE, "unsupported OGR FDW expression type, T_SubscriptingRef");
return false;
#endif
case T_ArrayExpr:
elog(NOTICE, "unsupported OGR FDW expression type, T_ArrayExpr");
return false;
......
......@@ -2,6 +2,34 @@
#ifndef _OGR_FDW_GDAL_H
#define _OGR_FDW_GDAL_H 1
/*
* Quiet warnings due to double use of
* pkgconfig macros in GDAL and PgSQL
*/
#ifdef PACKAGE_VERSION
#undef PACKAGE_VERSION
#endif
#ifdef PACKAGE_TARNAME
#undef PACKAGE_TARNAME
#endif
#ifdef PACKAGE_STRING
#undef PACKAGE_STRING
#endif
#ifdef PACKAGE_NAME
#undef PACKAGE_NAME
#endif
#ifdef PACKAGE_BUGREPORT
#undef PACKAGE_BUGREPORT
#endif
#ifdef PACKAGE_VERSION
#undef PACKAGE_VERSION
#endif
/*
* OGR library API
*/
......
......@@ -10,7 +10,7 @@ CREATE FOREIGN TABLE pt_1 (
geom bytea,
name varchar,
age integer,
height real,
height double precision,
birthdate date )
SERVER myserver
OPTIONS ( layer 'pt_two' );
......@@ -46,6 +46,20 @@ SELECT * FROM pt_3 ORDER BY name;
\x0101000000c00497d1162cb93f8cbaef08a080e63f | Peter
(2 rows)
------------------------------------------------
CREATE FOREIGN TABLE poly_1 (
fid bigint,
geom bytea,
id double precision,
name varchar(5)
) SERVER myserver
OPTIONS (layer 'poly');
SELECT length(geom) FROM poly_1 WHERE name = 'Three';
length
--------
307
(1 row)
------------------------------------------------
-- Laundering and explicit column naming test
CREATE FOREIGN TABLE column_name_test (
......
......@@ -19,7 +19,7 @@ ORDER BY c.ordinal_position;
geom | bytea |
n2ame | character varying | {column_name=2ame}
age | integer |
height | real |
height | double precision |
b_rthdate | date | {column_name=b-rthdate}
(6 rows)
......@@ -46,7 +46,7 @@ ORDER BY c.ordinal_position;
column_name | data_type | attfdwoptions
-------------+-------------------+---------------
fid | bigint |
id | real |
id | double precision |
natural | character varying |
(3 rows)
......