looking for a smart approach to "sort" an array

Mike Bonner bonnmike at gmail.com
Fri May 5 16:52:30 CEST 2017


Bob, can you do a custom sort using order by with sqlite?  I did some
digging and see a way, but for this purpose it seems complicated and I'm
wondering if there is something better than what I found. Basically what I
found was this..

ORDER BY
  CASE ID
    WHEN 4 THEN 0
    WHEN 3 THEN 1
    WHEN 1 THEN 2
    WHEN 5 THEN 3
    WHEN 6 THEN 4
  END

So to my thinking one would build a large "order by" with all the
words and their associated line numbers so you could do

WHEN 'myfirstword' THEN 0.. etc for each word and its line number in
the list.  (Always interested in new ways)


On Fri, May 5, 2017 at 8:37 AM, Bob Sneidar via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Why not load the array into a memory sqlite database and query using order
> by?
>
> Bob S
>
>
> > On May 5, 2017, at 02:30 , Tiemo Hollmann TB via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >
> > Hello,
> >
> > I have a list field of words and a correspondent array with the words of
> the
> > field as the keys plus some data per key. I can store the array in a
> file,
> > read it later from file and rebuild the list of words from the keys of
> the
> > array. Up to now, I had this list of words alphabetically sorted. So it
> was
> > easy, when reloading the array to sort the list always alphabetically to
> > refresh the visible list in the field.
> >
> > The user can also create a custom sequence of the words in the field by
> drag
> > and drop the lines in individual order. Now I am looking for a smart
> > approach to keep the same sort order in the correspondent array. I need
> the
> > custom sort order of the words in case I reload the array later from
> file to
> > get the same sequence of words as the user has sorted them, after
> extracting
> > the words from the array. The key of the array has to keep the words from
> > the list for accessing the data in the array.
> >
> > As far as I see it, I have to add an additional item to the array data,
> > storing the sort sequence of the keys, while the user creates his custom
> > sequence of the words in the list field and keeping this number always
> > synchronous to the line number of the fields list. So I could use this
> "sort
> > sequence number" from the array to rebuild the same sort of the words
> when
> > extracting the words from the array.
> >
> > Would this be the best approach to keep the sort sequence of the words
> > stored with the array, or do you see an easier more straight forward
> > approach to keep the array "synchronous sorted" which I don't see right
> now?
> >
> > Thanks for your input
> >
> > Tiemo
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


More information about the use-livecode mailing list