don't allow blank property values in find(); handle property deletion

This commit is contained in:
Dan Williams 2006-12-11 10:59:30 -05:00
parent 74d9555796
commit dbca112368

View File

@ -233,6 +233,8 @@ class DataStore(object):
subquery = "" subquery = ""
for (key, value) in prop_dict.items(): for (key, value) in prop_dict.items():
safe_key = key.replace("'", "''") safe_key = key.replace("'", "''")
if not len(value):
raise ValueError("Property values must not be blank.")
value = str(value) value = str(value)
substr = "key='%s' AND value='%s'" % (safe_key, sqlite.encode(value)) substr = "key='%s' AND value='%s'" % (safe_key, sqlite.encode(value))
if len(subquery) > 0: if len(subquery) > 0:
@ -280,6 +282,10 @@ class DataStore(object):
for (key, value) in prop_dict.items(): for (key, value) in prop_dict.items():
safe_key = key.replace("'", "''") safe_key = key.replace("'", "''")
if not len(value):
# delete the property
curs.execute("DELETE FROM properties WHERE (objid=%d AND key='%s');" % (uid, safe_key))
else:
enc_value = sqlite.encode(_get_data_as_string(value)) enc_value = sqlite.encode(_get_data_as_string(value))
curs.execute("SELECT objid FROM properties WHERE (objid=%d AND key='%s');" % (uid, safe_key)) curs.execute("SELECT objid FROM properties WHERE (objid=%d AND key='%s');" % (uid, safe_key))
if len(curs.fetchall()) > 0: if len(curs.fetchall()) > 0: