salk31 / RedQueryBuilder

SQL Query Builder UI JavaScript component
http://redquerybuilder.appspot.com/
Eclipse Public License 1.0
95 stars 22 forks source link

Multi select allows no selection but SQL "IN" does not... #2

Closed salk31 closed 10 years ago

salk31 commented 10 years ago

Some options: A - Force a selection in UI CON - user never asked for it CON - don't do that elsewhere PRO - simple and obvious

B - Force evaluation to true be removing the expression CON - UI can't be reloaded in previous state PRO - Good for template queries where no entry means ignore

C - Validation allow client code to say "no"? CON - Different feature/problem? CON - Can't save SQL in that state

D - Force to evaluate to false with IN (NULL) CON - Pain for devs to parse, find and do what they want with it

C - Force to evaluate to false with IN (?) where ? represents some magic CON - Devs have to look for magic args and SQL

matt-schwartz commented 10 years ago

My preference would be validation since you can't possibly produce valid SQL if no selection is made. Maybe pass a validation flat to onSqlChange to let the developer know the current selection is invalid and shouldn't proceed to process the query.

matt-schwartz commented 10 years ago

I just though of another possible solution: don't add a condition to the SQL until values are input. So if the user adds an IN condition, but hasn't yet chosen any values, it's simply not added as a condition in the SQL string. I imagine that's tricky since you're creating the SQL immediately on any input change, but it may be easier than separate validation messages / flags.

salk31 commented 10 years ago

Re-labelled the options and made it explicit that I think B is like this suggestion. Mine was thinking about how to hack the code easily. Although neither that easy.

Hard to tell what usages are required. I could imagine people setting up template searches and if the user doesn't enter anything then that expression should be suppressed (but then how do you search for an empty string - on something other than Oracle).

I think possibly two mechanisms might be the solution (pretty generic so not too scary): 1 - validation so the developer can say "no" in some nice way 2 - massage the output - however needs to be in legal SQL as I'd like standard SQL tools to be for this.

So would you still be happy with validation or making it, effectively, evaluate to true?

matt-schwartz commented 10 years ago

I think having the SQL always evaluate to true / valid would be great. In my case I'm saving the generated SQL for later use (as a saved search query in a ticketing system), so I never want it to be invalid. But sending back validation flags / messages would also work. Whatever you think is best for the how the library will be used.

salk31 commented 10 years ago

Not doing this to be annoying but I'm leaning towards D i.e. spit out "x IN (NULL)" that way the UI can be reconstructed and developers can pick it out and do whatever they like with it.

Going to sleep on it but how much of a pain would it be for you?

NB this could/should be alongside some validation system.

matt-schwartz commented 10 years ago

D will work fine for me. No problem at all. Thanks so much for putting in the extra effort to work with me on this!

salk31 commented 10 years ago

Please could you try http://0-6-0.redquerybuilder.appspot.com/

This returns (NULL) where not selection. SQL is so powerful :)