with sql_exceptions; package body sql_enumeration_pkg is null_value_error : exception renames sql_exceptions. null_value_error; function null_sql_enumeration return sql_enumeration is null_holder : sql_enumeration; begin return null_holder; end; function without_null (value : sql_enumeration) return sql_enumeration_not_null is begin if value. is_null then raise null_value_error; else return value. value; end if; end without_null; function with_null (value : sql_enumeration_not_null) return sql_enumeration is begin return (is_null => false, value => value); end; procedure assign (left : in out sql_enumeration; right : in sql_enumeration) is begin left := right; end assign; function equals (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value = right. value then return true; else return false; end if; end equals; function not_equals (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value /= right. value then return true; else return false; end if; end not_equals; function "<" (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value < right. value then return true; else return false; end if; end "<"; function ">" (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value > right. value then return true; else return false; end if; end ">"; function "<=" (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value <= right. value then return true; else return false; end if; end "<="; function ">=" (left, right : sql_enumeration) return boolean_with_unknown is begin if left. is_null or else right. is_null then return unknown; elsif left. value >= right. value then return true; else return false; end if; end ">="; function is_null (value : sql_enumeration) return boolean is begin return value. is_null; end; function not_null (value : sql_enumeration) return boolean is begin return not value. is_null; end; function "=" (left, right : sql_enumeration) return boolean is -- This code is changed some from the Guidelines -- Document to be more compact begin if left. is_null or else right. is_null then return false; else return left. value = right. value; end if; end "="; function "<" (left, right : sql_enumeration) return boolean is begin if left. is_null or else right. is_null then return false; else return left. value < right. value; end if; end "<"; function ">" (left, right : sql_enumeration) return boolean is begin if left. is_null or else right. is_null then return false; else return left. value > right. value; end if; end ">"; function "<=" (left, right : sql_enumeration) return boolean is begin if left. is_null or else right. is_null then return false; else return left. value <= right. value; end if; end "<="; function ">=" (left, right : sql_enumeration) return boolean is begin if left. is_null or else right. is_null then return false; else return left. value >= right. value; end if; end ">="; function pred (value : in sql_enumeration) return sql_enumeration is begin if value. is_null then return null_sql_enumeration; else return (with_null (sql_enumeration_not_null'pred (value. value))); end if; end pred; function succ (value : in sql_enumeration) return sql_enumeration is begin if value. is_null then return null_sql_enumeration; else return (with_null (sql_enumeration_not_null'succ (value. value))); end if; end succ; function pos (value : in sql_enumeration) return integer is begin if value. is_null then raise null_value_error; else return sql_enumeration_not_null'pos (value. value); end if; end pos; function image (value : in sql_enumeration_not_null) return sql_char_not_null is begin return to_sql_char_not_null (sql_enumeration_not_null'image (value)); end image; function image (value : in sql_enumeration) return sql_char is begin if value. is_null then raise null_value_error; else return to_sql_char (sql_enumeration_not_null'image (value. value)); end if; end image; function val (value : in integer) return sql_enumeration is begin return (with_null (sql_enumeration_not_null'val (value))); end val; function value (value : in sql_char_not_null) return sql_enumeration_not_null is begin return (sql_enumeration_not_null'value (to_string (value))); end value; function value (value : in sql_char) return sql_enumeration is begin if is_null (value) then return null_sql_enumeration; else return with_null (sql_enumeration_not_null'value (to_string (value))); end if; end value; end sql_enumeration_pkg;