The following are the basic data types in Qore:
Table 2.6. Basic data types
Type | Description | Example | Default Value |
---|---|---|---|
True or False value | True | False | |
A sequence of characters | "string" | Empty string | |
A 64-bit signed integer | 1 | 0 | |
A double-precision floating-point number | 1.00023 | 0.0 | |
A date with an optional time component, with resolution to the millisecond. | 2005-07-20 | 1970-01-01 00:00:00 | |
An opaque binary object | n/a | an empty object of size 0 | |
Corresponds to a NULL value in a database query (not equivalent to NOTHING) | NULL | NULL | |
Represents the state of a variable having no value or function returning no value (not equivalent to NULL) | NOTHING | NOTHING |
The Boolean type can have two values, True and False. When converting other types to a Boolean, any value that converts to a non-zero integer will be evaluated as True. Otherwise the result of the conversion will be False.
String values are specified with text between double or single quotes. Text between double quotes is subject to interpretation of escape characters. Please see String Formatting for more information.
Strings are assumed by default to have the encoding given by the QORE_CHARSET
or the LANG
environment variable. If neither of these variables is set, then all strings will be assumed to have UTF-8 encoding.
For detailed information on Qore character encoding handling, please see Qore Strings and Character Encoding.
It is legal to specify a string literal with newline characters like the following:
$str = "this string is a multiline string";
Qore dates have a time component supporting a resolution to the millisecond and can be either absolute or relative.
Absolute date/time values specify a specific point in time, such as January 1, 2005 10:35:00 and can be specified with a special syntax as follows:
<4d-year>-<2d-month>-<2d-day>[-<2d-hour>:<2d-minute>:<2d-second>[.<3d-millisecond>]]
or, an almost-ISO-8601-compliant format (without the ISO-8601 time zone component but including an optional millisecond component)
<4d-year>-<2d-month>-<2d-day>[T<2d-hour>:<2d-minute>:<2d-second>[.<3d-millisecond>]]
for example, for just the date, without a time component:
<4d-year>-<2d-month>-<2d-day>
or, for just the time, without a date component (note that in this case the date component will be set to Jan 1, 1970, in order for time arithmetic to function properly):
<2d-hour>:<2d-minute>:<2d-second>[.<3d-millisecond>]]
Some examples should make it clearer:
2005-03-29-18:12:25 # represents: March 29, 2005 6:12:25 pm 0512-01-01T01:49:59.213 # represents: January 1, 512 1:49:59 am and 213 milliseconds 2005-03-29 # represents: March 29, 2005 00:00:00 18:35:26 # represents: January 1, 1970 6:35:26 pm (start of the Qore epoch)
The year must be a four-digit number, and all other values except milliseconds must be two-digit numbers. If milliseconds are present, 3 digits are required after the decimal point. Pad the numbers with leading zeros if the numbers are smaller than the required number of spaces. The hour component must be in 24-hour time format. Except for the month and day values, all other values start with 0 (hour = 00 - 23, minute and second: 00 - 59). Any deviation from this format will cause a parse exception.
Currently there is no time-zone component in Qore dates. Timezone support may be added in future versions of the Qore language, either by an addition to this data type, or by adding another date type including a time zone component. Specifically, ISO-8601 time zone components are not accepted by the qore parser and will cause a parse exception to be thrown.
Relative date/time values are specified as follows:
<integer><date component specifier>
Table 2.7. Date Specifiers For Relative Dates
Component | Meaning | Example | Description |
---|---|---|---|
Y | Years | 2Y | 2 Years |
M | Months | 3M | 3 Months |
D | Days | 10D | 10 Days |
h | Hours | 15h | 15 hours |
m | Minutes | 25m | 25 minutes |
s | Seconds | 19s | 19 seconds |
ms | Milliseconds | 250ms | 250 milliseconds |
Relative dates are normally used for date addition and subtraction. See Date/Time Arithmetic for more information.
When a date/time value is converted to an integer or vice-versa, a 64-bit offset in seconds from the start of the "epoch" is used for the conversion. Qore's "zero date" (the start of Qore's "epoch") is January 1, 1970. When calculating second offsets from this date, a 64-bit integer is used.
The binary data type is used to hold binary arbitrary binary data. Internally it is represented by a memory pointer and a size indicator.
This data can be manipulated by being written and read from File, Socket, and Datasource objects, or converted and parsed to/from base64 encoded strings using the makeBase64String() and parseBase64String() functions, or compressed and decompressed using the compress(), gzip(), bzip2(), etc. functions, and processed by most cryptographic funtions, among others.
Binary objects can be read from a File object using the File::readBinary() method and can be written using the File::write() method. Please see the File Class for more information.
Binary objects can be read from a Socket object using the Socket::recvBinary() method and can be written using the Socket::send() method. Please see the Socket Class for more information.
The Datasource and DatasourcePool classes can also be used to read and write Binary objects as BLOBs.
Note that this is not an exhaustive list; see the function and class library documentation for more examples.
This data type represents an SQL NULL value. Note that NULL is not equivalent to NOTHING.
This special data type represents no value.
The exists operator will return False when given NOTHING as an argument.
Boolean, string, integer, date, and floating point data types can be freely converted from one type to the other, although data loss is possible depending on the conversion (particularly when converting to the boolan type as only two possible values are supported).
The special types NULL and NOTHING are not equivalent and cannot be converted to or from any other type.
When date types are converted to/from strings, the following format must be used: "YYYYMMDDHHmmSS".
When dates are converted to and from integer values, the a 64-bit second offset from January 1, 1970 is used for the conversion. For example int(2006-01-01)
gives 1136073600
.
When an expression requires a certain data type and the source data type cannot be converted to the desired data type, the default value for the desired data type will be used. The default values are given here.