On Nov 10, 2009, at 3:06 PM, Walter Dnes wrote:

> Given the following code fragment...
>
> set xname [db eval { select name from elements where e_mtid =  
> $element }]
> puts [format "Requested element ==> %s ==> %s" $element $xname]
>
> The "business rules" are such that I know I'll only get one row
> returned.  I get output like so...
>
> Requested element ==> abcdef ==> {FOO BAR}
>
> What I need is...
>
> Requested element ==> abcdef ==> FOO BAR
>
> What do I need to do to get rid of the braces around the output name?
> And no, that's not how the data looked in the tab-delimited file it  
> was
> imported from.

[db eval] returns a list of values. In this case your list consists of
a single string - "FOO BAR". Tcl adds the braces to distinguish this
list from the two element list that consists of "FOO" followed by "BAR".

If you know in advance that your query will return a single element,
use [db one] instead of [db eval]. To extract elements from a list, use
[lindex]. To summarize, either of the following will probably work for
you:

set xname [db eval { select name from elements where e_mtid =  
$element }]

or,

set xname [lindex [db eval { select ... }] 0]

Dan.


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

Reply via email to