Data Types
Lobster_data can handle the following data types.
String |
Texts and alphanumeric values. |
Integer |
Numbers without decimals in the range of -2147483648 to 2147483647. |
BigInteger |
Number without decimals without a limit. |
Float |
Floating point numbers with a low relative precision (7 significant digits). |
Double |
Floating point numbers with a high relative precision (15 significant digits). |
BigDecimal |
Decimal number without limit and no errors during rounding. Especially useful when working with monetary amounts. |
Boolean |
Logical values (true or false), especially for logical conditions. Note: An implicit type conversion takes place in input fields. A string that begins with t or a number > 0 is converted to true (this includes numbers with leading 0, e.g. 012, which is actually a string before the implicit type cast). A string that does not begin with a t or a number <= 0 is converted to false. |
Date |
Dates (without time). |
Timestamp |
Dates (with times). |
Blob |
Binary data. |
To increase comfort, Lobster_data performs implicit conversions from one type to the other. In many cases, it is not necessary to keep an eye on the actual data type being in use. Every data type can be converted to String. A date value e.g. representing the date 05/07/11 will be converted to 2011-05-07, a Boolean value true to the text true. Vice versa every text in the before mentioned forms can be converted to a Date or Boolean. Every text that represents a number can be converted to a number, it is assumed that the decimal separator is a decimal point. If a non-String type implicitly converted into a String, the format of this text is called the native representation of this non-String type. In the opposite case, a text can be converted into a non-String type if it meets the native representation of this destination type.
To convert texts that are not in the native form of the destination type, different ways can be used.
Every input field allows setting the type and a template how to parse the data. E.g. a field of type Date and the template yyyyMMdd can read in texts in the form of 20110507. Vice versa it is possible to set a template in the destination field to control the formatting of a date/number into a String.
There are functions that allow the creation or formatting of a number e.g. the create date and format date/timestamp to text(a, template b, [Locale c], [Timezone d]) functions when working with Dates or Timestamps.
Important note: A type conversion can lead to data loss if the type the value has been converted to is more limited than the original one. E.g. Integer or BigInteger cannot hold decimals, implicit conversion of text abc into a number will lead to 0, meanwhile the same text abc converted into a Boolean will lead to false. Subsequent re-conversion into the data type String will not restore the text abc.
Implicit conversions will never abort the job on conversion format errors. Instead, the default value of the destination type is assumed. The default of a numeric value is 0, the default for Date/Timestamp will be the current date and time. In case an abort on error is needed, a suitable function should be used for explicit conversion which allows defining an explicit error handling.
Functions expect data of specific type and return data with a specific type
Functions always expect the parameters to be of a specific type, e.g. format date/timestamp to text(a, template b, [Locale c], [Timezone d]) expects parameter a to be of type Date or Timestamp. Every other type will implicitly be converted to Timestamp. The result of the function is of type String.
Variables have a type
The variable's type is declared during creation. A variable can only store values of the given type. Trying to save a value of different type will lead to an implicit conversion. Reading from the variable always returns the value with the defined type.
Comparisons and types
If two values are compared e.g. with the functions a equals b, logical-not( a equal b ), a == b ? c : d or goto function-pos(a==b, c, d) there are three different ways of comparison depending on the involved data types:
If both arguments are of type String comparison is performed.
If one argument is of type Boolean, the other one will be converted to Boolean and a Boolean comparison is done.
In all other cases, a numeric comparison will be performed using BigDecimal. Dates and Timestamps are converted to 'Unix time', i.e. the number of milliseconds since 1970-01-01 00:00:00 in order to compare them numerically.
To force a numeric comparison, at least one argument needs to be of a numeric type. This can, for example, be done by saving the value to a variable of that type or using the convert-type function.