Programming Guide



@dmrowcount

Contains a count of the number of rows either fetched to Panther or affected by the previous statement

Description

The use of this variable is dependent on the database engine. On all engines, @dmrowcount is set to the number of rows fetched to Panther variables in a SELECT statement or CONTINUE command. On some engines, it can also reflect the number of rows affected by an INSERT, UPDATE, and DELETE statement.

@dmrowcount is set to 0 before each new DBMS command is executed. You must copy its value to another location if you want to use the value after subsequent commands.

If the command fetches rows, Panther updates @dmrowcount writing the number of rows fetched to Panther variables. Most SQL syntaxes provide an aggregate function COUNT to count the number of values in a column or the number of rows in a select set. The value of @dmrowcount is not the number of rows in a select set; rather, it is the number of rows returned to Panther variables. Therefore if a select set has 14 rows in total, and its target Panther variables are arrays, each with ten occurrences, @dmrowcount is 10 after the SELECT is executed, and 4 after CONTINUE is executed. If CONTINUE is executed a second time, @dmrowcount would equal 0.

The value of @dmrowcount is either less than or equal to the maximum number of rows that can be written to the target Panther destinations; the maximum number of rows is the number of occurrences in a destination variable. If the value in @dmrowcount is less than the maximum number of occurrences, then the entire select set is written to the target variables and no further processing is needed. If @dmrowcount equals the maximum number of occurrences, then the SELECT might fetch more rows than can fit in the variables. To display the rest of the select set, the application must execute CONTINUE until @dmrowcount is less than the maximum number of occurrences (or equals 0) or until @dmretcode receives the DM_NO_MORE_ROWS code.

For information on whether the variable can be used to obtain the number of rows affected by an INSERT, UPDATE, or DELETE statement, refer to the Database Drivers for the specified engine.

If you are using the transaction manager, call sm_tm_inquire(TM_OCC_COUNT) to find the number of rows fetched in the current server view. Since a transaction command can consist of more than one DBMS command, @dmrowcount might have already been overwritten.

Example

proc get_selection
DBMS QUERY SELECT * FROM titles WHERE genre_code=:+type
call check_count
return
proc check_count
# If rows are returned but not the NO_MORE_ROWS code,
# let the user know there are rows pending.
if (@dmrowcount > 0) && \
(@dmretcode != DM_NO_MORE_ROWS)
msg setbkstat "Press %KPF1 to see more."
else
msg setbkstat "All rows returned."
return
proc get_more
# This function is called by pressing PF1.
# It retrieves the next set of rows.
DBMS CONTINUE
call check_count
return