jset/ODBSet using true/false for booleans
MIDAS does not seem to be consistent (or at least convenient) with how it handles booleans in AJAX functions.
When you request an ODB value that is a boolean with AJAX call like
http://neut14.triumf.ca:8081/?cmd=jcopy&odb=/Equipment/DCRC/Common/Hidden&format=json-nokeys
then you get
{ "Hidden/last_written" : 1437065425, "Hidden" : false }
This seems correct, since the JSON convention has booleans encoded as true/false.
But this convention does not work when trying to set the boolean value. For instance
http://neut14.triumf.ca:8081/?cmd=jset&odb=/Equipment/DCRC/Common/Hidden&format=json-nokeys&value=true
does not set the variable to true. To make this work you need to use the characters y/n
http://neut14.triumf.ca:8081/?cmd=jset&odb=/Equipment/DCRC/Common/Hidden&format=json-nokeys&value=y
I tested this with ajax/jset, but the same problem seems to occur when using the javascript function ODBSet. The documentation doesn't say what sort of encoding to use when using these functions, so I guess the idea is that these functions use MIDAS encoding for booleans. But it seems to me that it would be more convenient if jset/ODBSet allowed the option to use json/javascript encoding for boolean values; or at least had that as a format option for jset/ODBSet.
Comments (2)
-
-
- changed status to resolved
No it can. I changed actually db_sscanf() to accept "TRUE" or "true" as boolean true. This does not break existing web pages.
I agree however that the handling of boolean variables is totally screwed up inside midas. Internally stored as zero and one, db_sprintf() gives back "y" and "n", while the JSON encoder says "true" and "false". It would certainly make sense to change db_sprintf() also to "true" and "false", but this would certainly break existing systems. (or should we just try and wait until people are yelling?)
- Log in to comment
the documentation is correct. the data encoding for jset is unknown. the plan is to implement a jpaste function that goes along with jcopy and uses JSON encoding. the current jset function cannot be changed without breaking compatibility with existing web pages. sorry. K.O.