total_pages) {
current_page := total_pages;
}
-- Calculate record range for this page
start_row := (current_page - 1) * page_size + 1;
end_row := start_row + page_size - 1;
if (end_row > total_records) {
end_row := total_records;
}
-- Get sort parameters (default to sorting by CustomerID)
order_by := http_param('order_by');
if (order_by is null or order_by = '' or order_by = 0) {
order_by := 'CustomerID';
}
direction := http_param('direction');
if (direction is null or direction = '' or direction = 0) {
direction := 'ASC';
}
?>
Customer ID
Company Name
Contact Name
Country
'')
order_clause := sprintf('ORDER BY %s %s', order_by, direction);
else
order_clause := '';
-- Create the SQL for pagination using Virtuoso's TOP syntax
sql_text := sprintf('
SELECT TOP (%d, %d) CustomerID, CompanyName, ContactName, Country
FROM Demo.demo.Customers
%s',
(current_page - 1) * page_size, page_size, order_clause);
DECLARE cursor_handle, state, message, data_row any;
state := '00000';
dbg_obj_print (sql_text);
if (0 <> exec (sql_text, state, message, vector(), 0, null, null, cursor_handle))
{
rollback work;
; --- handle error state, message
}
else
{
while (exec_next(cursor_handle, state, message, data_row) = 0)
{
http(sprintf('