Embedded Statements Inside Pascal If Blocks
As mentioned above, the preprocessor may produce several Pascal statements for a single Embedded SQL statement. However, all the statements generated by the preprocessor are enclosed in Pascal begin and end delimiters, composing a Pascal block. Thus the statement:
if (not dba) then
exec sql select passwd
into :passwd
from security
where usrname = :userid;
will produce legal Pascal code, even though the SQL select statement produces more than one Pascal statement. However, two or more Embedded SQL statements will generate multiple Pascal blocks, so you must delimit them yourself, just as you would delimit two Pascal statements in a single if block. For example:
if (not dba) then
begin
exec frs message 'Confirming your user id';
exec sql select passwd
into :passwd
from security
where usrname = :userid;
end;
Note that, because the preprocessor generates a Pascal block for every Embedded SQL statement, the Pascal compiler may generate the error "Internal Table Overflow" when a single procedure has a very large number of Embedded SQL statements and local variables. You can correct this problem by splitting the file or procedure into smaller components.
All Embedded SQL statements must be terminated by a semicolon. Therefore, because Pascal does not permit semicolons before the else clause of an if statement, you must surround any single Embedded SQL statement that precedes an else clause with a Pascal begin-end block. For example, the following if statement will cause a Pascal error:
if error then
exec frs message 'Error occurred';
{Semicolon required by Embedded SQL}
else
exec frs message 'No error occurred';
By delimiting the then clause with begin-end, you eliminate the error:
if error then
begin
exec frs message 'Error occurred';
{Semicolon required by Embedded SQL}
end {
| ... but that's okay because
| there's no semicolon here
}
else
exec frs message 'No error occurred';