Enumerated types are declared using the ENUM()
statement. You must declare the acceptable enumeration values
when you use this statement.
To define a simple two-field table where the primary key is a UID and the second field contains an enum, you use the following DDL statement:
CREATE TABLE myTable (
uid INTEGER,
myEnum ENUM (Apple,Pears,Oranges),
PRIMARY KEY (uid)
)
CHECK constraints are not supported for
enumerated fields.
DEFAULT and NOT NULL
constraints are supported for enumerated fields. See
DEFAULT
for more information.
Enum values are handled as strings.
To write the enum:
row_d = {'uid' : 0,
'myEnum' : 'Pears'
}
try:
store.put("myTable", row_d)
logging.debug("Store write succeeded.")
except IllegalArgumentException, iae:
logging.error("Could not write table.")
logging.error(iae.message)
sys.exit(-1)
To read the enum:
try:
primary_key_d = {"uid" : 0}
row = store.get("myTable", primary_key_d)
if not row:
logging.debug("Row retrieval failed")
else:
logging.debug("Row retrieval succeeded.")
myEnum = row['myEnum']
print "myEnum: %s" % myEnum
except IllegalArgumentException, iae:
logging.error("Row retrieval failed.")
logging.error(iae.message)
return
except KeyError, ke:
logging.error("Row display failed. Bad key: %s" % ke.message)