New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quotes escaping in strings doesn't work with postgis raster "filename" field #5030

Open
cassiel74 opened this Issue Nov 6, 2014 · 7 comments

Comments

Projects
None yet
5 participants
@cassiel74

cassiel74 commented Nov 6, 2014

According to http://mapserver.org/mapfile/expressions.html#quotes-escaping-in-strings it should be possible to use a DATA statement like the following:

DATA "PG:host=localhost port=5432 dbname='xxx' user='xxx' password='xxx' schema='raster' table='dem' where='filename='dem20_12.tif'' mode='2' "

but when testing with shp2img each and every quote escaping "tecnique" fails with similar error messages
msDrawRasterLayerLow(): Unable to access file. Corrupt, empty or missing file 'PG:host=localhost port=5432 dbname='xxx' user='xxx' password='xxx' schema='raster' table='dem' where="filename='dem20_12.tif'" mode='2'' for layer 'dem20'. Error browsing database for PostGIS Raster properties

Regards

@sdlime

This comment has been minimized.

Show comment
Hide comment
@sdlime

sdlime Nov 6, 2014

Member

What MapServer version?

Member

sdlime commented Nov 6, 2014

What MapServer version?

@cassiel74

This comment has been minimized.

Show comment
Hide comment
@cassiel74

cassiel74 Nov 7, 2014

debian jessie here:
Architecture: amd64
Source: mapserver (6.4.1-5)
Version: 6.4.1-5+b2

cassiel74 commented Nov 7, 2014

debian jessie here:
Architecture: amd64
Source: mapserver (6.4.1-5)
Version: 6.4.1-5+b2

@ChrisVolz

This comment has been minimized.

Show comment
Hide comment
@ChrisVolz

ChrisVolz Aug 3, 2015

I can confirm this problem. The escaping does not work. (mapserver 6.4.1). Does anyone know a workaround?

ChrisVolz commented Aug 3, 2015

I can confirm this problem. The escaping does not work. (mapserver 6.4.1). Does anyone know a workaround?

@sdlime

This comment has been minimized.

Show comment
Hide comment
@sdlime

sdlime Aug 3, 2015

Member

The escaping within MapServer looks to be working at some level or you'd see a parse error as the mapfile is being read. This looks to be more specific to the PostGIS driver. What specifically does your data statement look like? The syntax in the initial message doesn't look right to me.

Member

sdlime commented Aug 3, 2015

The escaping within MapServer looks to be working at some level or you'd see a parse error as the mapfile is being read. This looks to be more specific to the PostGIS driver. What specifically does your data statement look like? The syntax in the initial message doesn't look right to me.

@matrottier

This comment has been minimized.

Show comment
Hide comment
@matrottier

matrottier Nov 4, 2015

working for me ( mapserver 6.4.2 ) :
DATA "PG:host=host port=port dbname='pgsyst' user='user' password='password' schema='schema' table='table_name' mode='2' where='filename='patate.tiff'' "

matrottier commented Nov 4, 2015

working for me ( mapserver 6.4.2 ) :
DATA "PG:host=host port=port dbname='pgsyst' user='user' password='password' schema='schema' table='table_name' mode='2' where='filename='patate.tiff'' "

@diplonics

This comment has been minimized.

Show comment
Hide comment
@diplonics

diplonics Feb 7, 2018

Example below of how I got around this issue using double dollar signs for the date and geomfromtext query elements:

DATA "PG:host=localhost user='some_user' password='some_password' dbname='some_db' port=5432 schema='public' table='some_table' where='datetime BETWEEN $$2017-05-10T00:00:00.000Z$$::timestamp AND $$2017-06-21T00:00:00.000Z$$::timestamp AND ST_Intersects(rast, ST_Transform(ST_GeomFromText($$POLYGON((-8.463592529296875 51.96203858429277,-8.466339111328127 51.712565159815114,-7.568206787109377 51.72447619956401,-7.573699951171877 51.97219182433531,-8.463592529296875 51.96203858429277))$$, 4326), 32629))' mode='2'"

diplonics commented Feb 7, 2018

Example below of how I got around this issue using double dollar signs for the date and geomfromtext query elements:

DATA "PG:host=localhost user='some_user' password='some_password' dbname='some_db' port=5432 schema='public' table='some_table' where='datetime BETWEEN $$2017-05-10T00:00:00.000Z$$::timestamp AND $$2017-06-21T00:00:00.000Z$$::timestamp AND ST_Intersects(rast, ST_Transform(ST_GeomFromText($$POLYGON((-8.463592529296875 51.96203858429277,-8.466339111328127 51.712565159815114,-7.568206787109377 51.72447619956401,-7.573699951171877 51.97219182433531,-8.463592529296875 51.96203858429277))$$, 4326), 32629))' mode='2'"

@diplonics

This comment has been minimized.

Show comment
Hide comment
@diplonics

diplonics Feb 7, 2018

Leading on from this, maybe another question, but is there a syntax where I can pass a FILTER into the where clause of the DATA element in a mapfile. I know how to do it in the standard setup where DATA defines the geom and table and the FILTER defines the where elements which can be attached to variables passed to the mapfile.
However, after numerous efforts searching and working/guessing how the DATA string is defined such that it accepts a FILTER I still haven't got anything to work properly.

I'm looking for advice on mapfile setup trying to take WMS filters from Openlayers and using them to control the date period and extent of the raster returns. I've got date and extent where element working in the DATA string as per the previous posts example but don't know a syntax to add dynamic query elements being passed into the where element.
The following just returns the whole raster table but I'd like the FILTER to be applied as the WHERE and the %area% to be a filter element coming from Openlayers in a GeomFromText format?
VALIDATION "area" "^[a-zA-Z0-9-.,() ]*$" END DATA "PG:host=localhost user='some_user' password='some_password' dbname='some_db' port=5432 schema='public' table='some_table' mode='2'" FILTER (datetime BETWEEN $$2017-05-10T00:00:00.000Z$$::timestamp AND $$2017-06-21T00:00:00.000Z$$::timestamp AND ST_Intersects(rast, ST_Transform(ST_GeomFromText($$%area%$$, 4326), 32629)))

diplonics commented Feb 7, 2018

Leading on from this, maybe another question, but is there a syntax where I can pass a FILTER into the where clause of the DATA element in a mapfile. I know how to do it in the standard setup where DATA defines the geom and table and the FILTER defines the where elements which can be attached to variables passed to the mapfile.
However, after numerous efforts searching and working/guessing how the DATA string is defined such that it accepts a FILTER I still haven't got anything to work properly.

I'm looking for advice on mapfile setup trying to take WMS filters from Openlayers and using them to control the date period and extent of the raster returns. I've got date and extent where element working in the DATA string as per the previous posts example but don't know a syntax to add dynamic query elements being passed into the where element.
The following just returns the whole raster table but I'd like the FILTER to be applied as the WHERE and the %area% to be a filter element coming from Openlayers in a GeomFromText format?
VALIDATION "area" "^[a-zA-Z0-9-.,() ]*$" END DATA "PG:host=localhost user='some_user' password='some_password' dbname='some_db' port=5432 schema='public' table='some_table' mode='2'" FILTER (datetime BETWEEN $$2017-05-10T00:00:00.000Z$$::timestamp AND $$2017-06-21T00:00:00.000Z$$::timestamp AND ST_Intersects(rast, ST_Transform(ST_GeomFromText($$%area%$$, 4326), 32629)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment