On 11/17/2017 03:20 PM, Cecil Westerhof wrote:
The folowing works:
     db eval ${getTeasToDrinkStr} {
         puts [format "%-30s %-10s %2s %d" ${Tea} ${Last Used} ${Location}
${Randomiser}]
     }
​
But I want to reuse what I get, so I tried the following:
​    set teaChoices [db eval ${getTeasToDrinkStr}]
     foreach tea [array names teaChoices] {
         puts ${teaChoices}(${tea})
     }

But that does not work. teaChoices is filled, but not as an array. When
using:
     puts ${teaChoices}
     puts [array size teaChoices]

I see in the first line what I expect in teaChoices, but the size is zero.
So teaChoices is a string instead of an array. How do I get it filled as an
array?

$teaChoices is a Tcl list. Assuming your query is still:

  SELECT tea, "last used", location FROM teaInStock;

then $teaChoices contains three elements for each row returned by the query. The first of each set of three is the "tea", the second the "last used" value and the third the "location". So:

  set teaChoices [db eval $getTeasToDrinkStr]
  for {t last_used loc} $teaChoices {
    puts $t
  }

will print the list of teas.

Not sure whether or not you really want an "array". In Tcl, array means associative array - a key-value structure like an STL map. A list is a flat vector of values, like an STL vector or an array in plain old C.

Dan.


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to