The stereotyping (see Stereotypes) provides unique properties at the record level and field level. When you use a variable of this type as the target of an EGL data access statement such as get or replace, it triggers specific behavior.
EGL can automatically create SQLRecord parts based on information from your database; for more information, see Creating a data access application in the EGL Programmer's Guide.
Record CustomerRecord type SQLRecord { tableNames = [["Customer"]] } ... end
In most cases, the SQL default select condition supplements a second condition, which is based on an association between the key-field values in the SQL record and the key columns of the SQL table.
Specify the conditions using the #sqlCondition directive; for more information, see #sqlCondition directive.
myTable STRING; Record CustomerRecord type SQLRecord { tableNameVariables = [["myTable"]] } ... end myCustomer CustomerRecord; function main() myTable = requestTableName(); get myCustomer; displayCustomer(myCustomer); end
{ tableNameVariables = [["myTable", "T1"], ["myOtherTable", "T2"]] }
package com.CompanyB.CustomerPackage; Record CustomerRecord type SQLRecord { tableNames=[["Customer", "T1"]], keyItems=["customerNumber"] } customerNumber INT {column = "customer_number"}; customerName STRING {column = "customer_name"}; customerBalance DECIMAL(9,2) {column = "customer_balance"}; end Record OrderRecord type SQLRecord { tableNames=[["Orders", "T2"]], keyItems=["orderNumber"] } orderNumber INT {column = "order_number"}; customerNumber INT {column = "customer_number"}; orderTotal DECIMAL(9,2) {column = "order_total"}; end program CustomerTest type BasicProgram myCustomer CustomerRecord; myOrder OrderRecord; function main() myCustomer.customerNumber = 1001; get myCustomer with #sql{ select customer_name, order_total from Customer T1, Orders T2 join Orders on T1.customer_number = T2.customer_number where T1.customer_number = :myCustomer.customerNumber } into myCustomer.customerName, myCustomer.customerBalance; end end
The customerNumber field is a primary key in the Customer table and a foreign key in the Order table. However, after you join the two tables, you must use the T1 or T2 designation to specify which customerNumber the code refers to.