Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GQL disallowed literal error, google datastore

I am trying to use GQL to get some data back from the datastore.

When I do a SELECT * FROM Kind request, it works and I get data back.

However when I try:

SELECT * FROM kind where num < 1234

I get a disallowed literal error.

I even tried to do it with quotations:

SELECT * FROM kind where num < '1234'

but I get the same error.

Has anyone run into this before?

Here is the code:

Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY,             
          "SELECT * FROM " + kind + " WHERE num < '100'"
          ).build();
  QueryResults<Entity> results = datastore.run(query);
  while (results.hasNext()) {
    Entity result = results.next();
   myList.add(result.getString("num"));
like image 874
A Ba Avatar asked Oct 18 '22 07:10

A Ba


1 Answers

You need to bind the query parameter rather than directly adding it into the query.

Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY,             
                          "SELECT * FROM " + kind + " WHERE num < @num")
                      .setBinding("num", 100)
                      .build();
QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
    Entity result = results.next();
    myList.add(result.getString("num"));
...
like image 171
Dan McGrath Avatar answered Oct 21 '22 04:10

Dan McGrath