I've written a utility to handle adding values to data parameters for hand-rolling sql queries. Consumption looks like
utility.Add("SELECT * FROM MyTable WHERE MyColumn = {0}", myVariable, DBType.TheType);
or
utility.Add("UPDATE MyTable SET MyColumn = {0}", myVariable, DBType.TheType);
How should a null value for myVariable be handled?
- All values should be fully trusted. The responsibility is solely upon the consumer. How would the consumer know that null would be handled anyway?
- null can never work, so it should throw a NullArgumentException. Why go any further?
- null should be automatically interpreted as DBNull.Value since it's the only viable solution. This is a utility, right? Make it utilizable and dry up some code!
Optional bonus question: If these arguments were made by three political candidates, what would their parties be? (Please state the home country of such parties)