novoda/sqlite-analyzer

Allow duplicated column names

ouchadam opened this issue · 7 comments

At the moment, views are forced to SELECT DISTINCT and manually select columns when duplicated names are found, such as _id

These duplicated columns should reuse the existing getters/setters and fields

@ouchadam Could you please elaborate?
We'd need some more description of the the current behaviour and why you consider it buggy.

when two tables are joined together with the same column names eg _id then the generated DB class has two fields/getters/setters with the same name causing a compilation error

I would consider it a bug because it's not noted anywhere that selecting the specific columns is required

Ah, okay. How would you deal with that ambiguity then?

Seems that sqlite de-duplicates names appending :1, :2 ....
These parts are discarded by the analyzer in com.novoda.sqlite.StringUtil#camelify. Some more robust parsing here could prevent that. That said, I think using duplicate names is asking for trouble. Seems that other databases prohibit that straight away, see http://stackoverflow.com/questions/7493566/sqlite-prevents-duplicate-column-names-in-my-view

Since sqlite permits it the analyzer should probably not prevent it though.

I agree using duplicate column names is bad practice but forcing clients to select every column to avoid including two (or more) _id is a bit annoying 😢

How would you feel about keeping :1 etc?
Or would it be possible to append the table name instead? _id_table1 _id_table2

I definitely see your point. 👍

I'll look into keeping the :1 and appending _1 to the respective column name variable. Currently, that does not work due to some implementation limitations that we can work on.

fixed with #45