GQL error on WHERE

隐身守侯 提交于 2019-12-24 21:36:50

问题


select from comments.Comment 
where ownerType == 'looks.Look' 
AND ownerName == 'Yakuza' order by date

I get exception:

Portion of expression could not be parsed: AND ownerName == 'Yakuza'

While this query works nice:

select from comments.Comment 
where ownerType == 'looks.Look' 
order by date

And this too:

select from comments.Comment 
where ownerName == 'Yakuza' order by date

The full code:

PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "... query goes here ...";
List<Comment> comments = null;
try {
    comments = (List<Comment>) pm.newQuery(query).execute();
}
...

回答1:


Replace "AND" with "&&"

  PersistenceManager pm = PMF.get().getPersistenceManager();
  try {
    Query query = pm.newQuery("select from " + Song.class.getName()
        + " where mArtist== '" +artist+
        "' &&  mTitle=='"+title+
        "' &&  mAlbum=='"+album+"'" );
    List<Song> list = (List<Song>) query.execute();
  } catch (RuntimeException e) {
    System.out.println(e);
    throw e;
  } finally {
    pm.close();
  }


来源:https://stackoverflow.com/questions/4903474/gql-error-on-where

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!