How do I output multi-word strings without braces?

View: New views
4 Messages — Rating Filter:   Alert me  

How do I output multi-word strings without braces?

by Walter Dnes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

  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.

--
Walter Dnes <waltdnes@...>
_______________________________________________
sqlite-users mailing list
sqlite-users@...
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Re: How do I output multi-word strings without braces?

by Dan Kennedy-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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@...
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Re: How do I output multi-word strings without braces?

by Walter Dnes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 10, 2009 at 03:06:08AM -0500, 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]

  Oops, I forgot to mention that this is the TCL interface to SQLite.
This is one of those "grey area" questions that could go to either TCL
or SQLite forums, because it's an interaction between the two of them.
I assume that some people here have dealt with this issue before.

--
Walter Dnes <waltdnes@...>
_______________________________________________
sqlite-users mailing list
sqlite-users@...
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Re: How do I output multi-word strings without braces?

by D. Richard Hipp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 10, 2009, at 2:01 PM, Walter Dnes wrote:
>
>  Oops, I forgot to mention that this is the TCL interface to SQLite.
> This is one of those "grey area" questions that could go to either TCL
> or SQLite forums, because it's an interaction between the two of them.
> I assume that some people here have dealt with this issue before.


SQLite began as a TCL extension.  The TCL bindings for SQLite are  
native to the SQLite source tree.  TCL is used to test SQLite.  TCL is  
required in order to build SQLite from original source files.  74% of  
the code in the source SQLite tree is TCL script.

We're comfortable having mixed Tcl/SQLite questions here.  http://www.sqlite.org/docsrc/artifact/07b4fa3fd6

D. Richard Hipp
drh@...



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