Working with SQL statements

With EGL you can deal with explicit SQL code in your EGL program.

You can do some reasonably sophisticated database manipulation in EGL without writing a word of SQL. Experienced SQL programmers, however, might want the level of control that writing in SQL gives them. EGL accommodates those programmers through the #sql directive.

The #sql directive

The EGL keyword #sql introduces a section of explicit SQL code, delimited by braces, as in the following example:
get myCustomer with #sql{
  select C_NUMBER, C_NAME, C_ADDR1, C_ADDR2, C_ADDR3, C_BALANCE
  from ADMINISTRATOR.CUSTOMER L1
  where C_NUMBER = :myCustomer.customerNumber };

You may modify this code to fine tune your SELECT statement. For more information, see Viewing implicit SQL statements. You can also use the #sql directive to call a stored procedure (see Calling a stored procedure).

Host variables

You might have noticed in the preceding example that the variable myCustomer.customerNumber has a colon in front of it. This tells EGL to look for the variable name within the EGL program, not the SQL table. Such variables are called host variables, because EGL is the programming language that is hosting SQL; SQL cannot run as an independent language.


Feedback