1

From the implementation point of view for a database, is it preferable to handle optional form fields by setting to some default value (e.g. false, 0, "", etc.) or just ignore such fields (do nothing with the specific attribute)

So supposing you have a form of

  • firstname* (textbox)
  • lastname* (textbox)
  • What type of ice-cream do you like? (textbox)
  • If you like ice-cream, do you like flakes as well? (checkbox)

Where firstname and lastname are required values (and suitably validated). In the form processing is it a "better idea"(TM) to automatically set values for icecream_type and flakes_are_the_best_thing_ever if no such values exit? Is it preferable for an implicitly boolean type such as the checkbox inputs, or indeed those relating to text, to have explicit false values instead of nulls?

Bearing in mind that prepared statements to mitigate against SQL injection will normally consider all aspects of the form for insertion

e.g. $pdoexec->prepare("INSERT INTO person (firstname, lastname, icecream_type, flakes_are_the_best_thing_ever")

While SQL statements will normally select all attributes from a particular table

SELECT firstname, lastname, icecream_type, flakes_are_the_best_thing_ever FROM person

At what point should these non-values be handled: pre-processing (before they get near the database) or post-processing (after the fact)?

Stumbler
  • 123
  • 1
  • 4
  • So basically, you're asking, "should I use token values in order to avoid NULLs?" – Aaron Bertrand Jul 02 '15 at 11:04
  • @AaronBertrand pretty much – Stumbler Jul 02 '15 at 11:55
  • 1
    In isolation, that's been discussed before. It all depends on what you want to convey - do you want to differentiate between "hasn't specified an ice cream type yet" and "doesn't eat ice cream" and "likes them all the same"? For checkboxes do you want to differentiate between "no" and "hasn't answered (yet)"? The argument shouldn't be about whether handling NULL values is "hard," which is what I find it mostly boils down to... – Aaron Bertrand Jul 02 '15 at 12:33

0 Answers0