The previous section described Data sources and Queries which provide raw data. Raw data can be used as is, or can be processed further for the purposes of the report. This is where expressions come in.
There are three main data types in OpenCReports:
numeric, string,
and datetime.
OpenCReports automatically detects the type of raw data
supplied by Queries for SQL and some
file based Data sources, and the
application can supply extra data to indicate column
data types.
Expressions can use and result in any of these types.
A numeric expression's result is
a number. It uses high numeric precision. Most functions
and operators deal with numbers.
For historic record, RLIB was designed for the US and for slower computers. It used a fixed point numeric representation. For the US, with its strong currency and prices expressed in low numbers, this was an acceptable design decision at the time. But for countries, where currencies are a few orders of magnitude weaker and conversely, the prices are similarly higher, the fixed point numeric value range was easily overflown (especially in report variables that added values), leading to wrong data in the report output.
Another potential problem with fixed point numeric representation is that converting numbers from the input data to this internal representation always rounds down. The numeric error (i.e. the difference between floating point values and fixed point values) can be demonstrated even with small data sets that add up percentages.
OpenCReports uses high precision floating point values.
Technically, it's 256-bit precision GNU MPFR numerics by default,
and the precision can be modified by the application if needed.
This allows handling very large and very small numbers
and directly consuming the SQL numeric
and decimal types or arbitrary precision,
or using bcmath numerics in PHP.
This also allows scientific computation or monetary
calculations even with late stage
hyperinflation
prices.
A string expression's result is arbitrary
text. Strings can be concatenated or otherwise processed
by string functions.
A datetime expression may store a date,
a time (with or without timezone) or both. Also, it may store
a time interval, e.g. 2 months that can be
added to or subtracted from another datetime
value.
There is a further data type: error.
Errors usually occur if there is an error in processing,
e.g. when a function argument does not match its expected
parameter data type. The error type is
a special case of strings: it stores a string literal,
the error message. As opposed to the
string data type, an error cannot be
processed further by passing them as function arguments or
operator operands. Instead, the first error is propagated
up from subexpressions to the final result of the expression.