Closed ssardina closed 5 years ago
org.jpl7.Util
has
public static Term textParamsToTerm(String text, Term[] params)
which does this (or is intended to).
NB Query1 is dubiously overloaded: if text
merely denotes an atom, it builds a Compound.
mmm yes you are right, Util.textParamsToTerm(String text, Term[] params)
hsa that already. In fact, Query1
uses it (well its non params version) and then injects the params into the ? placeholders...
Now this is interesting... It seems to me we would like to get rid of Query1
and use the already existing tool in org.jpl7.Util
.
As you said Query1
seems to be "careful" and transform a text Atom into a Compound, but textParamsToTerm
should handle or we should make it to handle that.
In the end, we would like to write Query
without using Query1
, that is ,we want:
public Query(String text, Term[] args) {
this(Util.textParamsToTerm(text, args));
}
so the strange case would be that text
is not a compound text with placeholders ?
, but just an atom and you do pass arguments...
presumably you should have as many arguments as ? in text. There must be an error otherwise...
OK all tested. and is good:
Query1
public as there is Util.textParamsToTerm(text, args)
available.Query1
is still needed to allow building queries in two ways:
Query1
generates a corresponding Term as needed depending on input of text
. Query1
has been renamed to buildQueryTerm
org.jpl7.test.standalone.QueryBuilder
to test all possible ways of building a Query and all possible exceptions that can be thrown.All this is in commit 2507f1b73c06a46646ec994d6eab62687b85ea69
Hi,
Class
Query.java
has a useful public method to convert a string with args into a Term:Would be very nice to have this as a public method as it is useful to get the term itself, not just the whole query. And maybe rename it to
queryBuilder
or something?Can this be done? It is a small change and would help, otherwise I need to replicate that code in my framework.
Thanks in advance,
Sebastian