views:

62

answers:

1

Our application provides multiple query interfaces that are basically just text inputs. Is there a best practice on whether the backend logic should be pad the query parameter with wildcards then perform a like or should it just do an equals. Of course another option would be to allow user's to use wildcards and then check and use a "like" if appropriate.

I understand the performance implication of using a wildcard like this and that this could be viewed as a subject question, I just want to know if there is a standard practice.

+2  A: 

This is something I would leave up to the user, allowing then to actually make a choice. All the UIs I've seen for allowing user-specified conditions have:

  • the column to check.
  • a drop-down box containing the relationship, such as equal to, not equal to, less than, greater than, starts with.
  • the value you want to compare to.

Then, for the starts with option, you just tack on % and use like.

You'll note (for performance reasons which you seem to already understand) I used starts with rather than like to limit the possibility of dragging down the database performance.

I'm not a big fan of unrestricted like statements although you could also provide ends with for those DBMS' capable of storing reversed indexes.

paxdiablo
You'd use aligator brackets for string comparison?
OMG Ponies
Depends on the users. To be honest, I'd probably have `not equal to` (and textual representations for all the others as well) since they may understand neither `<>` nor `!=`.
paxdiablo
Good point on the !=
OMG Ponies