How to sort a cursor ?

Robert Brenstein rjb at robelko.com
Mon Feb 21 23:59:52 CST 2005


>I am using one main cursor for each table. When I want to use it, I 
>just put its ref into CursorRef.
>Let us say one of the cursors ref is "cursor1Ref".
>My column headings are made of buttons used to sort the columns.
>I must create a cursor with every sort to have the navigation arrows 
>working properly.
>
>To do that, I must :
>(cursor1Ref is put into cursorRef)
>
>1 - ask for the sql string of cursor1Ref
>2 - change the "order by" in the sql
>3 - remove the cursor - because Valentina does not let me create a 
>cursor with the same query even with a different name.
>4 - create a new cursor
>5 - save its value into cursor1Ref
>6 - put it into CursorRef.
>
>Maybe I am doing things in a complicated manner ?
>Please let me know.
>Roger;

This of course all depends on the data and program specifics, but in 
general, you can use SqlSelectRecords instead of SqlSelect, so you 
have all your display data in a variable, global or local, so it 
persists.

put Valentina("Database_SqlSelectoRecords",dbRef,query) into displayList

Then clicking any sort button calls a card handler that redisplays 
that variable after sorting it by a specific column.

on displaySorted sortColumn,sortType
   set the itemDelimiter to tab
   sort lines of displayList sortType by item sortColumn of each
   put displayList into fld "xyz"
end displaySorted

This is generally simpler than using multiple SQL queries and 
managing cursors. This also reduces shuffling data through valentina 
external which ads some pverhead by having to convert values to 
proper types.

BTW, you don't have to use buttons as column headings to achieve the 
above. You can have a text field and check the clickcharchunk to 
figure which header (field item) was clicked, then sort accordingly 
and underline that header to indicate sorting column by setting the 
textstyle of that item.

Robert


More information about the Valentina mailing list