The most prominent data parts created are the SQLRecord parts. The fields in these Record parts relate to columns in the database. When you create a variable based on this record you can use that variable to represent a new or existing row in the database. Though each SQLRecord created by the data access application wizard matches only the columns in a single table, later in this tutorial you will learn how to merge data from more than one table into a single record (called a table join in SQL).
record Customer type sqlRecord {
tablenames=[["EGL.CUSTOMER"]],
keyItems=[CustomerId]
}
CustomerId CustomerId {column="EGL.CUSTOMER.CUSTOMER_ID"};
FirstName FirstName {column="EGL.CUSTOMER.FIRST_NAME",
sqlVariableLen=yes, maxLen=30, isSqlNullable=yes};
LastName LastName {column="EGL.CUSTOMER.LAST_NAME",
sqlVariableLen=yes, maxLen=30, isSqlNullable=yes};
...
Directions Directions {column="EGL.CUSTOMER.DIRECTIONS",
sqlVariableLen=yes, maxLen=255, isSqlNullable=yes};
end
The code tablenames=[["EGL.CUSTOMER"]] specifies
the table in the database that this record relates to, and the column properties
on each of the fields specify the column in the table that the field relates
to. The code keyItems=[CustomerId] indicates that the CustomerId
field, and by connection, the EGL.CUSTOMER.CUSTOMER_ID column of the database,
is the primary key for this table.| EGL command | EGL example | SQL command |
|---|---|---|
| add | add myRecord; |
INSERT |
| get | get myRecord; |
SELECT |
| replace | replace myRecord; |
UPDATE |
| delete | delete myRecord; |
DELETE |
add myCustomer;If you place the cursor on the myCustomer record, right-click, and then click , the EGL editor expands the add statement to show the SQL code, making the SQL code explicit:

add myCustomer with
#sql{
insert into EGL.CUSTOMER
(EGL.CUSTOMER.CUSTOMER_ID, EGL.CUSTOMER.FIRST_NAME,
EGL.CUSTOMER.LAST_NAME, EGL.CUSTOMER.PASSWORD,
EGL.CUSTOMER.PHONE, EGL.CUSTOMER.EMAIL_ADDRESS,
EGL.CUSTOMER.STREET, EGL.CUSTOMER.APARTMENT,
EGL.CUSTOMER.CITY, EGL.CUSTOMER."STATE",
EGL.CUSTOMER.POSTALCODE, EGL.CUSTOMER.DIRECTIONS)
values
(:myCustomer.CustomerId, :myCustomer.FirstName,
:myCustomer.LastName, :myCustomer.Password,
:myCustomer.Phone, :myCustomer.EmailAddress,
:myCustomer.Street, :myCustomer.Apartment,
:myCustomer.City, :myCustomer.State,
:myCustomer.Postalcode, :myCustomer.Directions)
};
Nothing of substance has changed; EGL has merely exposed the
SQL code that it generates from the add statement.
Now that the code is explicit, you can edit the default SQL generated from
the EGL command.The VALUES clause of the SQL INSERT statement lists the values to insert into the new database row, in this case, fields in the myCustomer record. Each value inside the #sql block is preceded by a colon (:), indicating that the value is not an SQL value but an EGL value. These EGL values used in the explicit SQL code are referred to as host variables.
function getCustFromState(customerState CHAR(2) in,
customers Customer[] out)
get customers with
#sql{
select *
from EGL.CUSTOMER
where EGL.CUSTOMER."STATE" like :customerState
};
end
This function receives a two-byte CHAR parameter and uses that
parameter as a host variable to retrieve the records that have a STATE field
matching those two characters. Careful use of host variables is critical to
making EGL work with explicit SQL code.