Understanding records
This is an introduction to records.
A record defines a structured variable, where each member can be defined with a specific data type.
Records are used in interactive instructions like
INPUT
to control forms, and record are also used in INSERT
and
UPDATE
SQL instructions, to
update the database table.
Records can contain sub-record structures, and list types like arrays and dictionaries:
DEFINE reader RECORD
id INTEGER,
name VARCHAR(100),
birth DATE,
address RECORD
num VARCHAR(20),
street VARCHAR(200),
city_id INTEGER,
state_id VARCHAR(5)
END RECORD,
book_ids DYNAMIC ARRAY OF INTEGER
END RECORD
Records are typically used to store the values of a database row. Records can be based on the
column types of a database table, which is defined in a database schema
(SCHEMA
):
SCHEMA stores
DEFINE cust RECORD customer.*
-- cust is defined with the column of the customer table
The following list summarizes record usage:
- Record variables are defined with the
RECORD
syntax block, or with aTYPE
defined asRECORD
. - Records can be defined with attributes.
- Records can be initialized in their definitions with record initializers.
- To access a record member, use the dot notation
(
record-name.member-name
) - Records can be copied to other records, if they are defined with the same type, by using the
LET rec1 = rec2
assignment operation. - It is possible to compare all members of records of the same type with the
rec1.* == rec2.*
comparison expression. - Records can be passed as function parameters by value
or by reference (
INOUT
).