4

I'm working on a servlet in Google App Engine. This servlet retrieves the data from the GAE's datastore; everything works fine when querying like "SELECT * FROM...". But when I want to filter it by a certain column, it does not work since the name of the column has a hypen. It is like the following:

Query query = new Query("tableName");
query.addFilter("col-name", Query.FilterOperator.EQUAL, filterValue);

How do I pass the propertyName with a hyphen?

David Underhill
  • 15,896
  • 7
  • 53
  • 61
Pablo
  • 81
  • 1
  • 3
  • This should work fine - what happens when you try it? – Nick Johnson Dec 24 '09 at 19:11
  • 1
    It does not return any row. For example, if I filter by a column called "field-1", it is kind of I was trying to subtract 1 from every returned value of the column called field... – Pablo Dec 26 '09 at 10:29
  • And what happens if you do the filtering in the original Gql call? – raphink Dec 28 '09 at 12:02
  • Raphink, it returns an error :( I am not able to filter by a 'hyphened' column on the GQL call... – Pablo Dec 29 '09 at 07:23

3 Answers3

1

java only accepts letters and digits the dollar sign "$", or the underscore character "_" like legal identifiers. So i believe that's not posible. Also did't work in python

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html#naming

Kristian Damian
  • 1,360
  • 3
  • 22
  • 43
  • Thanks for your comment Kristian, but I was talking about the name of the column in the database. – Pablo Dec 29 '09 at 07:21
1

The AppEngine datastore doesn't have rows or columns; it has models and properties.

The Defining Data Classes talks about defining your models; the important thing to note is that the Java rules for identifier names matter, because each property of a model will at some point be turned into a java object with the same name.

You've described this yourself:

if I filter by a column called "field-1", it is kind of I was trying to subtract 1 from every returned value of the column called field

James Polley
  • 7,977
  • 2
  • 29
  • 33
0

Is the addFilter method correctly enclosing the column name in single quotes? You might want to try adding them yourself. One can filter by things which are not keys in the database in GQL so this might be something that is expected of you.

Clueless
  • 3,984
  • 1
  • 20
  • 27