Using the Inquire_sql Statement
The inquire_sql statement provides several types of information about the state of the application at run time:
• The number of rows affected by the last query statement
• The error number for any error that occurred on the last query
• The associated error text if an error occurred on the last query
• The session identifier for the current database connection.
• The connection name specified for the current database connection.
The following section discusses the rowcount, errorno, and errortext values returned by inquire_sql.
You also can use the inquire_sql statement to retrieve information about database events that have been raised. For a detailed discussion of using the inquire_sql statement with database events, see
4GL Statement Glossary.
Use rowcount to determine how many rows were found by a select statement, added by an insert statement, changed by an update, or deleted by a delete statement. For example:
partstbl := select * from parts;
inquire_sql (rcount = rowcount);
if rcount < 1 then
message 'No records were found';
sleep 3;
endif;
When used in conjunction with select statements, the following rules apply:
• A singleton select always causes inquire_sql to return a value of 0 or 1 for rowcount.
• For attached queries, the value is the number of rows actually viewed by the user, as controlled by the next statement in the submenu.
Use errorno and errortext to check the results of a query operation, as in this example:
delete from employee
where empnum = :empnum;
inquire_sql (errno = errorno,
txt = errortext);
if errno != 0 then
message 'Delete error ' + char(:errno) + ' ' + :txt;
else
commit;
endif;
Use inquire_sql after the query statement but before commit. For more information about errors returned by inquire_sql and a complete list of its parameters, see the section Inquire_sql.
Last modified date: 04/03/2024