Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
2017-11-17 13:51 GMT+01:00 Peter Da Silva : > Sqlite will perform the substitution of Tcl variables in a query. You can > flag the variable with a ‘$’ or with a ‘:’ (which makes it more like other > SQL APIs). > ​Yes, I found that. The disadvantage is that you have

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
2017-11-17 12:43 GMT+01:00 Cecil Westerhof : > I have the following: > set getLatestTeasStr { > SELECT Tea > FROM teaInStock > ORDER BY LastUsed DESC > LIMIT5 > ; > } > > But because I want to define the limit at

Re: [sqlite] Starting with TCL

2017-11-17 Thread Richard Hipp
On 11/17/17, Peter Da Silva wrote: > > $db eval { > SELECT Tea > FROM teaInStock > ORDER BY LastUsed DESC > LIMIT $nrToFetch; > } { > ... do something with $Tea ... > } > > This latter

Re: [sqlite] Starting with TCL

2017-11-17 Thread Peter Da Silva
Sqlite will perform the substitution of Tcl variables in a query. You can flag the variable with a ‘$’ or with a ‘:’ (which makes it more like other SQL APIs). So you can write: $db eval { SELECT Tea FROM teaInStock ORDER BY LastUsed DESC

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
I have the following: set getLatestTeasStr { SELECT Tea FROM teaInStock ORDER BY LastUsed DESC LIMIT5 ; } But because I want to define the limit at runtime I want to change it to: set getLatestTeasStr { SELECT Tea

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
​In Bash I can use: continue 2 ​to continue not the current loop, but the loop surrounding it. This does not work in TCL. Is there another way to do this? -- Cecil Westerhof ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
2017-11-17 9:57 GMT+01:00 Dan Kennedy : > > This gives: >> wrong # args: should be "for start test next command" >> while executing >> "for {t last_used loc} $teaChoices { >> puts $t >> } >> > > Sorry - [for] should be [foreach]. > > So with your query as above,

Re: [sqlite] Starting with TCL

2017-11-17 Thread Simon Slavin
On 16 Nov 2017, at 6:58pm, Richard Hipp wrote: > Everything in TCL is a function. On 17 Nov 2017, at 8:38am, Dan Kennedy wrote: > `In Tcl, array means associative array - a key-value structure like an STL > map. A list is a flat vector of values, like

Re: [sqlite] Starting with TCL

2017-11-17 Thread Clemens Ladisch
Simon Slavin wrote: > I thought in Tcl everything was a function ? In Tcl, all values are strings. A list is a string with entries as words according to the Tcl syntax rules. A dictionary is a list with an even number of elements (key/value pairs). (An array is not a

Re: [sqlite] Starting with TCL

2017-11-17 Thread Dan Kennedy
​Nope, this one is: SELECT Tea FROM teaInStock ORDER BY "Last Used" DESC LIMIT5 ; ​ 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

Re: [sqlite] Starting with TCL

2017-11-17 Thread Simon Slavin
On 17 Nov 2017, at 8:38am, Dan Kennedy wrote: > 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. I

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
2017-11-17 9:38 GMT+01:00 Dan Kennedy : > 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

Re: [sqlite] Starting with TCL

2017-11-17 Thread Dan Kennedy
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

Re: [sqlite] Starting with TCL

2017-11-17 Thread Cecil Westerhof
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

Re: [sqlite] Starting with TCL

2017-11-16 Thread Cecil Westerhof
2017-11-17 5:38 GMT+01:00 Cecil Westerhof : > setsqliteVersion [sqlite3 -version] > ​By the way, I think it is a good idea to amend: https://sqlite.org/tclsqlite.html to show this possibility. -- Cecil Westerhof

Re: [sqlite] Starting with TCL

2017-11-16 Thread Cecil Westerhof
2017-11-16 22:20 GMT+01:00 Richard Hipp : > On 11/16/17, Cecil Westerhof wrote: > > ​Is it possible to get the library version before connecting to a > database? > > puts [sqlite -version] > ​Combining yours and Eric's version, I made: #!/usr/bin/env

Re: [sqlite] Starting with TCL

2017-11-16 Thread Eric
On Thu, 16 Nov 2017 21:28:10 +0100, Cecil Westerhof wrote: > Is it possible to get the library version before connecting to a database? > Now I do the following: > #!/usr/bin/env tclsh > > package require sqlite3 > > > sqlite3 db ~/Databases/general.sqlite > > puts

Re: [sqlite] Starting with TCL

2017-11-16 Thread Richard Hipp
On 11/16/17, Cecil Westerhof wrote: > ​Is it possible to get the library version before connecting to a database? puts [sqlite -version] -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list

Re: [sqlite] Starting with TCL

2017-11-16 Thread Cecil Westerhof
​Is it possible to get the library version before connecting to a database? Now I do the following: #!/usr/bin/env tclsh package require sqlite3 sqlite3 db ~/Databases/general.sqlite puts [db version] But I would prefer to check the version before connecting to a database. Is this possible?

Re: [sqlite] Starting with TCL

2017-11-16 Thread Cecil Westerhof
2017-11-16 18:44 GMT+01:00 Peter Da Silva : > > On 11/16/17, 11:37 AM, "sqlite-users on behalf of Cecil Westerhof" < > sqlite-users-boun...@mailinglists.sqlite.org on behalf of > cldwester...@gmail.com> wrote: > > When I use: > > db eval {SELECT * FROM

Re: [sqlite] Starting with TCL

2017-11-16 Thread Richard Hipp
On 11/16/17, Cecil Westerhof wrote: > puts $Tea, $Location Everything in TCL is a function. The syntax is "FUNCTIONNAME ARG1 ARG2 ARG3 ..." where the arguments are separated by white space. The "puts" function takes either one or two arguments. The one-argument

Re: [sqlite] Starting with TCL

2017-11-16 Thread Peter Da Silva
On 11/16/17, 11:37 AM, "sqlite-users on behalf of Cecil Westerhof" wrote: > When I use: > db eval {SELECT * FROM teaInStock} { >puts $Tea, $Location > } puts takes a single string, so you can do