The following are the basic data types in Qore (see Container Data Types for container data types):
Table 2.6. Basic data types
Type | Description | Example | Default Value |
|---|---|---|---|
True or |
| False | |
A sequence of characters |
| Empty string | |
A 64-bit signed integer |
| 0 | |
A double-precision floating-point number |
| 0.0 | |
A date/time value with an optional time zone component, with resolution to the microsecond. |
| 1970-01-01Z | |
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) |
|
| |
Represents the state of a variable having no value or function returning no value (not equivalent to NULL) |
|
|
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";
Internally, strings are stored as a pointer to the string data, an unsigned integer giving the length of the string, and a pointer to an encoding object, giving the string's character encoding.
Qore floats are double precision floating-point numbers (C/C++ type double), normally a 64-bit value.
Qore dates have a time component supporting a resolution to the microsecond and can be either absolute or relative.
See Date and Time Functions for a list of functions related to date/time processing.
Absolute date/time values specify a specific point in time in a certain time zone, such as January 1, 2005 10:35:00 +01:00. They are stored interally as a 64-bit signed offset from the Qore epoch (1970-01-01Z), a positive 4-byte integer for microseconds, and a pointer to a time zone description object that provides the UTC offset and daylight savings time information (see Time Zones for more information). Note that all absolute date/time values in Qore are stored internally in UTC and are converted for display purposes to the representation of wall time in their tagged time zone.
Absolute date/time values can be specified with a syntax based on ISO-8601 date formats as follows:
YYYY-MM-DD[THH:mm:SS[.n*]][Z|[+-]HH[:mm[:SS]]]
Note that if no time zone information is given, the local time zone will be assumed. If a time zone UTC offset is given, it is given in units of time east of UTC (i.e. +05:00 means five hours east of UTC).
Or an alternative format (with a '-' instead ofa 'T' to separate the time component):
YYYY-MM-DD[-HH:mm:SS[.n*]][Z|[+-]HH[:mm[:SS]]]
for example, for just the date in UTC, without a time component:
2010-05-26
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 and will also be tagged with the local time zone):
20:05:10.458342
Some further examples (note that the date/time values without a time zone specification here are tagged with the local time zone):
prompt%qore -X '2005-03-29-18:12:25' 2005-03-29 18:12:25 Tue +02:00 (CEST)prompt%qore -X '0512-01-01T01:49:59.002213Z' 0512-01-01 01:49:59.002213 Fri Z (UTC)prompt%qore -X '2005-03-29' 2005-03-29 00:00:00 Tue +02:00 (CEST)prompt%qore -X '18:35:26+08:00' 1970-01-01 18:35:26 Thu +08:00 (+08)
The year must be a four-digit number, and all other values except microseconds must be two-digit numbers. If microseconds are present, at least one and up to 6 digits may be given after the decimal point. Pad the numbers with leading zeros if the numbers are smaller than the required number of digits. 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.
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 UTC. When calculating second offsets from this date, a 64-bit integer is used.
The default local time zone for qore is set when the qore library is initialized; see Time Zones for more information.
Relative dates (durations) are normally used for date addition and subtraction. See Date/Time Arithmetic for more information.
Internally, durations are stored as a set of seven discrete signed integer values, one each for years, months, days, hours, minutes, seconds, and microseconds.
There are 3 different formats understood by the Qore parser for describing literal durations in Qore.
A single relative date/time value (or a duration) may be specified as follows (note that this format is specific to Qore and not based on ISO-8601):
<integer><date component specifier>
Table 2.7. Date Specifiers For Single Values For Relative Dates (non-ISO-8601 syntax)
Component | Meaning | Example | Description |
|---|---|---|---|
Y | Years |
| 2 Years |
M | Months |
| 3 Months |
D | Days |
| 10 Days |
h | Hours |
| 15 hours |
m | Minutes |
| 25 minutes |
s | Seconds |
| 19 seconds |
ms | Milliseconds |
| 250 milliseconds |
us | Microseconds |
| 21194 microseconds |
This and the next duration format for composite relative date/time values are both based on ISO-8601.
This first format has the following syntax:
PnYnMnDTnHnMnSnu
Each element above is optional, but at least one element must be present. Note that "M" means months when before the "T" and minutes when found after the "T". The other elements are years, days, hours, seconds, and, as an extension to ISO-8601, "u" for microseconds. Additionally, the values may be negative.
Here are some examples (using qore's -X command-line option to evaluate and expression and print out the result):
prompt%qore -X 'P1Y3MT4S' <time: 1 year 3 months 4 seconds>prompt%qore -X 'PT4M551u' <time: 4 minutes 551 microseconds>prompt%qore -X 'P3DT21H' <time: 3 days 21 hours>
The second ISO-8601-based format for specifing complex durations with multiple time units has the following syntax:
PYYYY-MM-DDTHH:mm:SS
This format is more limited than the first format, in that all values must be positive, and furthermore, all values must be present (although they may be zero).
Here are some examples of the second format (equivalent to the first examples):
prompt%qore -X 'P0001-03-00T00:00:04' <time: 1 year 3 months 4 seconds>prompt%qore -X 'P0000-00-00T00:04:00.000551' <time: 4 minutes 551 microseconds>prompt%qore -X 'P0000-00-03T21:00:00' <time: 3 days 21 hours>
The binary data type is used to hold binary arbitrary binary data. Internally it is represented by a pointer to a memory location for the data and a size indicator.
Binary data can be concatenated with the + and += operators.
This data can be manipulated by being written and read from File, Socket, Datasource, DatasourcePool, or SQLStatement 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, DatasourcePool, and SQLStatement 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; for example:
prompt% qore -X 'exists NOTHING'
FalseBoolean, 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 from strings, any of the following formats can be used: "YYYYMMDDHHmmSS[.us][Z|+-HH[:MM[:SS]]]", "YYYY-MM-DD HH:mm:SS.us", "YYYY-MM-DDTHH:mm:SS", "YYYY-MM-DDTHH:mm:SS[.us][Z|+-HH[:MM[:SS]]]", and most reasonable combinations thereof. If the time zone component is missing, then the local time zone will be assumed (see Time Zones).
When dates are converted to and from integer values, the a 64-bit second offset from January 1, 1970 in the local time zone is used for the conversion. For example int(2006-01-01) gives 1136073600 (regardless of the local time zone the date is in). To get the second offset of a date from 1970-01-01Z (i.e. the true epoch offset), call get_epoch_seconds() instead.
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.