2017-11-17 9:38 GMT+01:00 Dan Kennedy <danielk1...@gmail.com>:

> 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;
>

​Nope, this one is:
    SELECT   Tea
    FROM     teaInStock
    ORDER BY "Last Used" DESC
    LIMIT    5
    ;
​


> 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.
>

​This gives:
wrong # args: should be "for start test next command"
    while executing
"for {t last_used loc} $teaChoices {
    puts $t
}

There is something going wrong, because:
    puts [llength teaChoices]
gives:
    1
while it should give:
    5​




> 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.


​Nope, I want a list then. (Or maybe a list of arrays.)​


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

Reply via email to