[Git][debian-gis-team/pgsql-ogr-fdw][master] 4 commits: New upstream version 1.0.9
Bas Couwenberg
gitlab at salsa.debian.org
Tue Nov 5 05:04:16 GMT 2019
Bas Couwenberg pushed to branch master at Debian GIS Project / pgsql-ogr-fdw
Commits:
2cd58c1a by Bas Couwenberg at 2019-11-05T04:51:51Z
New upstream version 1.0.9
- - - - -
4a94cda4 by Bas Couwenberg at 2019-11-05T04:51:52Z
Update upstream source from tag 'upstream/1.0.9'
Update to upstream version '1.0.9'
with Debian dir 77b37b1b5cfacb91fe475bf897abde9add757c0f
- - - - -
b13b88a5 by Bas Couwenberg at 2019-11-05T04:52:12Z
New upstream release.
- - - - -
4f9aba95 by Bas Couwenberg at 2019-11-05T04:53:42Z
Set distribution to unstable.
- - - - -
7 changed files:
- META.json
- README.md
- debian/changelog
- ogr_fdw.c
- ogr_fdw_deparse.c
- ogr_fdw_info.c
- stringbuffer.c
Changes:
=====================================
META.json
=====================================
@@ -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",
+ "version": "1.0.9",
"maintainer": [
"Paul Ramsey <pramsey at cleverelephant.ca>"
],
@@ -20,12 +20,12 @@
}
},
"provides": {
- "http": {
+ "ogr_fdw": {
"file": "ogr_fdw--1.0.sql",
"docfile": "README.md",
- "version": "1.0",
+ "version": "1.0.9",
"abstract": "OGR FDW wrapper"
- },
+ }
},
"resources": {
"homepage": "https://github.com/pramsey/pgsql-ogr-fdw/",
@@ -44,8 +44,10 @@
"url": "http://pgxn.org/meta/spec.txt"
},
"tags": [
- "http",
- "curl",
- "web"
+ "ogr",
+ "gdal",
+ "gis",
+ "fdw",
+ "postgis"
]
-}
\ No newline at end of file
+}
=====================================
README.md
=====================================
@@ -16,6 +16,15 @@ This implementation currently has the following limitations:
* **OGR connections every time** Rather than pooling OGR connections, each query makes (and disposes of) two new ones, which seems to be the largest performance drag at the moment for restricted (small) queries.
* **All columns are retrieved every time.** PostgreSQL foreign data wrappers don't require all columns all the time, and some efficiencies can be gained by only requesting the columns needed to fulfill a query. This would be a minimal efficiency improvement, but can be removed given some development time, since the OGR API supports returning a subset of columns.
+## Download
+* Windows
+ * Via [Stackbuilder](https://www.postgresql.org/download/windows/) (part of PostGIS Bundle)
+* Linux
+ * [Arch Linux](https://aur.archlinux.org/packages/pgsql-ogr-fdw/)
+ * [Ubuntu](https://launchpad.net/ubuntu/+source/pgsql-ogr-fdw)
+ * [Red Hat](https://yum.postgresql.org/news-packagelist.php)
+* OSX
+
## Basic Operation
In order to access geometry data from OGR, the PostGIS extension has to be installed: if it is not installed, geometry will be represented as bytea columns, with well-known binary (WKB) values.
=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+pgsql-ogr-fdw (1.0.9-1) unstable; urgency=medium
+
+ * Team upload.
+ * New upstream release.
+
+ -- Bas Couwenberg <sebastic at debian.org> Tue, 05 Nov 2019 05:53:30 +0100
+
pgsql-ogr-fdw (1.0.8-2) unstable; urgency=medium
* Team upload.
=====================================
ogr_fdw.c
=====================================
@@ -201,7 +201,7 @@ ogrErrorHandler(CPLErr eErrClass, int err_no, const char* msg)
{
const char* gdalErrType = "unknown type";
if (err_no >= 0 && err_no <
- (int)sizeof(gdalErrorTypes)/sizeof(gdalErrorTypes[0]))
+ (int)sizeof(gdalErrorTypes) / sizeof(gdalErrorTypes[0]))
{
gdalErrType = gdalErrorTypes[err_no];
}
@@ -569,6 +569,10 @@ ogrGetConnectionFromServer(Oid foreignserverid, OgrUpdateable updateable)
/* Connect! */
err = ogrGetDataSource(&ogr, updateable);
+ if (err == OGRERR_FAILURE)
+ {
+ elog(ERROR, "ogrGetDataSource failed");
+ }
return ogr;
}
@@ -608,9 +612,9 @@ ogrGetConnectionFromTable(Oid foreigntableid, OgrUpdateable updateable)
if (ogr.ds_updateable == OGR_UPDATEABLE_FALSE)
{
ereport(ERROR, (
- errcode(ERRCODE_FDW_ERROR),
- errmsg("data source \"%s\" is not updateable", ogr.ds_str),
- errhint("cannot set table '%s' option to true", OPT_UPDATEABLE)
+ errcode(ERRCODE_FDW_ERROR),
+ errmsg("data source \"%s\" is not updateable", ogr.ds_str),
+ errhint("cannot set table '%s' option to true", OPT_UPDATEABLE)
));
}
ogr.lyr_updateable = OGR_UPDATEABLE_TRUE;
@@ -633,12 +637,12 @@ ogrGetConnectionFromTable(Oid foreigntableid, OgrUpdateable updateable)
{
const char* ogrerr = CPLGetLastErrorMsg();
ereport(ERROR, (
- errcode(ERRCODE_FDW_TABLE_NOT_FOUND),
- errmsg("unable to connect to %s to \"%s\"", OPT_LAYER, ogr.lyr_str),
- (ogrerr && ! streq(ogrerr, ""))
- ? errhint("%s", ogrerr)
- : errhint("Does the layer exist?")
- ));
+ errcode(ERRCODE_FDW_TABLE_NOT_FOUND),
+ errmsg("unable to connect to %s to \"%s\"", OPT_LAYER, ogr.lyr_str),
+ (ogrerr && ! streq(ogrerr, ""))
+ ? errhint("%s", ogrerr)
+ : errhint("Does the layer exist?")
+ ));
}
ogr.lyr_utf8 = OGR_L_TestCapability(ogr.lyr, OLCStringsAsUTF8);
@@ -738,11 +742,11 @@ ogr_fdw_validator(PG_FUNCTION_ARGS)
}
ereport(ERROR, (
- errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
- errmsg("invalid option \"%s\"", def->defname),
- buf.len > 0
- ? errhint("Valid options in this context are: %s", buf.data)
- : errhint("There are no valid options in this context.")));
+ errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
+ errmsg("invalid option \"%s\"", def->defname),
+ buf.len > 0
+ ? errhint("Valid options in this context are: %s", buf.data)
+ : errhint("There are no valid options in this context.")));
}
}
@@ -753,8 +757,8 @@ ogr_fdw_validator(PG_FUNCTION_ARGS)
if (catalog == opt->optcontext && opt->optrequired && ! opt->optfound)
{
ereport(ERROR, (
- errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
- errmsg("required option \"%s\" is missing", opt->optname)));
+ errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
+ errmsg("required option \"%s\" is missing", opt->optname)));
}
}
@@ -770,6 +774,10 @@ ogr_fdw_validator(PG_FUNCTION_ARGS)
ogr.open_options = open_options;
err = ogrGetDataSource(&ogr, updateable);
+ if (err == OGRERR_FAILURE)
+ {
+ elog(ERROR, "ogrGetDataSource failed");
+ }
if (ogr.ds)
{
GDALClose(ogr.ds);
@@ -1174,18 +1182,18 @@ ogrCanConvertToPg(OGRFieldType ogr_type, Oid pg_type, const char* colname, const
case OFTWideStringList:
{
ereport(ERROR, (
- errcode(ERRCODE_FDW_INVALID_DATA_TYPE),
- errmsg("column \"%s\" of foreign table \"%s\" uses an OGR array, currently unsupported", colname, tblname)
- ));
+ errcode(ERRCODE_FDW_INVALID_DATA_TYPE),
+ errmsg("column \"%s\" of foreign table \"%s\" uses an OGR array, currently unsupported", colname, tblname)
+ ));
break;
}
}
ereport(ERROR, (
- errcode(ERRCODE_FDW_INVALID_DATA_TYPE),
- errmsg("column \"%s\" of foreign table \"%s\" converts OGR \"%s\" to \"%s\"",
- colname, tblname,
- OGR_GetFieldTypeName(ogr_type), format_type_be(pg_type))
- ));
+ errcode(ERRCODE_FDW_INVALID_DATA_TYPE),
+ errmsg("column \"%s\" of foreign table \"%s\" converts OGR \"%s\" to \"%s\"",
+ colname, tblname,
+ OGR_GetFieldTypeName(ogr_type), format_type_be(pg_type))
+ ));
}
#ifdef OGR_FDW_HEXWKB
@@ -1361,7 +1369,7 @@ ogrReadColumnData(OgrFdwState* state)
/* Handle FID first */
if (strcaseeq(col.pgname, "fid") &&
- (col.pgtype == INT4OID || col.pgtype == INT8OID))
+ (col.pgtype == INT4OID || col.pgtype == INT8OID))
{
if (fid_count >= 1)
{
=====================================
ogr_fdw_deparse.c
=====================================
@@ -19,39 +19,44 @@
typedef struct OgrDeparseCtx
{
- PlannerInfo *root; /* global planner state */
- RelOptInfo *foreignrel; /* the foreign relation we are planning for */
+ PlannerInfo* root; /* global planner state */
+ RelOptInfo* foreignrel; /* the foreign relation we are planning for */
StringInfo buf; /* output buffer to append to */
- List **params_list; /* exprs that will become remote Params */
+ List** params_list; /* exprs that will become remote Params */
OGRGeometryH geom; /* if filter contains a geometry constant, it resides here */
- OgrFdwState *state; /* to convert local column names to OGR names */
+ OgrFdwState* state; /* to convert local column names to OGR names */
} OgrDeparseCtx;
/* Local function signatures */
-static bool ogrDeparseExpr(Expr *node, OgrDeparseCtx *context);
+static bool ogrDeparseExpr(Expr* node, OgrDeparseCtx* context);
// static void ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context);
-static void setStringInfoLength(StringInfo str, int len)
+static void
+setStringInfoLength(StringInfo str, int len)
{
str->len = len;
str->data[len] = '\0';
}
-static char *
+static char*
ogrStringFromDatum(Datum datum, Oid type)
{
StringInfoData result;
regproc typoutput;
HeapTuple tuple;
- char *str, *p;
+ char* str, *p;
/* Special handling for boolean */
- if ( type == BOOLOID )
+ if (type == BOOLOID)
{
- if ( datum )
+ if (datum)
+ {
return "1=1";
+ }
else
+ {
return "1=0";
+ }
}
/* get the type's output function */
@@ -66,7 +71,7 @@ ogrStringFromDatum(Datum datum, Oid type)
initStringInfo(&result);
/* Special handling to convert a geometry to a bbox needed here */
- if ( type == ogrGetGeometryOid() )
+ if (type == ogrGetGeometryOid())
{
elog(ERROR, "got a GEOMETRY!");
return NULL;
@@ -75,50 +80,54 @@ ogrStringFromDatum(Datum datum, Oid type)
/* render the constant in OGR SQL */
switch (type)
{
- case TEXTOID:
- case DATEOID:
- case TIMESTAMPOID:
- case TIMESTAMPTZOID:
- case CHAROID:
- case BPCHAROID:
- case VARCHAROID:
- case NAMEOID:
- str = DatumGetCString(OidFunctionCall1(typoutput, datum));
-
- /* Don't return a zero length string, return an empty string */
- if (str[0] == '\0')
- return "''";
-
- /* wrap string with ' */
- appendStringInfoChar(&result, '\'');
- for (p=str; *p; ++p)
+ case TEXTOID:
+ case DATEOID:
+ case TIMESTAMPOID:
+ case TIMESTAMPTZOID:
+ case CHAROID:
+ case BPCHAROID:
+ case VARCHAROID:
+ case NAMEOID:
+ str = DatumGetCString(OidFunctionCall1(typoutput, datum));
+
+ /* Don't return a zero length string, return an empty string */
+ if (str[0] == '\0')
+ {
+ return "''";
+ }
+
+ /* wrap string with ' */
+ appendStringInfoChar(&result, '\'');
+ for (p = str; *p; ++p)
+ {
+ /* Escape single quotes as doubled '' */
+ if (*p == '\'')
{
- /* Escape single quotes as doubled '' */
- if (*p == '\'')
- appendStringInfoChar(&result, '\'');
- appendStringInfoChar(&result, *p);
+ appendStringInfoChar(&result, '\'');
}
- appendStringInfoChar(&result, '\'');
- break;
- case INT8OID:
- case INT2OID:
- case INT4OID:
- case OIDOID:
- case FLOAT4OID:
- case FLOAT8OID:
- case NUMERICOID:
- appendStringInfoString(&result, DatumGetCString(OidFunctionCall1(typoutput, datum)));
- break;
- default:
- elog(DEBUG1, "could not convert type (%d) to OGR query form", type);
- return NULL;
+ appendStringInfoChar(&result, *p);
+ }
+ appendStringInfoChar(&result, '\'');
+ break;
+ case INT8OID:
+ case INT2OID:
+ case INT4OID:
+ case OIDOID:
+ case FLOAT4OID:
+ case FLOAT8OID:
+ case NUMERICOID:
+ appendStringInfoString(&result, DatumGetCString(OidFunctionCall1(typoutput, datum)));
+ break;
+ default:
+ elog(DEBUG1, "could not convert type (%d) to OGR query form", type);
+ return NULL;
}
return result.data;
}
static bool
-ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
+ogrDeparseConst(Const* constant, OgrDeparseCtx* context)
{
/* TODO: Can OGR do anythign w/ NULL? */
if (constant->constisnull)
@@ -126,7 +135,7 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
appendStringInfoString(context->buf, "NULL");
}
/* Use geometry as a spatial filter? */
- else if ( constant->consttype == ogrGetGeometryOid() )
+ else if (constant->consttype == ogrGetGeometryOid())
{
/*
* For geometry we need to convert the gserialized constant into
@@ -137,8 +146,8 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
Oid sendfunction;
bool typeIsVarlena;
Datum wkbdatum;
- char *gser;
- char *wkb;
+ char* gser;
+ char* wkb;
int wkb_size;
OGRGeometryH ogrgeom;
OGRErr err;
@@ -157,17 +166,21 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
gser = DatumGetPointer(wkbdatum);
wkb = VARDATA(gser);
wkb_size = VARSIZE(gser) - VARHDRSZ;
- err = OGR_G_CreateFromWkb((unsigned char *)wkb, NULL, &ogrgeom, wkb_size);
+ err = OGR_G_CreateFromWkb((unsigned char*)wkb, NULL, &ogrgeom, wkb_size);
/*
* Save the result
*/
- if ( err != OGRERR_NONE )
+ if (err != OGRERR_NONE)
{
- if ( ! context->geom )
+ if (! context->geom)
+ {
context->geom = ogrgeom;
+ }
else
+ {
elog(WARNING, "got two geometries in OGR FDW query, only using the first");
+ }
}
/*
* geometry doesn't play a role in the deparsed SQL
@@ -177,8 +190,8 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
else
{
/* get a string representation of the value */
- char *c = ogrStringFromDatum(constant->constvalue, constant->consttype);
- if ( c == NULL )
+ char* c = ogrStringFromDatum(constant->constvalue, constant->consttype);
+ if (c == NULL)
{
return false;
}
@@ -192,44 +205,48 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
static bool
-ogrDeparseParam(Param *node, OgrDeparseCtx *context)
+ogrDeparseParam(Param* node, OgrDeparseCtx* context)
{
elog(DEBUG3, "got into ogrDeparseParam code");
return false;
}
static bool
-ogrIsLegalVarName(const char *varname)
+ogrIsLegalVarName(const char* varname)
{
size_t len = strlen(varname);
int i;
- for ( i = 0; i < len; i++ )
+ for (i = 0; i < len; i++)
{
char c = varname[i];
/* First char must be a-zA-Z */
- if ( i == 0 && ! ((c>=97&&c<=122)||(c>=65&&c<=90)) )
+ if (i == 0 && !((c >= 97 && c <= 122) || (c >= 65 && c <= 90)))
+ {
return false;
+ }
/* All other chars must be 0-9a-zA-Z_ */
- if ( ! ((c>=97&&c<=122)||(c>=65&&c<=90)||(c>=48&&c<=59)||(c==96)) )
+ if (!((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || (c >= 48 && c <= 59) || (c == 96)))
+ {
return false;
+ }
}
return true;
}
static bool
-ogrDeparseVar(Var *node, OgrDeparseCtx *context)
+ogrDeparseVar(Var* node, OgrDeparseCtx* context)
{
- StringInfoData *buf = context->buf;
+ StringInfoData* buf = context->buf;
if (node->varno == context->foreignrel->relid && node->varlevelsup == 0)
{
/* Var belongs to foreign table */
int i;
- OgrFdwTable *table = context->state->table;
+ OgrFdwTable* table = context->state->table;
OGRLayerH lyr = context->state->ogr.lyr;
bool done = false;
@@ -239,31 +256,37 @@ ogrDeparseVar(Var *node, OgrDeparseCtx *context)
/* TODO: Handle case of mapping columns to OGR columns that don't share their name */
/* TODO: Lookup OGR column name by going from varattno -> OGR via a table/OGR map */
- for ( i = 0; i < table->ncols; i++ )
+ for (i = 0; i < table->ncols; i++)
{
- if ( table->cols[i].pgattnum == node->varattno )
+ if (table->cols[i].pgattnum == node->varattno)
{
- const char *fldname = NULL;
+ const char* fldname = NULL;
- if ( table->cols[i].ogrvariant == OGR_FID )
+ if (table->cols[i].ogrvariant == OGR_FID)
{
fldname = OGR_L_GetFIDColumn(lyr);
- if ( ! fldname || strlen(fldname) == 0 )
+ if (! fldname || strlen(fldname) == 0)
+ {
fldname = "fid";
+ }
}
- else if ( table->cols[i].ogrvariant == OGR_FIELD )
+ else if (table->cols[i].ogrvariant == OGR_FIELD)
{
OGRFeatureDefnH fd = OGR_L_GetLayerDefn(lyr);
OGRFieldDefnH fld = OGR_FD_GetFieldDefn(fd, table->cols[i].ogrfldnum);
fldname = OGR_Fld_GetNameRef(fld);
}
- if ( fldname )
+ if (fldname)
{
- if ( ogrIsLegalVarName(fldname) )
+ if (ogrIsLegalVarName(fldname))
+ {
appendStringInfoString(buf, fldname);
+ }
else
+ {
appendStringInfo(buf, "\"%s\"", fldname);
+ }
done = true;
}
@@ -281,48 +304,55 @@ ogrDeparseVar(Var *node, OgrDeparseCtx *context)
return true;
}
-static int ogrOperatorCmpFunc(const void * a, const void * b)
+static int
+ogrOperatorCmpFunc(const void* a, const void* b)
{
return strcasecmp(*(const char**)a, *(const char**)b);
}
static bool
-ogrOperatorIsSupported(const char *opname)
+ogrOperatorIsSupported(const char* opname)
{
/* IMPORTANT */
/* This array MUST be in sorted order or the bsearch will fail */
- static const char * ogrOperators[10] = { "!=", "&&", "<", "<=", "<>", "=", ">", ">=", "~~", "~~*" };
+ static const char* ogrOperators[10] = { "!=", "&&", "<", "<=", "<>", "=", ">", ">=", "~~", "~~*" };
elog(DEBUG3, "ogrOperatorIsSupported got operator '%s'", opname);
- if ( bsearch(&opname, ogrOperators, 10, sizeof(char*), ogrOperatorCmpFunc) )
+ if (bsearch(&opname, ogrOperators, 10, sizeof(char*), ogrOperatorCmpFunc))
+ {
return true;
+ }
else
+ {
return false;
+ }
}
static bool
-ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
+ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx* context)
{
StringInfo buf = context->buf;
HeapTuple tuple;
Form_pg_operator form;
char oprkind;
- char *opname;
- ListCell *arg;
+ char* opname;
+ ListCell* arg;
bool result = true;
/* Retrieve information about the operator from system catalog. */
tuple = SearchSysCache1(OPEROID, ObjectIdGetDatum(node->opno));
if (!HeapTupleIsValid(tuple))
+ {
elog(ERROR, "cache lookup failed for operator %u", node->opno);
+ }
form = (Form_pg_operator) GETSTRUCT(tuple);
oprkind = form->oprkind;
opname = NameStr(form->oprname);
/* Don't deparse expressions we cannot support */
- if ( ! ogrOperatorIsSupported(opname) )
+ if (! ogrOperatorIsSupported(opname))
{
ReleaseSysCache(tuple);
return false;
@@ -333,7 +363,7 @@ ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
/* Overlaps operator is special case: if one side is a constant, */
/* then we can pass it as a spatial filter to OGR */
- if ( strcmp("&&", opname) == 0 )
+ if (strcmp("&&", opname) == 0)
{
// Expr *r_arg = lfirst(list_head(node->args));
// Expr *l_arg = lfirst(list_tail(node->args));
@@ -369,7 +399,7 @@ ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
appendStringInfoChar(buf, '(');
/* Deparse left operand. */
- if ( oprkind == 'r' || oprkind == 'b' )
+ if (oprkind == 'r' || oprkind == 'b')
{
arg = list_head(node->args);
/* recurse for nested operations */
@@ -381,8 +411,10 @@ ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
/* by PgSQL, so we have to convert it back here */
/* All OGR string comparisons are case insensitive, so we just */
/* use 'ILIKE' all the time. */
- if ( streq(opname, "~~") || streq(opname, "~~*") )
+ if (streq(opname, "~~") || streq(opname, "~~*"))
+ {
opname = "ILIKE";
+ }
/* Operator symbol */
appendStringInfoString(buf, opname);
@@ -404,10 +436,10 @@ ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
}
static bool
-ogrDeparseBoolExpr(BoolExpr *node, OgrDeparseCtx *context)
+ogrDeparseBoolExpr(BoolExpr* node, OgrDeparseCtx* context)
{
- const char *op = NULL; /* keep compiler quiet */
- ListCell *lc;
+ const char* op = NULL; /* keep compiler quiet */
+ ListCell* lc;
bool first = true;
bool result = true;
int len_save_all, len_save_part;
@@ -417,144 +449,164 @@ ogrDeparseBoolExpr(BoolExpr *node, OgrDeparseCtx *context)
switch (boolop)
{
- case AND_EXPR:
- op = "AND";
- break;
- case OR_EXPR:
- op = "OR";
- break;
-
- /* OGR SQL cannot handle "NOT" */
- case NOT_EXPR:
- return false;
+ case AND_EXPR:
+ op = "AND";
+ break;
+ case OR_EXPR:
+ op = "OR";
+ break;
+
+ /* OGR SQL cannot handle "NOT" */
+ case NOT_EXPR:
+ return false;
}
len_save_all = buf->len;
appendStringInfoChar(buf, '(');
- foreach(lc, node->args)
+ foreach (lc, node->args)
{
len_save_part = buf->len;
/* Connect expressions and parenthesize each condition */
- if ( ! first )
+ if (! first)
+ {
appendStringInfo(buf, " %s ", op);
+ }
/* Unparse the expression, if possible */
- result = ogrDeparseExpr((Expr *) lfirst(lc), context);
+ result = ogrDeparseExpr((Expr*) lfirst(lc), context);
result_total += result;
/* We can backtrack just this term for AND expressions */
- if ( boolop == AND_EXPR && ! result )
+ if (boolop == AND_EXPR && ! result)
+ {
setStringInfoLength(buf, len_save_part);
+ }
/* We have to drop the whole thing if we can't get every part of an OR expression */
- if ( boolop == OR_EXPR && ! result )
+ if (boolop == OR_EXPR && ! result)
+ {
break;
+ }
/* Don't flip the "first" bit until we get a good expression */
- if ( first && result )
+ if (first && result)
+ {
first = false;
+ }
}
appendStringInfoChar(buf, ')');
/* We have to drop the whole thing if we can't get every part of an OR expression */
- if ( boolop == OR_EXPR && ! result )
+ if (boolop == OR_EXPR && ! result)
+ {
setStringInfoLength(buf, len_save_all);
+ }
return result_total > 0;
}
static bool
-ogrDeparseRelabelType(RelabelType *node, OgrDeparseCtx *context)
+ogrDeparseRelabelType(RelabelType* node, OgrDeparseCtx* context)
{
if (node->relabelformat != COERCE_IMPLICIT_CAST)
+ {
elog(WARNING, "Received a non-implicit relabel expression but did not handle it");
+ }
return ogrDeparseExpr(node->arg, context);
}
static bool
-ogrDeparseNullTest(NullTest *node, OgrDeparseCtx *context)
+ogrDeparseNullTest(NullTest* node, OgrDeparseCtx* context)
{
StringInfo buf = context->buf;
appendStringInfoChar(buf, '(');
ogrDeparseExpr(node->arg, context);
if (node->nulltesttype == IS_NULL)
+ {
appendStringInfoString(buf, " IS NULL)");
+ }
else
+ {
appendStringInfoString(buf, " IS NOT NULL)");
+ }
return true;
}
static bool
-ogrDeparseExpr(Expr *node, OgrDeparseCtx *context)
+ogrDeparseExpr(Expr* node, OgrDeparseCtx* context)
{
- if ( node == NULL )
+ if (node == NULL)
+ {
return false;
+ }
- switch ( nodeTag(node) )
+ switch (nodeTag(node))
{
- case T_OpExpr:
- return ogrDeparseOpExpr((OpExpr *) node, context);
- case T_Const:
- return ogrDeparseConst((Const *) node, context);
- case T_Var:
- return ogrDeparseVar((Var *) node, context);
- case T_Param:
- return ogrDeparseParam((Param *) node, context);
- case T_BoolExpr:
- /* Handle "OR" and "NOT" queries */
- return ogrDeparseBoolExpr((BoolExpr *) node, context);
- case T_NullTest:
- /* Handle "IS NULL" queries */
- return ogrDeparseNullTest((NullTest *) node, context);
- case T_RelabelType:
- return ogrDeparseRelabelType((RelabelType *) node, context);
- case T_ScalarArrayOpExpr:
- /* TODO: Handle this to support the "IN" operator */
- elog(NOTICE, "unsupported OGR FDW expression type, T_ScalarArrayOpExpr");
- return false;
+ case T_OpExpr:
+ return ogrDeparseOpExpr((OpExpr*) node, context);
+ case T_Const:
+ return ogrDeparseConst((Const*) node, context);
+ case T_Var:
+ return ogrDeparseVar((Var*) node, context);
+ case T_Param:
+ return ogrDeparseParam((Param*) node, context);
+ case T_BoolExpr:
+ /* Handle "OR" and "NOT" queries */
+ return ogrDeparseBoolExpr((BoolExpr*) node, context);
+ case T_NullTest:
+ /* Handle "IS NULL" queries */
+ return ogrDeparseNullTest((NullTest*) node, context);
+ case T_RelabelType:
+ return ogrDeparseRelabelType((RelabelType*) node, context);
+ case T_ScalarArrayOpExpr:
+ /* 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;
+ 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;
+ 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;
- case T_FuncExpr:
- elog(NOTICE, "unsupported OGR FDW expression type, T_FuncExpr");
- return false;
- case T_DistinctExpr:
- elog(NOTICE, "unsupported OGR FDW expression type, T_DistinctExpr");
- return false;
- default:
- elog(NOTICE, "unsupported OGR FDW expression type for deparse: %d", (int) nodeTag(node));
- return false;
+ case T_ArrayExpr:
+ elog(NOTICE, "unsupported OGR FDW expression type, T_ArrayExpr");
+ return false;
+ case T_FuncExpr:
+ elog(NOTICE, "unsupported OGR FDW expression type, T_FuncExpr");
+ return false;
+ case T_DistinctExpr:
+ elog(NOTICE, "unsupported OGR FDW expression type, T_DistinctExpr");
+ return false;
+ default:
+ elog(NOTICE, "unsupported OGR FDW expression type for deparse: %d", (int) nodeTag(node));
+ return false;
}
}
bool
-ogrDeparse(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *exprs, OgrFdwState *state, List **params)
+ogrDeparse(StringInfo buf, PlannerInfo* root, RelOptInfo* foreignrel, List* exprs, OgrFdwState* state, List** params)
{
OgrDeparseCtx context;
- ListCell *lc;
+ ListCell* lc;
bool first = true;
/* initialize result list to empty */
if (params)
+ {
*params = NIL;
+ }
/* Set up context struct for recursion */
context.buf = buf;
@@ -566,14 +618,14 @@ ogrDeparse(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *expr
// context.geom_op = NULL;
// context.geom_func = NULL;
- foreach(lc, exprs)
+ foreach (lc, exprs)
{
- RestrictInfo *ri = (RestrictInfo *) lfirst(lc);
+ RestrictInfo* ri = (RestrictInfo*) lfirst(lc);
int len_save = buf->len;
bool result;
/* Connect expressions with "AND" and parenthesize each condition */
- if ( ! first )
+ if (! first)
{
appendStringInfoString(buf, " AND ");
}
@@ -583,15 +635,17 @@ ogrDeparse(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *expr
result = ogrDeparseExpr(ri->clause, &context);
// appendStringInfoChar(buf, ')');
- if ( ! result )
+ if (! result)
{
/* Couldn't unparse some portion of the expression, so rewind the stringinfo */
setStringInfoLength(buf, len_save);
}
/* Don't flip the "first" bit until we get a good expression */
- if ( first && result )
+ if (first && result)
+ {
first = false;
+ }
}
return true;
=====================================
ogr_fdw_info.c
=====================================
@@ -19,18 +19,18 @@
#include "ogr_fdw_common.h"
static void usage();
-static OGRErr ogrListLayers(const char *source);
-static OGRErr ogrGenerateSQL(const char *source, const char *layer);
+static OGRErr ogrListLayers(const char* source);
+static OGRErr ogrGenerateSQL(const char* source, const char* layer);
#define STR_MAX_LEN 256
/* Define this no-op here, so that code */
/* in the ogr_fdw_common module works */
-const char * quote_identifier(const char *ident);
+const char* quote_identifier(const char* ident);
-const char *
-quote_identifier(const char *ident)
+const char*
+quote_identifier(const char* ident)
{
return ident;
}
@@ -43,13 +43,13 @@ formats()
GDALAllRegister();
- printf( "Supported Formats:\n" );
- for ( i = 0; i < GDALGetDriverCount(); i++ )
+ printf("Supported Formats:\n");
+ for (i = 0; i < GDALGetDriverCount(); i++)
{
GDALDriverH ogr_dr = GDALGetDriver(i);
int vector = FALSE;
int createable = TRUE;
- const char *tmpl;
+ const char* tmpl;
#if GDAL_VERSION_MAJOR >= 2
char** papszMD = GDALGetMetadata(ogr_dr, NULL);
@@ -59,13 +59,20 @@ formats()
createable = GDALDatasetTestCapability(ogr_dr, ODrCCreateDataSource);
#endif
/* Skip raster data sources */
- if ( ! vector ) continue;
+ if (! vector)
+ {
+ continue;
+ }
/* Report sources w/ create capability as r/w */
- if( createable )
+ if (createable)
+ {
tmpl = " -> \"%s\" (read/write)\n";
+ }
else
+ {
tmpl = " -> \"%s\" (readonly)\n";
+ }
printf(tmpl, GDALGetDriverShortName(ogr_dr));
}
@@ -77,57 +84,61 @@ static void
usage()
{
printf(
- "usage: ogr_fdw_info -s <ogr datasource> -l <ogr layer>\n"
- " ogr_fdw_info -s <ogr datasource>\n"
- " ogr_fdw_info -f\n"
- "\n");
+ "usage: ogr_fdw_info -s <ogr datasource> -l <ogr layer>\n"
+ " ogr_fdw_info -s <ogr datasource>\n"
+ " ogr_fdw_info -f\n"
+ "\n");
exit(0);
}
int
-main (int argc, char **argv)
+main(int argc, char** argv)
{
int ch;
- char *source = NULL, *layer = NULL;
+ char* source = NULL, *layer = NULL;
OGRErr err = OGRERR_NONE;
/* If no options are specified, display usage */
if (argc == 1)
+ {
usage();
+ }
- while ((ch = getopt(argc, argv, "h?s:l:f")) != -1) {
- switch (ch) {
- case 's':
- source = optarg;
- break;
- case 'l':
- layer = optarg;
- break;
- case 'f':
- formats();
- break;
- case '?':
- case 'h':
- default:
- usage();
- break;
+ while ((ch = getopt(argc, argv, "h?s:l:f")) != -1)
+ {
+ switch (ch)
+ {
+ case 's':
+ source = optarg;
+ break;
+ case 'l':
+ layer = optarg;
+ break;
+ case 'f':
+ formats();
+ break;
+ case '?':
+ case 'h':
+ default:
+ usage();
+ break;
}
}
- if ( source && ! layer )
+ if (source && ! layer)
{
err = ogrListLayers(source);
}
- else if ( source && layer )
+ else if (source && layer)
{
err = ogrGenerateSQL(source, layer);
}
- else if ( ! source && ! layer )
+ else if (! source && ! layer)
{
usage();
}
- if ( err != OGRERR_NONE )
+ if (err != OGRERR_NONE)
{
// printf("OGR Error: %s\n\n", CPLGetLastErrorMsg());
}
@@ -137,7 +148,7 @@ main (int argc, char **argv)
}
static OGRErr
-ogrListLayers(const char *source)
+ogrListLayers(const char* source)
{
GDALDatasetH ogr_ds = NULL;
int i;
@@ -148,21 +159,21 @@ ogrListLayers(const char *source)
ogr_ds = OGROpen(source, FALSE, NULL);
#else
ogr_ds = GDALOpenEx(source,
- GDAL_OF_VECTOR|GDAL_OF_READONLY,
- NULL, NULL, NULL);
+ GDAL_OF_VECTOR | GDAL_OF_READONLY,
+ NULL, NULL, NULL);
#endif
- if ( ! ogr_ds )
+ if (! ogr_ds)
{
CPLError(CE_Failure, CPLE_AppDefined, "Could not connect to source '%s'", source);
return OGRERR_FAILURE;
}
printf("Layers:\n");
- for ( i = 0; i < GDALDatasetGetLayerCount(ogr_ds); i++ )
+ for (i = 0; i < GDALDatasetGetLayerCount(ogr_ds); i++)
{
OGRLayerH ogr_lyr = GDALDatasetGetLayer(ogr_ds, i);
- if ( ! ogr_lyr )
+ if (! ogr_lyr)
{
return OGRERR_FAILURE;
}
@@ -176,7 +187,7 @@ ogrListLayers(const char *source)
}
static OGRErr
-ogrGenerateSQL(const char *source, const char *layer)
+ogrGenerateSQL(const char* source, const char* layer)
{
OGRErr err;
GDALDatasetH ogr_ds = NULL;
@@ -191,24 +202,26 @@ ogrGenerateSQL(const char *source, const char *layer)
ogr_ds = OGROpen(source, FALSE, &ogr_dr);
#else
ogr_ds = GDALOpenEx(source,
- GDAL_OF_VECTOR|GDAL_OF_READONLY,
- NULL, NULL, NULL);
+ GDAL_OF_VECTOR | GDAL_OF_READONLY,
+ NULL, NULL, NULL);
#endif
- if ( ! ogr_ds )
+ if (! ogr_ds)
{
CPLError(CE_Failure, CPLE_AppDefined, "Could not connect to source '%s'", source);
return OGRERR_FAILURE;
}
- if ( ! ogr_dr )
+ if (! ogr_dr)
+ {
ogr_dr = GDALGetDatasetDriver(ogr_ds);
+ }
/* There should be a nicer way to do this */
strcpy(server_name, "myserver");
ogr_lyr = GDALDatasetGetLayerByName(ogr_ds, layer);
- if ( ! ogr_lyr )
+ if (! ogr_lyr)
{
CPLError(CE_Failure, CPLE_AppDefined, "Could not find layer '%s' in source '%s'", layer, source);
return OGRERR_FAILURE;
@@ -216,23 +229,23 @@ ogrGenerateSQL(const char *source, const char *layer)
/* Output SERVER definition */
printf("\nCREATE SERVER %s\n"
- " FOREIGN DATA WRAPPER ogr_fdw\n"
- " OPTIONS (\n"
- " datasource '%s',\n"
- " format '%s' );\n",
- server_name, source, GDALGetDriverShortName(ogr_dr));
+ " FOREIGN DATA WRAPPER ogr_fdw\n"
+ " OPTIONS (\n"
+ " datasource '%s',\n"
+ " format '%s' );\n",
+ server_name, source, GDALGetDriverShortName(ogr_dr));
stringbuffer_init(&buf);
err = ogrLayerToSQL(ogr_lyr,
- server_name,
- TRUE, /* launder table names */
- TRUE, /* launder column names */
- TRUE, /* use postgis geometry */
- &buf);
+ server_name,
+ TRUE, /* launder table names */
+ TRUE, /* launder column names */
+ TRUE, /* use postgis geometry */
+ &buf);
GDALClose(ogr_ds);
- if ( err != OGRERR_NONE )
+ if (err != OGRERR_NONE)
{
return err;
}
=====================================
stringbuffer.c
=====================================
@@ -14,14 +14,14 @@
/**
* Allocate a new stringbuffer_t. Use stringbuffer_destroy to free.
*/
-stringbuffer_t*
+stringbuffer_t*
stringbuffer_create(void)
{
return stringbuffer_create_with_size(STRINGBUFFER_STARTSIZE);
}
static void
-stringbuffer_init_with_size(stringbuffer_t *s, size_t size)
+stringbuffer_init_with_size(stringbuffer_t* s, size_t size)
{
s->str_start = malloc(size);
s->str_end = s->str_start;
@@ -30,13 +30,16 @@ stringbuffer_init_with_size(stringbuffer_t *s, size_t size)
}
void
-stringbuffer_release(stringbuffer_t *s)
+stringbuffer_release(stringbuffer_t* s)
{
- if ( s->str_start ) free(s->str_start);
+ if (s->str_start)
+ {
+ free(s->str_start);
+ }
}
void
-stringbuffer_init(stringbuffer_t *s)
+stringbuffer_init(stringbuffer_t* s)
{
stringbuffer_init_with_size(s, STRINGBUFFER_STARTSIZE);
}
@@ -44,10 +47,10 @@ stringbuffer_init(stringbuffer_t *s)
/**
* Allocate a new stringbuffer_t. Use stringbuffer_destroy to free.
*/
-stringbuffer_t*
+stringbuffer_t*
stringbuffer_create_with_size(size_t size)
{
- stringbuffer_t *s;
+ stringbuffer_t* s;
s = malloc(sizeof(stringbuffer_t));
stringbuffer_init_with_size(s, size);
@@ -57,11 +60,14 @@ stringbuffer_create_with_size(size_t size)
/**
* Free the stringbuffer_t and all memory managed within it.
*/
-void
-stringbuffer_destroy(stringbuffer_t *s)
+void
+stringbuffer_destroy(stringbuffer_t* s)
{
stringbuffer_release(s);
- if ( s ) free(s);
+ if (s)
+ {
+ free(s);
+ }
}
/**
@@ -69,8 +75,8 @@ stringbuffer_destroy(stringbuffer_t *s)
* without the expense of freeing and re-allocating a new
* stringbuffer_t.
*/
-void
-stringbuffer_clear(stringbuffer_t *s)
+void
+stringbuffer_clear(stringbuffer_t* s)
{
s->str_start[0] = '\0';
s->str_end = s->str_start;
@@ -80,17 +86,19 @@ stringbuffer_clear(stringbuffer_t *s)
* If necessary, expand the stringbuffer_t internal buffer to accomodate the
* specified additional size.
*/
-static inline void
-stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
+static inline void
+stringbuffer_makeroom(stringbuffer_t* s, size_t size_to_add)
{
size_t current_size = (s->str_end - s->str_start);
size_t capacity = s->capacity;
size_t required_size = current_size + size_to_add;
while (capacity < required_size)
+ {
capacity *= 2;
+ }
- if ( capacity > s->capacity )
+ if (capacity > s->capacity)
{
s->str_start = realloc(s->str_start, capacity);
s->capacity = capacity;
@@ -101,22 +109,24 @@ stringbuffer_makeroom(stringbuffer_t *s, size_t size_to_add)
/**
* Return the last character in the buffer.
*/
-char
-stringbuffer_lastchar(stringbuffer_t *s)
+char
+stringbuffer_lastchar(stringbuffer_t* s)
{
- if( s->str_end == s->str_start )
+ if (s->str_end == s->str_start)
+ {
return 0;
-
- return *(s->str_end - 1);
+ }
+
+ return * (s->str_end - 1);
}
/**
* Append the specified string to the stringbuffer_t.
*/
-void
-stringbuffer_append(stringbuffer_t *s, const char *a)
+void
+stringbuffer_append(stringbuffer_t* s, const char* a)
{
- int alen = strlen(a); /* Length of string to append */
+ int alen = strlen(a); /* Length of string to append */
int alen0 = alen + 1; /* Length including null terminator */
stringbuffer_makeroom(s, alen0);
memcpy(s->str_end, a, alen0);
@@ -126,13 +136,13 @@ stringbuffer_append(stringbuffer_t *s, const char *a)
/**
* Append the specified character to the stringbuffer_t.
*/
-void
-stringbuffer_append_char(stringbuffer_t *s, char c)
+void
+stringbuffer_append_char(stringbuffer_t* s, char c)
{
- stringbuffer_makeroom(s, 2); /* space for char + null terminator */
- *(s->str_end) = c; /* add char */
+ stringbuffer_makeroom(s, 2); /* space for char + null terminator */
+ * (s->str_end) = c; /* add char */
s->str_end += 1;
- *(s->str_end) = 0; /* null terminate */
+ * (s->str_end) = 0; /* null terminate */
}
/**
@@ -140,8 +150,8 @@ stringbuffer_append_char(stringbuffer_t *s, char c)
* the stringbuffer. The current string will be null-terminated
* within the internal string.
*/
-const char*
-stringbuffer_getstring(stringbuffer_t *s)
+const char*
+stringbuffer_getstring(stringbuffer_t* s)
{
return s->str_start;
}
@@ -151,11 +161,11 @@ stringbuffer_getstring(stringbuffer_t *s)
* current state of the string. Caller is responsible for
* freeing the return value.
*/
-char*
-stringbuffer_getstringcopy(stringbuffer_t *s)
+char*
+stringbuffer_getstringcopy(stringbuffer_t* s)
{
size_t size = (s->str_end - s->str_start) + 1;
- char *str = malloc(size);
+ char* str = malloc(size);
memcpy(str, s->str_start, size);
str[size - 1] = '\0';
return str;
@@ -165,8 +175,8 @@ stringbuffer_getstringcopy(stringbuffer_t *s)
* Returns the length of the current string, not including the
* null terminator (same behavior as strlen()).
*/
-int
-stringbuffer_getlength(stringbuffer_t *s)
+int
+stringbuffer_getlength(stringbuffer_t* s)
{
return (s->str_end - s->str_start);
}
@@ -174,8 +184,8 @@ stringbuffer_getlength(stringbuffer_t *s)
/**
* Clear the stringbuffer_t and re-start it with the specified string.
*/
-void
-stringbuffer_set(stringbuffer_t *s, const char *str)
+void
+stringbuffer_set(stringbuffer_t* s, const char* str)
{
stringbuffer_clear(s);
stringbuffer_append(s, str);
@@ -184,8 +194,8 @@ stringbuffer_set(stringbuffer_t *s, const char *str)
/**
* Copy the contents of src into dst.
*/
-void
-stringbuffer_copy(stringbuffer_t *dst, stringbuffer_t *src)
+void
+stringbuffer_copy(stringbuffer_t* dst, stringbuffer_t* src)
{
stringbuffer_set(dst, stringbuffer_getstring(src));
}
@@ -195,8 +205,8 @@ stringbuffer_copy(stringbuffer_t *dst, stringbuffer_t *src)
* using the format and argument list provided. Returns -1 on error,
* check errno for reasons, documented in the printf man page.
*/
-static int
-stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
+static int
+stringbuffer_avprintf(stringbuffer_t* s, const char* fmt, va_list ap)
{
int maxlen = (s->capacity - (s->str_end - s->str_start));
int len = 0; /* Length of the output */
@@ -209,17 +219,18 @@ stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
va_end(ap2);
/* Propogate errors up */
- if ( len < 0 )
- #if defined(__MINGW64_VERSION_MAJOR)
- len = _vscprintf(fmt, ap2);/**Assume windows flaky vsnprintf that returns -1 if initial buffer to small and add more space **/
- #else
+ if (len < 0)
+#if defined(__MINGW64_VERSION_MAJOR)
+ len = _vscprintf(fmt,
+ ap2); /**Assume windows flaky vsnprintf that returns -1 if initial buffer to small and add more space **/
+#else
return len;
- #endif
+#endif
/* We didn't have enough space! */
/* Either Unix vsnprint returned write length larger than our buffer */
/* or Windows vsnprintf returned an error code. */
- if ( len >= maxlen )
+ if (len >= maxlen)
{
stringbuffer_makeroom(s, len + 1);
maxlen = (s->capacity - (s->str_end - s->str_start));
@@ -228,9 +239,15 @@ stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
len = vsnprintf(s->str_end, maxlen, fmt, ap);
/* Printing error? Error! */
- if ( len < 0 ) return len;
+ if (len < 0)
+ {
+ return len;
+ }
/* Too long still? Error! */
- if ( len >= maxlen ) return -1;
+ if (len >= maxlen)
+ {
+ return -1;
+ }
}
/* Move end pointer forward and return. */
@@ -244,8 +261,8 @@ stringbuffer_avprintf(stringbuffer_t *s, const char *fmt, va_list ap)
* Returns -1 on error, check errno for reasons,
* as documented in the printf man page.
*/
-int
-stringbuffer_aprintf(stringbuffer_t *s, const char *fmt, ...)
+int
+stringbuffer_aprintf(stringbuffer_t* s, const char* fmt, ...)
{
int r;
va_list ap;
@@ -259,17 +276,17 @@ stringbuffer_aprintf(stringbuffer_t *s, const char *fmt, ...)
* Trims whitespace off the end of the stringbuffer. Returns
* the number of characters trimmed.
*/
-int
-stringbuffer_trim_trailing_white(stringbuffer_t *s)
+int
+stringbuffer_trim_trailing_white(stringbuffer_t* s)
{
- char *ptr = s->str_end;
+ char* ptr = s->str_end;
int dist = 0;
-
+
/* Roll backwards until we hit a non-space. */
- while( ptr > s->str_start )
- {
+ while (ptr > s->str_start)
+ {
ptr--;
- if( (*ptr == ' ') || (*ptr == '\t') )
+ if ((*ptr == ' ') || (*ptr == '\t'))
{
continue;
}
@@ -282,7 +299,7 @@ stringbuffer_trim_trailing_white(stringbuffer_t *s)
return dist;
}
}
- return dist;
+ return dist;
}
/**
@@ -290,61 +307,77 @@ stringbuffer_trim_trailing_white(stringbuffer_t *s)
* The number has to be the very last thing in the buffer. Only the
* last number will be trimmed. Returns the number of characters
* trimmed.
-*
+*
* eg: 1.22000 -> 1.22
* 1.0 -> 1
* 0.0 -> 0
*/
-int
-stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
+int
+stringbuffer_trim_trailing_zeroes(stringbuffer_t* s)
{
- char *ptr = s->str_end;
- char *decimal_ptr = NULL;
+ char* ptr = s->str_end;
+ char* decimal_ptr = NULL;
int dist;
-
- if ( s->str_end - s->str_start < 2)
+
+ if (s->str_end - s->str_start < 2)
+ {
return 0;
+ }
/* Roll backwards to find the decimal for this number */
- while( ptr > s->str_start )
- {
+ while (ptr > s->str_start)
+ {
ptr--;
- if ( *ptr == '.' )
+ if (*ptr == '.')
{
decimal_ptr = ptr;
break;
}
- if ( (*ptr >= '0') && (*ptr <= '9' ) )
+ if ((*ptr >= '0') && (*ptr <= '9'))
+ {
continue;
+ }
else
+ {
break;
+ }
}
/* No decimal? Nothing to trim! */
- if ( ! decimal_ptr )
+ if (! decimal_ptr)
+ {
return 0;
-
+ }
+
ptr = s->str_end;
-
+
/* Roll backwards again, with the decimal as stop point, trimming contiguous zeroes */
- while( ptr >= decimal_ptr )
+ while (ptr >= decimal_ptr)
{
ptr--;
- if ( *ptr == '0' )
+ if (*ptr == '0')
+ {
continue;
+ }
else
+ {
break;
+ }
}
-
+
/* Huh, we get anywhere. Must not have trimmed anything. */
- if ( ptr == s->str_end )
+ if (ptr == s->str_end)
+ {
return 0;
+ }
- /* If we stopped at the decimal, we want to null that out.
- It we stopped on a numeral, we want to preserve that, so push the
+ /* If we stopped at the decimal, we want to null that out.
+ It we stopped on a numeral, we want to preserve that, so push the
pointer forward one space. */
- if ( *ptr != '.' )
+ if (*ptr != '.')
+ {
ptr++;
+ }
/* Add null terminator re-set the end of the stringbuffer. */
*ptr = '\0';
View it on GitLab: https://salsa.debian.org/debian-gis-team/pgsql-ogr-fdw/compare/e8491f9374fb68c43760ab436a50506716716a26...4f9aba95c9734f41bf35e439f6668a9822ca725f
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/pgsql-ogr-fdw/compare/e8491f9374fb68c43760ab436a50506716716a26...4f9aba95c9734f41bf35e439f6668a9822ca725f
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20191105/a286496a/attachment-0001.html>
More information about the Pkg-grass-devel
mailing list