php Mapscript queryByAttributes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

php Mapscript queryByAttributes

Sven Schroeter
Hi,

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

My Test Script:

$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

Works fine on the old Server, on the new Server no result.

I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";

No result on old server and new...

How can I get it run on MS7?



Thanks + greetings 
Sven
 


**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Carlos Ruiz
Sven,

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

MS4W version is 3.1.3

Try to solve it by using FILTER, which allows more complex expressions:

$layer->setFilter("gid IN (100, 101)");


Cheers

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:


Hi,

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

My Test Script:

$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

Works fine on the old Server, on the new Server no result.

I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";

No result on old server and new...

How can I get it run on MS7?



Thanks + greetings 
Sven
 


**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
www.netgis.de


_______________________________________________
mapserver-users mailing list

_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Lime, Steve D (MNIT)

The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:

 

  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

 

is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.

 

  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

 

is evaluated as gid = 100 which makes sense.

 

  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

 

is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.

 

  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

 

like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…

 

  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

 

the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.

 

  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

 

This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

 

Steve

 

From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes

 

Sven,

 

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

 

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

 

MS4W version is 3.1.3

 

Try to solve it by using FILTER, which allows more complex expressions:

 

$layer->setFilter("gid IN (100, 101)");

 

 

Cheers

 

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:

 

 

Hi,

 

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)

New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

 

My Test Script:

 

$qfield = 'gid';

$qstring = "gid IN (1,2,3)";

@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

 

Works fine on the old Server, on the new Server no result.

 

I have tried to change the query expression, i.e.:

$qstring = "('[gid]' in '1,2,3')";

 

No result on old server and new...

 

How can I get it run on MS7?

 

 

 

Thanks + greetings 

Sven

 

 

 

**************************************

NETGIS GbR

Benediktinerstr. 32a

54292 Trier

Tel.: 0651-1704731

Fax: 0651-1704733

 

 

_______________________________________________

mapserver-users mailing list


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Lime, Steve D (MNIT)
In reply to this post by Sven Schroeter
Try:

  $qfield = 'gid';
  $qstring = "([gid] IN '1,2,3')";
  @$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

I'm guessing the layer in question is PostGIS? In older versions of MapServer the query string could be given in the native SQL language of underlying driver. In 7.0 there was some expression normalization work done where expressions and filters are given in MapServer expression syntax and then converted to native SQL. It's possible that you've hit an example where the translation isn't working as it should.

Steve

-----Original Message-----
From: mapserver-users [mailto:[hidden email]] On Behalf Of Sven Schroeter
Sent: Wednesday, October 11, 2017 10:46 AM
To: [hidden email]
Subject: [mapserver-users] php Mapscript queryByAttributes

Hi,

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

My Test Script:

$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

Works fine on the old Server, on the new Server no result.

I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";

No result on old server and new...

How can I get it run on MS7?



Thanks + greetings 
Sven
 


**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Carlos Ruiz
In reply to this post by Lime, Steve D (MNIT)
Hey Steve,

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be
> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1


On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:

 

  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

 

is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.

 

  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

 

is evaluated as gid = 100 which makes sense.

 

  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

 

is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.

 

  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

 

like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…

 

  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

 

the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.

 

  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

 

This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

 

Steve

 

From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes

 

Sven,

 

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

 

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

 

MS4W version is 3.1.3

 

Try to solve it by using FILTER, which allows more complex expressions:

 

$layer->setFilter("gid IN (100, 101)");

 

 

Cheers

 

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:

 

 

Hi,

 

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)

New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

 

My Test Script:

 

$qfield = 'gid';

$qstring = "gid IN (1,2,3)";

@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

 

Works fine on the old Server, on the new Server no result.

 

I have tried to change the query expression, i.e.:

$qstring = "('[gid]' in '1,2,3')";

 

No result on old server and new...

 

How can I get it run on MS7?

 

 

 

Thanks + greetings 

Sven

 

 

 

**************************************

NETGIS GbR

Benediktinerstr. 32a

54292 Trier

Tel.: 0651-1704731

Fax: 0651-1704733

 

 

_______________________________________________

mapserver-users mailing list


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Carlos Ruiz
Regex worked as a LIKE workaround. The backend database is PostgreSQL 9.5.9.


On Wednesday, October 11, 2017, 4:28:27 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


What’s the backend database – it’s possible the IN operator is screwy for that driver? For the LIKE operator I should have remembered that MapServer doesn’t support that operator, try a regex instead:

 

  queryByAttributes("municipio", "(‘[municipio]’ ~ 'G.*')", MS_MULTIPLE);

 

Steve

 

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Wednesday, October 11, 2017 4:03 PM
To: [hidden email]; Sven Schroeter <[hidden email]>; Lime, Steve D (MNIT) <[hidden email]>
Subject: Re: RE: [mapserver-users] php Mapscript queryByAttributes

 

Hey Steve,

 

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

 

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

 

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be

> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

 

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

 

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1

 

 

On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:

 

 

The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:

 

  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

 

is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.

 

  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

 

is evaluated as gid = 100 which makes sense.

 

  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

 

is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.

 

  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

 

like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…

 

  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

 

the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.

 

  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

 

This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

 

Steve

 

From: mapserver-users [[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes

 

Sven,

 

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

 

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

 

MS4W version is 3.1.3

 

Try to solve it by using FILTER, which allows more complex expressions:

 

$layer->setFilter("gid IN (100, 101)");

 

 

Cheers

 

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:

 

 

Hi,

 

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)

New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

 

My Test Script:

 

$qfield = 'gid';

$qstring = "gid IN (1,2,3)";

@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

 

Works fine on the old Server, on the new Server no result.

 

I have tried to change the query expression, i.e.:

$qstring = "('[gid]' in '1,2,3')";

 

No result on old server and new...

 

How can I get it run on MS7?

 

 

 

Thanks + greetings 

Sven

 

 

 

**************************************

NETGIS GbR

Benediktinerstr. 32a

54292 Trier

Tel.: 0651-1704731

Fax: 0651-1704733

 

 

_______________________________________________

mapserver-users mailing list


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Sven Schroeter
In reply to this post by Carlos Ruiz
Hi Steve and Carlos,

thanks for your support.

When I understand it correctly, I can not use the IN operator in conjunction with queryByAttributes in Mapserver 7 (mapscript) ?
I use this function so far for the transfer of different IDs (whether integer or string) to read out a subset of POSTGIS tables.
I have now tried the following and it works:

$qstring = "([gid] = '1' || [gid] = '2' || [gid] = '4' || [gid] = '11')";
$query_layer->queryByAttributes("gid",$qstring,MS_MULTIPLE);

Maybe it is possible to get the IN operator back in the future?

Sven


Von: Lime, Steve D (MNIT) [mailto:[hidden email]]
Gesendet: Mittwoch, 11. Oktober 2017 23:33
An: Carlos Ruiz; [hidden email]; Sven Schroeter
Betreff: RE: RE: [mapserver-users] php Mapscript queryByAttributes

Ugh, my bad. At least with the LIKE operator it’s because MapServer doesn’t support it. Using a regex should work depending on your back-end. Which reminds me, which backend are you using? I need to investigate the IN operator. It maybe that I can come up with a work around for Sven using the native SQL that worked previously since that can still be set as a processing option. Will report back…

Steve

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Wednesday, October 11, 2017 4:03 PM
To: [hidden email]; Sven Schroeter <[hidden email]>; Lime, Steve D (MNIT) <[hidden email]>
Subject: Re: RE: [mapserver-users] php Mapscript queryByAttributes

Hey Steve,

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be
> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1


On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:
 
  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
 
is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.
  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
 
is evaluated as gid = 100 which makes sense.
 
  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
 
is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.
 
  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
 
like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…
 
  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
 
the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.
 
  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
 
This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);
 
Steve
 
From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes
 
Sven,
 
Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).
 
queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results
 
MS4W version is 3.1.3
 
Try to solve it by using FILTER, which allows more complex expressions:
 
$layer->setFilter("gid IN (100, 101)");
 
 
Cheers
 
On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:
 
 
Hi,
 
Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)
 
My Test Script:
 
$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);
 
Works fine on the old Server, on the new Server no result.
 
I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";
 
No result on old server and new...
 
How can I get it run on MS7?
 
 
 
Thanks + greetings
Sven
 
 
 
**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de
 
 
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users

_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Lime, Steve D (MNIT)
I'll create a ticket...

Another approach would be to use the NATIVE_FILTER processing key at the layer level. This allows you to write a filter in native SQL. I believe you can set and unset processing keys in mapscript. Code would be something like (in perl):

  $layer->{processing}->set("NATIVE_FILTER", "gid IN (1,2,3)");
  $query_layer->queryByAttributes("gid", "(1=1)");
  $layer->{processing}->remove("NATIVE_FILTER");

That should result in a query like ... gid IN (1,2,3) AND 1=1 being executed.

Steve

-----Original Message-----
From: Sven Schroeter [mailto:[hidden email]]
Sent: Thursday, October 12, 2017 8:05 AM
To: Lime, Steve D (MNIT) <[hidden email]>; 'Carlos Ruiz' <[hidden email]>; [hidden email]
Subject: AW: RE: [mapserver-users] php Mapscript queryByAttributes

Hi Steve and Carlos,

thanks for your support.

When I understand it correctly, I can not use the IN operator in conjunction with queryByAttributes in Mapserver 7 (mapscript) ?
I use this function so far for the transfer of different IDs (whether integer or string) to read out a subset of POSTGIS tables.
I have now tried the following and it works:

$qstring = "([gid] = '1' || [gid] = '2' || [gid] = '4' || [gid] = '11')";
$query_layer->queryByAttributes("gid",$qstring,MS_MULTIPLE);

Maybe it is possible to get the IN operator back in the future?

Sven


Von: Lime, Steve D (MNIT) [mailto:[hidden email]]
Gesendet: Mittwoch, 11. Oktober 2017 23:33
An: Carlos Ruiz; [hidden email]; Sven Schroeter
Betreff: RE: RE: [mapserver-users] php Mapscript queryByAttributes

Ugh, my bad. At least with the LIKE operator it’s because MapServer doesn’t support it. Using a regex should work depending on your back-end. Which reminds me, which backend are you using? I need to investigate the IN operator. It maybe that I can come up with a work around for Sven using the native SQL that worked previously since that can still be set as a processing option. Will report back…

Steve

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Wednesday, October 11, 2017 4:03 PM
To: [hidden email]; Sven Schroeter <[hidden email]>; Lime, Steve D (MNIT) <[hidden email]>
Subject: Re: RE: [mapserver-users] php Mapscript queryByAttributes

Hey Steve,

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be
> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1


On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:
 
  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
 
is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.
  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
 
is evaluated as gid = 100 which makes sense.
 
  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
 
is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.
 
  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
 
like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…
 
  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
 
the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.
 
  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
 
This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);
 
Steve
 
From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes
 
Sven,
 
Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).
 
queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results
 
MS4W version is 3.1.3
 
Try to solve it by using FILTER, which allows more complex expressions:
 
$layer->setFilter("gid IN (100, 101)");
 
 
Cheers
 
On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:
 
 
Hi,
 
Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)
 
My Test Script:
 
$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);
 
Works fine on the old Server, on the new Server no result.
 
I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";
 
No result on old server and new...
 
How can I get it run on MS7?
 
 
 
Thanks + greetings
Sven
 
 
 
**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de
 
 
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users

_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Carlos Ruiz
In reply to this post by Sven Schroeter
Sven,

This is a good workarround. It's weird why the IN operator is not working for Postgres but as Steve wrote, a ticket will be opened.

On Thursday, October 12, 2017, 8:04:46 AM CDT, Sven Schroeter <[hidden email]> wrote:


Hi Steve and Carlos,

thanks for your support.

When I understand it correctly, I can not use the IN operator in conjunction with queryByAttributes in Mapserver 7 (mapscript) ?
I use this function so far for the transfer of different IDs (whether integer or string) to read out a subset of POSTGIS tables.
I have now tried the following and it works:

$qstring = "([gid] = '1' || [gid] = '2' || [gid] = '4' || [gid] = '11')";
$query_layer->queryByAttributes("gid",$qstring,MS_MULTIPLE);

Maybe it is possible to get the IN operator back in the future?

Sven


Von: Lime, Steve D (MNIT) [mailto:[hidden email]]
Gesendet: Mittwoch, 11. Oktober 2017 23:33
An: Carlos Ruiz; [hidden email]; Sven Schroeter
Betreff: RE: RE: [mapserver-users] php Mapscript queryByAttributes

Ugh, my bad. At least with the LIKE operator it’s because MapServer doesn’t support it. Using a regex should work depending on your back-end. Which reminds me, which backend are you using? I need to investigate the IN operator. It maybe that I can come up with a work around for Sven using the native SQL that worked previously since that can still be set as a processing option. Will report back…

Steve

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Wednesday, October 11, 2017 4:03 PM
To: [hidden email]; Sven Schroeter <[hidden email]>; Lime, Steve D (MNIT) <[hidden email]>
Subject: Re: RE: [mapserver-users] php Mapscript queryByAttributes

Hey Steve,

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be
> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1


On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:

  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.
  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

is evaluated as gid = 100 which makes sense.

  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.

  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…

  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.

  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

Steve

From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes

Sven,

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

MS4W version is 3.1.3

Try to solve it by using FILTER, which allows more complex expressions:

$layer->setFilter("gid IN (100, 101)");


Cheers

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:


Hi,

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

My Test Script:

$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

Works fine on the old Server, on the new Server no result.

I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";

No result on old server and new...

How can I get it run on MS7?



Thanks + greetings
Sven



**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users

_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: php Mapscript queryByAttributes

Lime, Steve D (MNIT)

Ticket is https://github.com/mapserver/mapserver/issues/5490... --Steve

 

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Thursday, October 12, 2017 12:55 PM
To: Lime, Steve D (MNIT) <[hidden email]>; [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: AW: RE: [mapserver-users] php Mapscript queryByAttributes

 

Sven,

 

This is a good workarround. It's weird why the IN operator is not working for Postgres but as Steve wrote, a ticket will be opened.

 

On Thursday, October 12, 2017, 8:04:46 AM CDT, Sven Schroeter <[hidden email]> wrote:

 

 

Hi Steve and Carlos,

thanks for your support.

When I understand it correctly, I can not use the IN operator in conjunction with queryByAttributes in Mapserver 7 (mapscript) ?
I use this function so far for the transfer of different IDs (whether integer or string) to read out a subset of POSTGIS tables.
I have now tried the following and it works:

$qstring = "([gid] = '1' || [gid] = '2' || [gid] = '4' || [gid] = '11')";
$query_layer->queryByAttributes("gid",$qstring,MS_MULTIPLE);

Maybe it is possible to get the IN operator back in the future?

Sven


Von: Lime, Steve D (MNIT) [mailto:[hidden email]]
Gesendet: Mittwoch, 11. Oktober 2017 23:33
An: Carlos Ruiz; [hidden email]; Sven Schroeter
Betreff: RE: RE: [mapserver-users] php Mapscript queryByAttributes

Ugh, my bad. At least with the LIKE operator it’s because MapServer doesn’t support it. Using a regex should work depending on your back-end. Which reminds me, which backend are you using? I need to investigate the IN operator. It maybe that I can come up with a work around for Sven using the native SQL that worked previously since that can still be set as a processing option. Will report back…

Steve

From: Carlos Ruiz [mailto:[hidden email]]
Sent: Wednesday, October 11, 2017 4:03 PM
To: [hidden email]; Sven Schroeter <[hidden email]>; Lime, Steve D (MNIT) <[hidden email]>
Subject: Re: RE: [mapserver-users] php Mapscript queryByAttributes

Hey Steve,

> the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace > is considered part of the tokens in a list.

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("gid"'100,101')

> This is close, it’s a logical expression but you’re comparing a number against a string. It should be
> queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

I have tried this and it doesn't work. There's a query error because Mapserver try to add the following: and ("municipio"::text'G%')

Maybe this happens because the MS4W version (3.1.3) with Mapserver CGI 7.0.1


On Wednesday, October 11, 2017, 2:31:41 PM CDT, Lime, Steve D (MNIT) <[hidden email]> wrote:


The query syntax is given in MapServer expression syntax. I think there’s a logical expression for why you’re seeing these results:

  queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything

is evaluated as gid = “gid > 100”. Valid but not what you’re looking for. Your last example is the right way to do it - queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE);. If MapServer sees the qstring is a logical expression then it ignores the qitem.
  queryByAttributes("gid", "100", MS_MULTIPLE) // found one result

is evaluated as gid = 100 which makes sense.

  queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result

is evaluated as municipio = GUADALAJARA which makes sense. I don’t think you need the interior quotes around GUADALAJARA though.

  queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything

like the first example this evaluates as municipio = "municipio LIKE 'G%'", not what you want. See below…

  queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error

the IN operator works off a delimited list, try queryByAttributes("gid", "([gid] IN ‘100,101’)", MS_MULTIPLE);. Any whitespace is considered part of the tokens in a list.

  queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error

This is close, it’s a logical expression but you’re comparing a number against a string. It should be queryByAttributes("municipio", "(‘[municipio]’ LIKE 'G%')", MS_MULTIPLE);

Steve

From: mapserver-users [mailto:[hidden email]] On Behalf Of Carlos Ruiz
Sent: Wednesday, October 11, 2017 1:36 PM
To: [hidden email]; Sven Schroeter <[hidden email]>
Subject: Re: [mapserver-users] php Mapscript queryByAttributes

Sven,

Doing some tests, queryByAttributes does not accept LIKE nor IN, just single values or simple operators (I am using PostGIS).

queryByAttributes("gid", "gid > 100", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "100", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "'GUADALAJARA'", MS_MULTIPLE) // found one result
queryByAttributes("municipio", "municipio LIKE 'G%'", MS_MULTIPLE) // does not found anything
queryByAttributes("gid", "([gid] IN (100, 101))", MS_MULTIPLE); // query error
queryByAttributes("municipio", "([municipio] LIKE 'G%')", MS_MULTIPLE); // query error
queryByAttributes("gid", "([gid] > 100)", MS_MULTIPLE); // found 25 results

MS4W version is 3.1.3

Try to solve it by using FILTER, which allows more complex expressions:

$layer->setFilter("gid IN (100, 101)");


Cheers

On Wednesday, October 11, 2017, 10:55:17 AM CDT, Sven Schroeter <[hidden email]> wrote:


Hi,

Old Server: PHP 5.4.36 with MS 6.4.1 (MS4W)
New Server: PHP 5.6.31 with MS 7.0.6 (MS4W 3.2.2)

My Test Script:

$qfield = 'gid';
$qstring = "gid IN (1,2,3)";
@$datQuery = $query_layer->queryByAttributes($qfield,$qstring,MS_MULTIPLE);

Works fine on the old Server, on the new Server no result.

I have tried to change the query expression, i.e.:
$qstring = "('[gid]' in '1,2,3')";

No result on old server and new...

How can I get it run on MS7?



Thanks + greetings
Sven



**************************************
NETGIS GbR
Benediktinerstr. 32a
54292 Trier
Tel.: 0651-1704731
Fax: 0651-1704733
[hidden email]
www.netgis.de


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users