You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Stephen Allen <sa...@apache.org> on 2013/04/02 17:49:19 UTC

Re: Templated queries and updates

On Sun, Mar 24, 2013 at 2:37 PM, Andy Seaborne <an...@apache.org> wrote:
...
> My suggestion is to have template queries, which are like, but not
> identical, to JDBC prepared statements.  A template query is a superset of
> SPARQL. Template parameterization is via a new parse item, not a legal
> SPARQL variable (e.g. ?{abc}).  They must be replaced by a node (which could
> be a real variable) to use them.  There would
> template.asQuery(..substitutions...).
>
> An alternative was using SPARQL variables, requiring a query/update template
> to declare the template variables and checking when converting to a query or
> update.  But, as below, there are a couple of points where it is desirable
> to parameterize a template that in SPARQL do not allow variables.  If we're
> tweaking the syntax anyway, we might as well have template variable syntax.
>
> The reason for some checking is so you can't do "SELECT * { ?s ?p ?o }"
> forgetting to replace ?s with a URI, for example.
...

I have been using ParameterizedSparqlString pretty heavily lately for
parameterization, and one of the main issues is exactly this,
forgetting to set the variable.  Perhaps this is mostly occurring
because paramString.setIri("foo", null) will clear that parameter.
And some of the legacy code is accidentally passing in nulls for some
of the parameters I wish to set.

One fix would be to make .setXXX() throw a NullPointerException if
null is passed in, and the user must use a .clear() method to
explicitly clear previously set parameters.  However, this still
doesn't help the case where the user just forgot to set a parameter.
I rather like Andy's suggestion of new syntax for templates.  That way
the query won't parse unless you fill in all the parameters.  Also
going beyond simple text matching will allow it to not change comments
or even literals that happen to contain a template (imagine storing
some of your templated queries in the store itself).

I also agree that we should focus on pre-binding and not try to turn
this into prepared statements.

-Stephen