6. Defining Function Instances : Length Definition of Result Data Type
 
Share this page                  
Length Definition of Result Data Type
The length of a result data type is defined by fid_rlength in II_ADD_FI_DFN or an external lenspec routine. This length is used by the DBMS Server when manipulating values internally. The length component of the actual data value (II_DATA_VALUE db_length) should not be changed within the function itself. If the length defined by fid_rlength or the lenspec routine differs from the data value’s db_length, then errors may result or data values may be incorrectly interpreted.
The same is true of scale and precision in the case of DECIMAL. In this case, the fid_rprec or lenspec is used and the db_prec of the data value should not be changed.
The following macros, defined in $II_SYSTEM/ingres/files/iiadd.h, can be used to manipulate DECIMAL length values:
DB_PS_ENCODE_MACRO(p,s)
Given a precision p and scale s, returns the two-byte value combining the two. This macro could be used, for example, when setting db_prec value within a user-defined lenspec routine.
DB_P_DECODE_MACRO(ps)
Given a two-byte combined value for precision and scale (db_prec) of ps, returns the precision part.
DB_S_DECODE_MACRO(ps)
Given a two-byte combined value for precision and scale (db_prec) of ps, returns the scale part.
DB_PREC_TO_LEN_MACRO(prec)
Given a precision of prec, returns the length needed for such a decimal. This macro could be used when setting the db_length within a user-defined lenspec routine.