This is an automated email from the git hooks/post-receive script.

myon pushed a commit to branch master
in repository pgsql-ogr-fdw.

commit faa601340d9f65260beece2336d9d3850dd9e5ef
Author: Christoph Berg <m...@debian.org>
Date:   Sat Dec 9 20:14:08 2017 +0100

    New upstream version 1.0.5
---
 Makefile  |  11 ++++--
 README.md | 129 ++++++++++++++++++++++++++++++++++++--------------------------
 ogr_fdw.c | 123 ++++++++++++++++++++++++++++++++++++-----------------------
 ogr_fdw.h |  27 ++++++-------
 4 files changed, 174 insertions(+), 116 deletions(-)

diff --git a/Makefile b/Makefile
index 86f89e3..d0bbb46 100644
--- a/Makefile
+++ b/Makefile
@@ -20,12 +20,17 @@ PG_CPPFLAGS += $(GDAL_CFLAGS)
 LIBS += $(GDAL_LIBS)
 SHLIB_LINK := $(LIBS)
 
-# order matters, file first, import last
-REGRESS = file pgsql import
-
 PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 
+PG_VERSION_NUM = $(shell awk '/PG_VERSION_NUM/ { print $$3 }' $(shell 
$(PG_CONFIG) --includedir-server)/pg_config.h)
+HAS_IMPORT_SCHEMA = $(shell [ $(PG_VERSION_NUM) -ge 90500 ] && echo yes)
+
+# order matters, file first, import last
+REGRESS = file pgsql
+ifeq ($(HAS_IMPORT_SCHEMA),yes)
+REGRESS += import
+endif
 
 ###############################################################
 # Build the utility program after PGXS to override the
diff --git a/README.md b/README.md
index 8be2276..9001893 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Travis: [![Build 
Status](https://secure.travis-ci.org/pramsey/pgsql-ogr-fdw.png)
 
 ## Motivation
 
-OGR is the vector half of the [GDAL](http://www.gdal.org/) spatial data access 
library. It allows access to a [large number of GIS data 
formats](http://www.gdal.org/ogr_formats.html) using a [simple C 
API](http://www.gdal.org/ogr__api_8h.html) for data reading and writing. Since 
OGR exposes a simple table structure and PostgreSQL [foreign data 
wrappers](https://wiki.postgresql.org/wiki/Foreign_data_wrappers) allow access 
to table structures, the fit seems pretty perfect. 
+OGR is the vector half of the [GDAL](http://www.gdal.org/) spatial data access 
library. It allows access to a [large number of GIS data 
formats](http://www.gdal.org/ogr_formats.html) using a [simple C 
API](http://www.gdal.org/ogr__api_8h.html) for data reading and writing. Since 
OGR exposes a simple table structure and PostgreSQL [foreign data 
wrappers](https://wiki.postgresql.org/wiki/Foreign_data_wrappers) allow access 
to table structures, the fit seems pretty perfect.
 
 ## Limitations
 
@@ -30,7 +30,7 @@ First install the `postgis` and `ogr_fdw` extensions in your 
database.
     CREATE EXTENSION postgis;
     CREATE EXTENSION ogr_fdw;
 
-For a test data set, copy the `pt_two` example shape file from the `data` 
directory to a location where the PostgreSQL server can read it (like 
`/tmp/test/` for example). 
+For a test data set, copy the `pt_two` example shape file from the `data` 
directory to a location where the PostgreSQL server can read it (like 
`/tmp/test/` for example).
 
 Use the `ogr_fdw_info` tool to read an OGR data source and output a server and 
table definition for a particular layer. (You can write these manually, but the 
utility makes it a little more foolproof.)
 
@@ -44,13 +44,13 @@ Use the `ogr_fdw_info` tool to read an OGR data source and 
output a server and t
 
 
     > ogr_fdw_info -s /tmp/test
-    
+
     Layers:
       pt_two
 
-    
+
     > ogr_fdw_info -s /tmp/test -l pt_two
-    
+
     CREATE SERVER myserver
       FOREIGN DATA WRAPPER ogr_fdw
       OPTIONS (
@@ -66,18 +66,18 @@ Use the `ogr_fdw_info` tool to read an OGR data source and 
output a server and t
       birthdate date )
       SERVER myserver
       OPTIONS (layer 'pt_two');
-    
+
 Copy the `CREATE SERVER` and `CREATE FOREIGN SERVER` SQL commands into the 
database and you'll have your foreign table definition.
 
                  Foreign table "public.pt_two"
-      Column  |       Type        | Modifiers | FDW Options 
+      Column  |       Type        | Modifiers | FDW Options
     ----------+-------------------+-----------+-------------
-     fid      | integer           |           | 
-     geom     | geometry          |           | 
-     name     | character varying |           | 
-     age      | integer           |           | 
-     height   | real              |           | 
-     birthday | date              |           | 
+     fid      | integer           |           |
+     geom     | geometry          |           |
+     name     | character varying |           |
+     age      | integer           |           |
+     height   | real              |           |
+     birthday | date              |           |
     Server: tmp_shape
     FDW Options: (layer 'pt_two')
 
@@ -85,7 +85,7 @@ And you can query the table directly, even though it's really 
just a shape file.
 
     > SELECT * FROM pt_two;
 
-     fid |                    geom                    | name  | age | height | 
 birthday  
+     fid |                    geom                    | name  | age | height | 
 birthday
     
-----+--------------------------------------------+-------+-----+--------+------------
        0 | 0101000000C00497D1162CB93F8CBAEF08A080E63F | Peter |  45 |    5.6 | 
1965-04-12
        1 | 010100000054E943ACD697E2BFC0895EE54A46CF3F | Paul  |  33 |   5.84 | 
1971-03-25
@@ -167,19 +167,19 @@ Query away!
 
 Wraparound action! Handy for testing. Connect your database back to your 
database and watch the fur fly.
 
-    CREATE TABLE typetest ( 
+    CREATE TABLE typetest (
       fid serial primary key,
       geom geometry(Point, 4326),
-      num real, 
-      name varchar, 
-      clock time, 
-      calendar date, 
-      tstmp timestamp 
+      num real,
+      name varchar,
+      clock time,
+      calendar date,
+      tstmp timestamp
     );
 
-    INSERT INTO typetest 
+    INSERT INTO typetest
       VALUES (1, 'SRID=4326;POINT(-126 46)', 4.5, 'Paul', '09:34:23', 'June 1, 
2013', '12:34:56 December 14, 1823');
-    INSERT INTO typetest 
+    INSERT INTO typetest
       VALUES (2, 'SRID=4326;POINT(-126 46)', 4.8, 'Peter', '14:34:53', 'July 
12, 2011', '1:34:12 December 24, 1923');
 
     CREATE SERVER wraparound
@@ -200,21 +200,21 @@ Wraparound action! Handy for testing. Connect your 
database back to your databas
       OPTIONS (layer 'typetest');
 
     SELECT * FROM typetest_fdw;
-    
+
 ## Advanced Features
 
 ### Writeable FDW Tables
 
-If the OGR driver you are using supports it, you can insert/update/delete 
records from your FDW tables. 
+If the OGR driver you are using supports it, you can insert/update/delete 
records from your FDW tables.
 
 For file-backed drivers, the user under which `postgres` runs will need 
read/write access to the file being altered. For database-backed drivers, your 
connection needs a user with read/write permissions to the database.
 
 By default, servers and tables are updateable if the OGR driver supports it, 
but you can turn off updateability at a server or table level using the 
`updateable` option:
 
-    ALTER SERVER myserver 
+    ALTER SERVER myserver
       OPTIONS (ADD updatable 'false');
 
-    ALTER FOREIGN TABLE mytable 
+    ALTER FOREIGN TABLE mytable
       OPTIONS (ADD updatable 'false');
 
 Writeable tables only work if you have included a `fid` column in your table 
definition. By default, tables imported by `IMPORT FOREIGN SCHEMA` or using the 
example SQL code from `ogr_fdw_info` include a `fid` column.
@@ -225,21 +225,21 @@ You can create an FDW table with any subset of columns 
from the OGR source you l
 
     CREATE FOREIGN TABLE typetest_fdw_partial (
       clock time,
-      name varchar 
+      name varchar
       )
       SERVER wraparound
       OPTIONS (layer 'typetest');
-      
+
 You can also explicitly map remote column names to different local names using 
the `column_name` option:
 
     CREATE FOREIGN TABLE typetest_fdw_mapped (
       fid bigint,
       supertime time OPTIONS (column_name 'clock'),
-      thebestnamething varchar OPTIONS (column_name 'name') 
+      thebestnamething varchar OPTIONS (column_name 'name')
       )
       SERVER wraparound
       OPTIONS (layer 'typetest');
-      
+
 
 ### Automatic Foreign Table Creation
 
@@ -252,9 +252,9 @@ You can use the PostgreSQL `IMPORT FOREIGN SCHEMA` command 
to [import table defi
 If you want to import all tables in the OGR data source use the special schema 
called "ogr_all".
 
        CREATE SCHEMA fgdball;
-    
-       IMPORT FOREIGN SCHEMA ogr_all 
-               FROM SERVER fgdbtest 
+
+       IMPORT FOREIGN SCHEMA ogr_all
+               FROM SERVER fgdbtest
         INTO fgdball;
 
 #### Import a Subset of Tables
@@ -264,9 +264,9 @@ Not all OGR data sources have a concept of schema, so we 
use the remote schema s
 For example, the following will only import tables that start with *CitiesIn*. 
As long as you quote, you can handle true schemaed databases such as SQL Server 
or PostgreSQL by using something like *"dbo."*
 
        CREATE SCHEMA fgdbcityinf;
-    
+
        IMPORT FOREIGN SCHEMA "CitiesIn"
-               FROM SERVER fgdbtest 
+               FROM SERVER fgdbtest
         INTO fgdbcityinf;
 
 You can also use PostgreSQL clauses `LIMIT TO` and `EXCEPT` to restrict the 
tables you are importing.
@@ -274,31 +274,31 @@ You can also use PostgreSQL clauses `LIMIT TO` and 
`EXCEPT` to restrict the tabl
        CREATE SCHEMA fgdbcitysub;
 
        -- import only layer called Cities
-       IMPORT FOREIGN SCHEMA ogr_all 
-        LIMIT TO(cities) 
-               FROM server fgdbtest 
+       IMPORT FOREIGN SCHEMA ogr_all
+        LIMIT TO(cities)
+               FROM server fgdbtest
         INTO fgdbcitysub ;
-               
+
        -- import only layers not called Cities or Countries
-       IMPORT FOREIGN SCHEMA ogr_all 
+       IMPORT FOREIGN SCHEMA ogr_all
         EXCEPT (cities, countries)
-               FROM server fgdbtest 
+               FROM server fgdbtest
         INTO fgdbcitysub;
-               
+
        -- With table laundering turned off, need to use exact layer names
        DROP SCHEMA IF EXISTS fgdbcitysub CASCADE;
-       
+
     -- import with un-laundered table name
-       IMPORT FOREIGN SCHEMA ogr_all 
-       LIMIT TO("Cities") 
-               FROM server fgdbtest 
-        INTO fgdbcitysub 
+       IMPORT FOREIGN SCHEMA ogr_all
+       LIMIT TO("Cities")
+               FROM server fgdbtest
+        INTO fgdbcitysub
         OPTIONS (launder_table_names 'false') ;
 
 
 #### Mixed Case and Special Characters
 
-In general, PostgreSQL prefers table names with [simple numbers and 
letters](http://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS),
 no punctuation or special characters. 
+In general, PostgreSQL prefers table names with [simple numbers and 
letters](http://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS),
 no punctuation or special characters.
 
 By default, when `IMPORT FOREIGN SCHEMA` is run on an OGR foreign data server, 
the table names and column names are "laundered" -- all upper case is converted 
to lowercase and special characters such as spaces and punctuation are replaced 
with "_".
 
@@ -307,15 +307,15 @@ Laundering is not desirable in all cases. You can 
override this behavior with tw
 To preserve casing and other funky characters in both column names and table 
names, do the following:
 
        CREATE SCHEMA fgdbcitypreserve;
-    
+
        IMPORT FOREIGN SCHEMA ogr_all
-               FROM SERVER fgdbtest 
-        INTO fgdbpreserve 
+               FROM SERVER fgdbtest
+        INTO fgdbpreserve
                OPTIONS (
-            launder_table_names 'false', 
+            launder_table_names 'false',
             launder_column_names 'false'
             ) ;
-               
+
 
 ###  GDAL Options
 
@@ -330,6 +330,8 @@ Since many Shapefiles are encoded using LATIN1, and most 
PostgreSQL databases ar
         format 'ESRI Shapefile',
         config_options 'SHAPE_ENCODING=LATIN1' );
 
+Multiple config options can be passed at one time by supplying a 
**space-separated** list of options.
+
 If you are using GDAL 2.0 or higher, you can also pass "open options" to your 
OGR foreign data wrapper, using the `open_options` parameter. In GDAL 2.0, the 
global `SHAPE_ENCODING` option has been superceded by a driver-specific 
`ENCODING` option, which can be called like this:
 
     CREATE SERVER myserver_latin1
@@ -339,4 +341,25 @@ If you are using GDAL 2.0 or higher, you can also pass 
"open options" to your OG
         format 'ESRI Shapefile',
         open_options 'ENCODING=LATIN1' );
 
+### GDAL Debugging
+
+If you are getting odd behavior and you want to see what GDAL is doing behind 
the scenes, enable debug logging in your server:
+
+    CREATE SERVER myserver_latin1
+      FOREIGN DATA WRAPPER ogr_fdw
+      OPTIONS (
+        datasource '/tmp/test',
+        format 'ESRI Shapefile',
+        config_options 'SHAPE_ENCODING=LATIN1 CPL_DEBUG=ON'
+        );
+
+GDAL-level messages will be logged at the PostgreSQL **DEBUG2** level, so to 
see them when running a query, alter your `client_min_messages` setting.
+
+    SET client_min_messages = debug2;
+
+Once you've figured out your issue, don't forget to remove the `CPL_DEBUG` 
option from your server definition, and set your messages back to **NOTICE** 
level.
+
+    SET client_min_messages = notice;
+    ALTER SERVER myserver_latin1 OPTIONS (SET config_options 
'SHAPE_ENCODING=LATIN1');
+    
 
diff --git a/ogr_fdw.c b/ogr_fdw.c
index beb4ea0..ea6bf3f 100644
--- a/ogr_fdw.c
+++ b/ogr_fdw.c
@@ -164,34 +164,35 @@ static void ogrReadColumnData(OgrFdwState *state);
 /* Global to hold GEOMETRYOID */
 Oid GEOMETRYOID = InvalidOid;
 
-
+#if GDAL_VERSION_MAJOR >= 2 && GDAL_VERSION_MINOR >= 1
+static void
+ogrErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
+{
+       switch (eErrClass)
+       {
+               case CE_None:
+                       elog(NOTICE, "[%d] %s", err_no, msg);
+                       break;
+               case CE_Debug:
+                       elog(DEBUG2, "[%d] %s", err_no, msg);
+                       break;
+               case CE_Warning:
+                       elog(WARNING, "[%d] %s", err_no, msg);
+                       break;
+               case CE_Failure:
+               case CE_Fatal:
+               default:
+                       elog(ERROR, "[%d] %s", err_no, msg);
+                       break;
+       }
+       return;
+}
+#endif
 
 void
 _PG_init(void)
 {
-       // DefineCustomIntVariable("mysql_fdw.wait_timeout",
-       //                                              "Server-side 
wait_timeout",
-       //                                              "Set the maximum 
wait_timeout"
-       //                                              "use to set the MySQL 
session timeout",
-       //                                              &wait_timeout,
-       //                                              WAIT_TIMEOUT,
-       //                                              0,
-       //                                              INT_MAX,
-       //                                              PGC_USERSET,
-       //                                              0,
-       //                                              NULL,
-       //                                              NULL,
-       //                                              NULL);
-
-       /*
-        * We assume PostGIS is installed in 'public' and if we cannot
-        * find it, we'll treat all geometry from OGR as bytea.
-        */
-       // const char *typname = "geometry";
-       // Oid namesp = LookupExplicitNamespace("public", false);
-       // Oid typoid = GetSysCacheOid2(TYPENAMENSP, CStringGetDatum(typname), 
ObjectIdGetDatum(namesp));
        Oid typoid = TypenameGetTypid("geometry");
-
        if (OidIsValid(typoid) && get_typisdefined(typoid))
        {
                GEOMETRYOID = typoid;
@@ -202,6 +203,12 @@ _PG_init(void)
        }
 
        on_proc_exit(&ogr_fdw_exit, PointerGetDatum(NULL));
+
+#if GDAL_VERSION_MAJOR >= 2 && GDAL_VERSION_MINOR >= 1
+       /* Hook up the GDAL error handlers to PgSQL elog() */
+       CPLSetErrorHandler(ogrErrorHandler);
+       CPLSetCurrentErrorHandlerCatchDebug(true);
+#endif
 }
 
 /*
@@ -522,6 +529,7 @@ ogrGetConnectionFromTable(Oid foreigntableid, bool 
updateable)
                                : errhint("Does the layer exist?")
                                ));
        }
+       ogr.lyr_utf8 = OGR_L_TestCapability(ogr.lyr, OLCStringsAsUTF8);
 
        return ogr;
 }
@@ -1091,7 +1099,7 @@ ogrReadColumnData(OgrFdwState *state)
        /* Get OGR metadata ready */
        dfn = OGR_L_GetLayerDefn(state->ogr.lyr);
        ogr_ncols = OGR_FD_GetFieldCount(dfn);
-#if GDAL_VERSION_MAJOR >= 2 || GDAL_VERSION_MINOR >= 11
+#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
        ogr_geom_count = OGR_FD_GetGeomFieldCount(dfn);
 #else
        ogr_geom_count = ( OGR_FD_GetGeomType(dfn) != wkbNone ) ? 1 : 0;
@@ -1125,7 +1133,11 @@ ogrReadColumnData(OgrFdwState *state)
                OgrFieldEntry *found_entry;
                OgrFieldEntry entry;
 
+#if PG_VERSION_NUM >= 110000
+               Form_pg_attribute att_tuple = &tupdesc->attrs[i];
+#else
                Form_pg_attribute att_tuple = tupdesc->attrs[i];
+#endif
                OgrFdwColumn col = tbl->cols[i];
                col.pgattnum = att_tuple->attnum;
                col.pgtype = att_tuple->atttypid;
@@ -1339,19 +1351,9 @@ pgDatumFromCString(const char *cstr, Oid pgtype, int 
pgtypmod, Oid pginputfunc)
        Datum value;
        Datum cdata = CStringGetDatum(cstr);
 
-       /* pgtypmod will be -1 for types w/o typmod  */
-       // if ( pgtypmod >= 0 )
-       // {
-               /* These functions require a type modifier */
-               value = OidFunctionCall3(pginputfunc, cdata,
-                       ObjectIdGetDatum(InvalidOid),
-                       Int32GetDatum(pgtypmod));
-       // }
-       // else
-       // {
-       //      /* These functions don't */
-       //      value = OidFunctionCall1(pginputfunc, cdata);
-       // }
+       value = OidFunctionCall3(pginputfunc, cdata,
+               ObjectIdGetDatum(InvalidOid),
+               Int32GetDatum(pgtypmod));
 
        return value;
 }
@@ -1440,7 +1442,7 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot 
*slot, const OgrFdwExecS
                        unsigned char *wkb;
                        OGRErr err;
 
-#if GDAL_VERSION_MAJOR >= 2 || GDAL_VERSION_MINOR >= 11
+#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
                        OGRGeometryH geom = OGR_F_GetGeomFieldRef(feat, 
ogrfldnum);
 #else
                        OGRGeometryH geom = OGR_F_GetGeometryRef(feat);
@@ -1544,7 +1546,7 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot 
*slot, const OgrFdwExecS
                }
                else if ( ogrvariant == OGR_FIELD )
                {
-#if (GDAL_VERSION_MAJOR > 2 || (GDAL_VERSION_MAJOR >= 2 && GDAL_VERSION_MINOR 
>= 2))
+#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
                        int field_not_null = OGR_F_IsFieldSet(feat, ogrfldnum) 
&& ! OGR_F_IsFieldNull(feat, ogrfldnum);
 #else
                        int field_not_null = OGR_F_IsFieldSet(feat, ogrfldnum);
@@ -1587,9 +1589,20 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot 
*slot, const OgrFdwExecS
                                                 */
                                                const char *cstr_in = 
OGR_F_GetFieldAsString(feat, ogrfldnum);
                                                size_t cstr_len = cstr_in ? 
strlen(cstr_in) : 0;
-                                               char *cstr_decoded = 
pg_any_to_server(cstr_in, cstr_len, PG_UTF8);
-                                               nulls[i] = false;
-                                               values[i] = 
pgDatumFromCString(cstr_decoded, pgtype, pgtypmod, pginputfunc);
+                                               if ( cstr_in && cstr_len > 0 )
+                                               {
+                                                       char *cstr_decoded;
+                                                       
if(execstate->ogr.lyr_utf8)
+                                                               cstr_decoded = 
pg_any_to_server(cstr_in, cstr_len, PG_UTF8);
+                                                       else
+                                                               cstr_decoded = 
pstrdup(cstr_in);
+                                                       nulls[i] = false;
+                                                       values[i] = 
pgDatumFromCString(cstr_decoded, pgtype, pgtypmod, pginputfunc);
+                                               }
+                                               else
+                                               {
+                                                       ogrNullSlot(values, 
nulls, i);
+                                               }
                                                break;
                                        }
                                        case OFTDate:
@@ -1784,7 +1797,7 @@ ogrSlotToFeature(const TupleTableSlot *slot, OGRFeatureH 
feat, const OgrFdwTable
                        OGRErr err;
                        if ( nulls[i] )
                        {
-#if GDAL_VERSION_MAJOR >= 2 || GDAL_VERSION_MINOR >= 11
+#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
                                err = OGR_F_SetGeomFieldDirectly(feat, 
ogrfldnum, NULL);
 #else
                                err = OGR_F_SetGeometryDirectly(feat, NULL);
@@ -1805,7 +1818,7 @@ ogrSlotToFeature(const TupleTableSlot *slot, OGRFeatureH 
feat, const OgrFdwTable
                                if ( err != OGRERR_NONE )
                                        return err;
 
-#if GDAL_VERSION_MAJOR >= 2 || GDAL_VERSION_MINOR >= 11
+#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
                                err = OGR_F_SetGeomFieldDirectly(feat, 
ogrfldnum, geom);
 #else
                                err = OGR_F_SetGeometryDirectly(feat, geom);
@@ -2008,7 +2021,8 @@ ogrIterateForeignScan(ForeignScanState *node)
        }
 
        /* If we rectreive a feature from OGR, copy it over into the slot */
-       if ( (feat = OGR_L_GetNextFeature(execstate->ogr.lyr)) )
+       feat = OGR_L_GetNextFeature(execstate->ogr.lyr);
+       if ( feat )
        {
                /* convert result to arrays of values and null indicators */
                if ( OGRERR_NONE != ogrFeatureToSlot(feat, slot, execstate) )
@@ -2090,8 +2104,13 @@ static int ogrGetFidColumn(const TupleDesc td)
        int i;
        for ( i = 0; i < td->natts; i++ )
        {
+#if PG_VERSION_NUM >= 110000
+               NameData attname = td->attrs[i].attname;
+               Oid atttypeid = td->attrs[i].atttypid;
+#else
                NameData attname = td->attrs[i]->attname;
                Oid atttypeid = td->attrs[i]->atttypid;
+#endif
                if ( (atttypeid == INT4OID || atttypeid == INT8OID) &&
                     strcaseeq("fid", attname.data) )
                {
@@ -2126,8 +2145,11 @@ static void ogrAddForeignUpdateTargets (Query *parsetree,
        if ( fid_column < 0 )
                elog(ERROR,"table '%s' does not have a 'fid' column", 
RelationGetRelationName(target_relation));
 
+#if PG_VERSION_NUM >= 110000
+       att = &tupdesc->attrs[fid_column];
+#else
        att = tupdesc->attrs[fid_column];
-
+#endif
        /* Make a Var representing the desired value */
        var = makeVar(parsetree->resultRelation,
                        att->attnum,
@@ -2209,8 +2231,11 @@ static TupleTableSlot *ogrExecForeignUpdate (EState 
*estate,
 
        /* What is the value of the FID for this record? */
        fid_datum = slot->tts_values[fid_column];
+#if PG_VERSION_NUM >= 110000
+       fid_type = td->attrs[fid_column].atttypid;
+#else
        fid_type = td->attrs[fid_column]->atttypid;
-
+#endif
        if ( fid_type == INT8OID )
                fid = DatumGetInt64(fid_datum);
        else
@@ -2408,7 +2433,11 @@ static TupleTableSlot *ogrExecForeignDelete (EState 
*estate,
 
        /* What is the value of the FID for this record? */
        fid_datum = planSlot->tts_values[fid_column];
+#if PG_VERSION_NUM >= 110000
+       fid_type = td->attrs[fid_column].atttypid;
+#else
        fid_type = td->attrs[fid_column]->atttypid;
+#endif
 
        if ( fid_type == INT8OID )
                fid = DatumGetInt64(fid_datum);
diff --git a/ogr_fdw.h b/ogr_fdw.h
index b24a676..d6c11ba 100644
--- a/ogr_fdw.h
+++ b/ogr_fdw.h
@@ -67,7 +67,7 @@
 /* hexwkb is not. */
 #define OGR_FDW_HEXWKB TRUE
 
-typedef enum 
+typedef enum
 {
        OGR_UNMATCHED,
        OGR_GEOMETRY,
@@ -89,19 +89,19 @@ typedef struct OgrFdwColumn
        char *pgname;            /* PostgreSQL column name */
        Oid pgtype;              /* PostgreSQL data type */
        int pgtypmod;            /* PostgreSQL type modifier */
-       
+
        /* For reading */
        Oid pginputfunc;         /* PostgreSQL function to convert cstring to 
type */
        Oid pginputioparam;
        Oid pgrecvfunc;          /* PostgreSQL function to convert binary to 
type */
        Oid pgrecvioparam;
-       
+
        /* For writing */
        Oid pgoutputfunc;        /* PostgreSQL function to convert type to 
cstring */
        bool pgoutputvarlena;
        Oid pgsendfunc;        /* PostgreSQL function to convert type to binary 
*/
        bool pgsendvarlena;
-       
+
        /* OGR metadata */
        OgrColumnVariant ogrvariant;
        int ogrfldnum;
@@ -124,11 +124,12 @@ typedef struct OgrConnection
        char *open_options;   /* GDAL open options */
        bool ds_updateable;
        bool lyr_updateable;
+       bool lyr_utf8;        /* OGR layer will return UTF8 strings */
        GDALDatasetH ds;      /* GDAL datasource handle */
        OGRLayerH lyr;        /* OGR layer handle */
 } OgrConnection;
 
-typedef enum 
+typedef enum
 {
        OGR_PLAN_STATE,
        OGR_EXEC_STATE,
@@ -138,7 +139,7 @@ typedef enum
 typedef struct OgrFdwState
 {
        OgrFdwStateType type;
-       Oid foreigntableid; 
+       Oid foreigntableid;
        OgrConnection ogr;  /* connection object */
        OgrFdwTable *table;
        TupleDesc tupdesc;
@@ -147,12 +148,12 @@ typedef struct OgrFdwState
 typedef struct OgrFdwPlanState
 {
        OgrFdwStateType type;
-       Oid foreigntableid; 
-       OgrConnection ogr; 
+       Oid foreigntableid;
+       OgrConnection ogr;
        OgrFdwTable *table;
        TupleDesc tupdesc;
        int nrows;           /* estimate of number of rows in file */
-       Cost startup_cost; 
+       Cost startup_cost;
        Cost total_cost;
        bool *pushdown_clauses;
 } OgrFdwPlanState;
@@ -160,8 +161,8 @@ typedef struct OgrFdwPlanState
 typedef struct OgrFdwExecState
 {
        OgrFdwStateType type;
-       Oid foreigntableid; 
-       OgrConnection ogr;   
+       Oid foreigntableid;
+       OgrConnection ogr;
        OgrFdwTable *table;
        TupleDesc tupdesc;
        char *sql;             /* OGR SQL for attribute filter */
@@ -173,7 +174,7 @@ typedef struct OgrFdwExecState
 typedef struct OgrFdwModifyState
 {
        OgrFdwStateType type;
-       Oid foreigntableid; 
+       Oid foreigntableid;
        OgrConnection ogr;     /* connection object */
        OgrFdwTable *table;
        TupleDesc tupdesc;
@@ -186,4 +187,4 @@ bool ogrDeparse(StringInfo buf, PlannerInfo *root, 
RelOptInfo *foreignrel, List
 /* Shared global value of the Geometry OId */
 extern Oid GEOMETRYOID;
 
-#endif /* _OGR_FDW_H */
\ No newline at end of file
+#endif /* _OGR_FDW_H */

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/pgsql-ogr-fdw.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to