'This is a knockoff of the Version 6 function S_Quote()
'to work with Version 5
'The FUN_QUOTE() function properly quotes variables so they can be used in expressions.
'Like .....
'd = date()
'm = .t.
'n = 5
'c = "Ed"
'filter = "date = " + fun_quote(d) + " .and. age = " + fun_quote(n) + " .and. name = " + fun_quote(c) + " .and. married = " + fun_quote(m)
'? filter
'= "date = {01/12/2005} .and. age = 5 .and. name = 'Ed' .and. married = .T."
''''also like
'd = date()
'bdate = {01/01/2001}
'edate = {01/01/2010}
'filter = "between("+fun_quote(d)+","+fun_quote(bdate)+","+fun_quote(edate)+")"
'? filter
'= "between({01/12/2005},{01/01/2001},{01/01/2010})"
FUNCTION FUN_QUOTE AS C (VARIABLE AS A )
IF .not. INLIST(typeof(VARIABLE),"C","D","N","L")
ui_msg_box("Warning","Parameter type must be Character, Date, Numeric, or logical")
exit function
end if
fun_quote = convert_type(variable,"C")
select
case typeof(variable) = "C"
FUN_QUOTE = quote(VARIABLE,"'")
case typeof(variable) = "D"
FUN_QUOTE = "{"+dtoc(variable)+"}"
case typeof(variable) = "N"
FUN_QUOTE = convert_type(variable,"C")
case typeof(variable) = "L"
if variable = .T.
FUN_QUOTE = ".T."
else
FUN_QUOTE = ".F."
end if
end select
END FUNCTION
As a knockoff it does not include all features available in the "real thing", but then I don't know how to make a parameter optional.
'to work with Version 5
'The FUN_QUOTE() function properly quotes variables so they can be used in expressions.
'Like .....
'd = date()
'm = .t.
'n = 5
'c = "Ed"
'filter = "date = " + fun_quote(d) + " .and. age = " + fun_quote(n) + " .and. name = " + fun_quote(c) + " .and. married = " + fun_quote(m)
'? filter
'= "date = {01/12/2005} .and. age = 5 .and. name = 'Ed' .and. married = .T."
''''also like
'd = date()
'bdate = {01/01/2001}
'edate = {01/01/2010}
'filter = "between("+fun_quote(d)+","+fun_quote(bdate)+","+fun_quote(edate)+")"
'? filter
'= "between({01/12/2005},{01/01/2001},{01/01/2010})"
FUNCTION FUN_QUOTE AS C (VARIABLE AS A )
IF .not. INLIST(typeof(VARIABLE),"C","D","N","L")
ui_msg_box("Warning","Parameter type must be Character, Date, Numeric, or logical")
exit function
end if
fun_quote = convert_type(variable,"C")
select
case typeof(variable) = "C"
FUN_QUOTE = quote(VARIABLE,"'")
case typeof(variable) = "D"
FUN_QUOTE = "{"+dtoc(variable)+"}"
case typeof(variable) = "N"
FUN_QUOTE = convert_type(variable,"C")
case typeof(variable) = "L"
if variable = .T.
FUN_QUOTE = ".T."
else
FUN_QUOTE = ".F."
end if
end select
END FUNCTION
As a knockoff it does not include all features available in the "real thing", but then I don't know how to make a parameter optional.
Comment