Problem with Propertyname "order" #31

Closed
sebastiandeutsch opened this Issue Apr 17, 2012 · 10 comments

Comments

Projects
None yet
4 participants
@sebastiandeutsch

When you add

entity.addIntProperty("order");

it will generate some code without any errors. Unfortunately the SQL generated by the querybuilder will throw an Exception since ORDER is a reserved keyword. Maybe greenDAO should throw an Exception in the generator when a reserved word is used.

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot Apr 17, 2012

Owner

This is weird, because I have unit tests for special property/column names. Also for QueryBuilder:
https://github.com/greenrobot/greenDAO/blob/master/DaoTest/src/de/greenrobot/daotest/query/QuerySpecialNamesTest.java

However, I did not test "order" yet...

Owner

greenrobot commented Apr 17, 2012

This is weird, because I have unit tests for special property/column names. Also for QueryBuilder:
https://github.com/greenrobot/greenDAO/blob/master/DaoTest/src/de/greenrobot/daotest/query/QuerySpecialNamesTest.java

However, I did not test "order" yet...

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot Apr 17, 2012

Owner

I just added an "order" property to those unit tests. It seems your use case is different and the current unit test do not cover it. Could you supply more info on your case, e.g. your query, the generated SQL, and the exception? Thanks.

Owner

greenrobot commented Apr 17, 2012

I just added an "order" property to those unit tests. It seems your use case is different and the current unit test do not cover it. Could you supply more info on your case, e.g. your query, the generated SQL, and the exception? Thanks.

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot Apr 24, 2012

Owner

I added another unit test (5aa643c), but still cannot reproduce this error. Please let me know your query leading to the error. Without being able to reproduce, I'd have to close the issue otherwise.

Owner

greenrobot commented Apr 24, 2012

I added another unit test (5aa643c), but still cannot reproduce this error. Please let me know your query leading to the error. Without being able to reproduce, I'd have to close the issue otherwise.

@sebastiandeutsch

This comment has been minimized.

Show comment
Hide comment
@sebastiandeutsch

sebastiandeutsch May 4, 2012

Hi, I've put up an Repository to reproduce the "bug" https://github.com/sebastiandeutsch/OrderBugTestAndGenerator - I understand if you don't fix it, since it's not a real bug, it's more the lameness of SQLite that you cannot escape fieldnames. But maybe you should enlist all reserved words in the docu, or in the FAQ.

Hi, I've put up an Repository to reproduce the "bug" https://github.com/sebastiandeutsch/OrderBugTestAndGenerator - I understand if you don't fix it, since it's not a real bug, it's more the lameness of SQLite that you cannot escape fieldnames. But maybe you should enlist all reserved words in the docu, or in the FAQ.

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot May 5, 2012

Owner

Thanks for getting back. I thought you were referring to greenDAO's QueryBuilder class. If it's about using SimpleCursorAdapter, you should try escaping your column names with a single quote, e.g. 'order' instead of order.

That's what QueryBuilder is doing and the unit tests seem to run correctly.

Owner

greenrobot commented May 5, 2012

Thanks for getting back. I thought you were referring to greenDAO's QueryBuilder class. If it's about using SimpleCursorAdapter, you should try escaping your column names with a single quote, e.g. 'order' instead of order.

That's what QueryBuilder is doing and the unit tests seem to run correctly.

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot Jun 7, 2012

Owner

I guess the question is whether to have column names wrapped inside single quotes somewhere in Properties.

Owner

greenrobot commented Jun 7, 2012

I guess the question is whether to have column names wrapped inside single quotes somewhere in Properties.

@gauthierm

This comment has been minimized.

Show comment
Hide comment
@gauthierm

gauthierm Jan 5, 2015

Using a field named "order" as an order field in a to-many relationship breaks because it is not quoted. See https://github.com/greenrobot/greenDAO/blob/master/DaoGenerator/src/de/greenrobot/daogenerator/PropertyOrderList.java#L67

Anywhere columns are put into generated SQL, they should be escaped using a method.

Using a field named "order" as an order field in a to-many relationship breaks because it is not quoted. See https://github.com/greenrobot/greenDAO/blob/master/DaoGenerator/src/de/greenrobot/daogenerator/PropertyOrderList.java#L67

Anywhere columns are put into generated SQL, they should be escaped using a method.

@gauthierm

This comment has been minimized.

Show comment
Hide comment
@gauthierm

gauthierm Jan 5, 2015

I will make a PR to do that if you will merge it.

I will make a PR to do that if you will merge it.

@greenrobot

This comment has been minimized.

Show comment
Hide comment
@greenrobot

greenrobot Jun 28, 2015

Owner

fixed PropertyOrderList in master, no other issues reported by this ticket

Owner

greenrobot commented Jun 28, 2015

fixed PropertyOrderList in master, no other issues reported by this ticket

@greenrobot greenrobot closed this Jun 28, 2015

@greenrobot greenrobot added the Bug label Jun 28, 2015

@greenrobot greenrobot added this to the Next Major milestone Jun 28, 2015

@andrewindayang

This comment has been minimized.

Show comment
Hide comment
@andrewindayang

andrewindayang Apr 24, 2016

I think it is not greendao bug. you can modify that from the JSON. Please check my answer:

http://stackoverflow.com/questions/31120433/using-retrofit-and-greendao-with-nested-json-objects/36789972#36789972

<----SOLUTION------>
//add this to daogenerator and generate the daogenerator
beacon.addStringProperty("order_food"); //Daogenerator

//add this to network manager
//add this into your network manager
FieldNamingStrategy strategy = new FieldNamingStrategy() {
@override
public String translateName(Field field) {
if(field.getName().equalsIgnoreCase("order_food")) {
return "order";
} else {
return field.getName();
}
}
};

//ADD THIS INTO YOUR GSON INSIDE YOUR NETWORK MANAGER
//add this in your Gson

.setFieldNamingStrategy(strategy)

hopefully it helps.

I think it is not greendao bug. you can modify that from the JSON. Please check my answer:

http://stackoverflow.com/questions/31120433/using-retrofit-and-greendao-with-nested-json-objects/36789972#36789972

<----SOLUTION------>
//add this to daogenerator and generate the daogenerator
beacon.addStringProperty("order_food"); //Daogenerator

//add this to network manager
//add this into your network manager
FieldNamingStrategy strategy = new FieldNamingStrategy() {
@override
public String translateName(Field field) {
if(field.getName().equalsIgnoreCase("order_food")) {
return "order";
} else {
return field.getName();
}
}
};

//ADD THIS INTO YOUR GSON INSIDE YOUR NETWORK MANAGER
//add this in your Gson

.setFieldNamingStrategy(strategy)

hopefully it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment