I have some code that only does updates
<cfif tags NEQ "skip">
<cfquery>
UPDATE myTable
SET tags = <cfqueryparam cfsqltype="CF_SQL_varchar" value="#arguments.tags#">
WHERE ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.ID#">
</cfquery>
What would be a better approach than using “skip” as a magic value? Note that blank is a valid value.
It depends on where the data is coming from. Ideally, I’d set a variable to true or false and check that. I’m guessing that in your example tags is coming from a form and that ‘skip’ is the value in a for ‘None of these’. You’ve probably got to use something as a magic value, but I’d favour using something like
__SKIP_TAGS__which is very clear.You could also split up your page logic, so that you process the form submission first, checking for magic values and setting up a boolean for whether to insert data from #tags#, then use the boolean later on for your check. The overall logic would be the same, but better laid out.
You might want to consider adding a bit more context to your question, like where the data is coming from, so that others can give you better advice