On 6 April 2013 10:27, Bruno Zerbo <[email protected]> wrote:
> hi,
> I'm working with an app that makes some query to a postgres db.
> I tried the following query with pgadmin and it works while thought the c++
> code I have a runtime error.
> This is the code:
>
> using namespace soci;
> Edge edge;
> soci::session sql(postgresql, "hostaddr=127.0.0.1 user=postgres
> password=aurali port=5432 dbname=routing");
>
> sql << "SELECT gid, source, target, the_geom, name,ST_Distance(the_geom,
> ST_GeometryFromText('POINT(15.1118 37.5667)', 4326)) AS dist FROM ways WHERE
> the_geom && setsrid('BOX3D(15.0118 37.4667, 15.2118 37,6667)'::box3d, 4326)
> ORDER BY dist LIMIT 1"
> , into(edge.gid), into(edge.source),
> into(edge.target), into(edge.the_geom),
> into(edge.name);
I can confirm this is a valid PostgreSQL/PostGIS query.
> the application gives my the following error:
>
> "Wt: fatal error: ERROR: syntax error at or near ""$1""
> LINE 1: ...etsrid('BOX3D(15.0118 37.4667, 15.2118 37,6667)'::$1, 4326) ...
>
> the error is given in place of $1 that in the query is ::box3d. Why? there
> was this traslation?
I haven't tested your query in action, but I suppose there may be conflict
between casting operators and how SOCI parses query to handle
placeholders bound by name:
http://soci.sourceforge.net/doc/3.2.0/exchange.html#bind_name
> Maybe is the double colons that gives the problem? How
> I can fix? How to pass a colon in the sql string?
Can you try the alternative [1], SQL conformant, syntax for the cast:
SetSRID(CAST('BOX3D(15.0118 37.4667, 15.2118 37,6667)' AS box3d), 4326)
[1]
http://www.postgresql.org/docs/9.1/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users