to use the udf you would do something like this
INSERT INTO TABLE (fieldName) values (
'#FilterNull(form.fieldName, "none", "yes")#')
however I've found a problem.
I was trying to make something similar only using NULL and not a string. when you use a string you must surround it with '
NULL is not surrounded with '
as this one is written you must code the ' around the function. if you want null it will not work because you'll end up with 'NULL' which is not the same as NULL
I've tried changing the function a little to use strictly NULL and not accept a user defined variable.
in my function
Code:
if (fld neq ""){
return "'" & fld & "'"
}else{
return "NULL";
}
here is the problem...
in the query i have
INSERT INTO TABLE (fieldName) values (
#FilterNull(form.fieldName)#)
this is fine if the value is ""
however if the value is not "" the query tries to change the returned ' to '' making the total query look like
INSERT INTO TABLE (fieldName) values (
''fieldValue'')
this is expected because macromedia tried to idiot proof the ' escaping.
my next attempt was to use PreserveSingleQuotes() i'll call it psq() for short.
i was soon saddened to find that psq does not accept a udf inside the psq call.
INSERT INTO TABLE (fieldName) values (
#PSQ(FilterNull(form.fieldName))#)
throws an error. on the first ( for the filterNull function.
I've tested in both cf5 and cf6.1
WITHOUT building a sql string (because that would defeat the entire purpouse) how else can this be done easily?
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)