When we bind the in clause with an empty collection this results in a SQL exception.
Instead it should be treated as "match nothing".
Consider this:
ArrayList() options = new ArrayList();Ebean.find(User.class).where().in("name", options).findList();
Since the collection is empty, no value is provided for the "in (?)"phrase and the DB throws an error. This requires us to break out thequery to a variable and do this:
if (options.size() > 0) query.where().in(options);
I'd like to request a feature enhancement where the in phrase isomitted if the collection is empty.
/Daryl
Hi!
considering an empty list as "match everything" is not the right thingto do - or at least it is application specific bahviour and thusshould not be added to the standard ebean api.
If you do "select * from xyz where prop in ()" this too will notresult in an list of all records of "xyz". Depending on the databaseyou will get an sql error or nothing.
The standard behaviour for an empty list is "match nothing". I am notsure if there exists a standard sql syntax to describe an empty liston the right side of the "in" operator. AFAIK this depends on thedatabase.
You have to query your options list (as you do) and decide if youreturn an empty list or omit the phrase and return everything, butthis depends on your needs.
Ciao,Mario
Well we don't want to generate a SQL exception so that's a bug (I'll logit).
>> The standard behaviour for an empty list is "match nothing".
I think we are all in agreement that we should get "match nothing". Sogenerating 1=0 is what we should do here for an empty collection in the "in"clause.
Fixed in HEAD.