Storing Boolean values
Booleans are very commonly used for storing binary values. You can either choose to store them as a simple 0 or 1 in SimpleDB or store them in a slightly more readable way as the string values true
and false
.
Storing Boolean values with Java
Here are two simple methods to convert values from a Boolean to a string and vice versa:
public String encodeBoolean(boolean valueToEncode) { return new Boolean(valueToEncode).toString(); }
public boolean decodeBoolean(String encodedValue) { return encodedValue.equalsIgnoreCase("true"); }
Storing Boolean values with PHP
These functions are in the SimpleDB PHP library. Boolean true is stored as the string true
while false is stored as the string false
. The following functions isolate the program from the stored value so that as an example 1
and 0
could be used for true
and false
instead:
public function encodeBoolean($input) { if ($input) { return "true"; } else { return "false"; } } public function decodeBoolean($input) { if (strtolower...