4D v17.4Data Types |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v17.4
Data Types
|
Field | Variable | Expression | |
String (see note 1) | Yes | Yes | Yes |
Number (see note 2) | Yes | Yes | Yes |
Date | Yes | Yes | Yes |
Time | Yes | Yes | Yes |
Boolean | Yes | Yes | Yes |
Picture | Yes | Yes | Yes |
Pointer | No | Yes | Yes |
BLOB (see note 3) | Yes | Yes | No |
Array (see note 4) | No | Yes | No |
Integer 64 bits (see note 5) | Yes | No | No |
Float (see note 5) | Yes | No | No |
Object | Yes | Yes | Yes |
Collection | No | Yes | No |
Undefined | No | Yes | Yes |
Null | No | No | Yes |
Notes:
String is a generic term that stands for:
There is no difference between a string or text variable.
You can assign a string to a text field and vice-versa; 4D does the conversion, truncating if necessary. You can mix string and text in an expression.
Note: In the 4D Language Reference manual, both string and text parameters in command descriptions are denoted as String, except when marked otherwise.
Number is a generic term that stands for:
The range for the Real data type is ±1.7e±308 (13 significant digits)
The range for the Integer data type (2-byte Integer) is -32,768..32,767 (2^15..(2^15)-1)
The range for the Long Integer data type (4-byte Integer) is -2^31..(2^31)-1
You can assign any Number data type to another; 4D does the conversion, truncating or rounding if necessary. However, when values are out of range, the conversion will not return a valid value. You can mix Number data types in expressions.
Note: In the 4D Language Reference manual, no matter the actual data type, the Real, Integer, and Long Integer parameters in command descriptions are denoted as number, except when marked otherwise.
Note: In the 4D Language Reference manual, Date parameters in command descriptions are denoted as Date, except when marked otherwise.
Since dates in JavaScript are objects, they are sent to 4D as text containing their JSON form like any other object. This principle is implemented in particular when using 4D Mobile or Web Area.
The JSON form of the JavaScript Date object follows the ISO 8601 standard, for example "2013-08-23T00:00:00Z".
It is your responsibility to convert this text into a 4D date (C_DATE). Two solutions are available:
C_TEXT($1) // reception of a date in ISO format
C_DATE($d)
$d:=JSON Parse("\""+$1+"\"";Is date))
C_TEXT($1) // reception of a date in ISO format
C_DATE($d)
$d:=Date($1)
Note the difference between these two solutions: JSON Parse respects the conversion mode set using the SET DATABASE PARAMETER (if any), while Date is not subject to this. Conversion using the Date command always takes the local time zone into account.
Note: Starting with 4D v16 R6, if the current date storage setting is "date type", JSON date strings in "YYYY-MM-DD" format are automatically handled as date values by the JSON Parse and Date commands. For more information on this setting, please refer to the "Use date type instead of ISO date format in objects" option in the Compatibility page.
Note: In the 4D Language Reference manual, Time parameters in command descriptions are denoted as Time, except when marked otherwise.
A Boolean field, variable or expression can be either TRUE or FALSE.
Note: In the 4D Language Reference manual, Boolean parameters in command descriptions are denoted as Boolean, except when marked otherwise.
A Picture field, variable or expression can be any Windows or Macintosh picture. In general, this includes any picture that can be put on the pasteboard or read from the disk using 4D or Plug-In commands.
Note: In the 4D Language Reference manual, Picture parameters in command descriptions are denoted as Picture, except when marked otherwise.
A Pointer variable or expression is a reference to another variable (including arrays and array elements), table, or field. There is no field of type Pointer.
For more information about Pointers, see the section Pointers.
Note: In the 4D Language Reference manual, Pointer parameters in command descriptions are denoted as Pointer except when marked otherwise.
A BLOB field or variable is a series of bytes (from 0 to 2 GB in length) that you can address individually or by using the BLOB Commands. There is no expression of type BLOB.
Note: In the 4D Language Reference manual, BLOB parameters in command descriptions are denoted as BLOB.
Variables, fields or expressions of the Object type can contain various types of data. The structure of "native" 4D objects is based on the classic principle of "property/value" pairs (also called "attribute/value"). The syntax of these objects is based on JSON, but does not follow it completely.
Warning: Keep in mind that attribute names differentiate between upper and lower case.
To manage Object type variables, fields or expressions you can use the object notation (see Using object notation) or 4D’s Objects (Language) commands, such as OB Get and OB SET. Note that specific commands of the Queries theme such as QUERY BY ATTRIBUTE, ORDER BY ATTRIBUTE and QUERY SELECTION BY ATTRIBUTE can be used to carry out processing on object fields.
Since Object fields are typically text-based, the contents of an Object field are displayed in a 4D form by default as text and formatted in JSON.
(*)When exposed as text in the debugger or exported to JSON, picture object properties print "[object Picture]". Attention - saving the record afterwards will save the "[object Picture]" string in the attribute.
Note: To work with JSON objects, you can use the commands found in the "JSON" theme.
A Collection variable can contain an ordered list of values of various types, for example:
C_COLLECTION($col)
$col:=New collection("Ford";"Renault";"Nissan";500;100;True)
//$col=["Ford","Renault","Nissan",500,100,true]
Supported value types are text, number, object, boolean, collection, or null. There is no expression or field of type Collection.
To manage Collection type variables you need to use the object notation (see Using object notation) and the commands of the Collections theme.
Example:
C_COLLECTION($col)
$col:=New collection("Ford";"Renault";"Nissan")
$col[1]:="BMW"
//$col=["Ford","BMW","Nissan"]
Collection variables store JSON arrays. A JSON array is a collection of comma-separated values of any type. You can store JSON arrays in collections. Examples:
C_COLLECTION($c1;$c2)
C_TEXT($json1;$json2)
$c1:=JSON Parse("[\"Ford\",\"Renault\",\"Nissan\",500,100,true]")
$json1:=JSON Stringify($c1)
//$json1=["Ford","Renault","Nissan",500,100,true]
$c2:=JSON Parse("[1,2,3,\"a\",\"b\",\"c\"]")
$json2:=JSON Stringify($c2)
//$json2=[1,2,3,"a","b","c"]
Undefined is not actually a data type. It denotes a variable that has not yet been defined. A function (a project method that returns a result) can return an undefined value if, within the method, the function result ($0) is assigned an undefined expression (an expression calculated with at least one undefined variable). A field cannot be undefined (the Undefined command always returns False for a field).
Null is a special data type with only one possible value: null. This value is returned by an expression that does not contain any value.
From the 4D database point of view, a null value expresses the fact that the data value is unknown. It does NOT mean that the value is blank, or empty ("" for a string, or 0 for a longint are blank values). In the 4D database, null values in fields (except for Object field attributes) are handled by the SQL engine only. A specific field option allows you to configure how the database should handle this value (Map NULL values to blank values) and you can set or read the null values using the Is field value Null and SET FIELD VALUE NULL commands.
In the 4D language and for object field attributes, null values are managed through the Null function. This function can be used with the following expressions for setting or comparing the null value:
Array is not actually a data type. The various types of arrays (such as Integer Array, Text Array, and so on) are grouped under this title. Arrays are variables—there is no field of type Array, and there is no expression of type Array. For more information about arrays, see the section Arrays.
Note: In the 4D Language Reference manual, Array parameters in command descriptions are denoted as Array, except when marked otherwise (i.e., Text Array, Numeric Array, etc.).
The 4D language contains operators and commands to convert between data types, where such conversions are meaningful. The 4D language enforces data type checking. For example, you cannot write: "abc"+0.5+!12/25/96!-?00:30:45?. This will generate syntax errors.
The following table lists the basic data types, the data types to which they can be converted, and the commands used to do so:
to String | to Number | to Date | to Time | |
String(*) | Num | Date | Time | |
Number (**) | String | |||
Date | String | |||
Time | String | |||
Boolean | Num | |||
Object | JSON Stringify | |||
Collection | JSON Stringify |
(*) Strings formatted in JSON can be converted into scalar data, objects, or collections, using the JSON Parse command.
(**) Time values can be be treated as numbers.
Note: In addition to the data conversions listed in this table, more sophisticated data conversions can be obtained by combining operators and other commands.
Arrays
Methods
Overview of JSON commands
Pointers
Type
Typing Guide
Using Compiler Directives
Variables
Product: 4D
Theme: Language definition
Modified: 4D v16 R4
Modified: 4D v16 R6
4D Language Reference ( 4D v17)
4D Language Reference ( 4D v17.1)
4D Language Reference ( 4D v17.2)
4D Language Reference ( 4D v17.3)
4D Language Reference ( 4D v17.4)