I did try the colon-style formatting as well, it didn't work. I didn't know
about [string map], but I tried it too, no luck:
% set map [dict create <<table>> NotImportant]
<<table>> NotImportant
% mydb eval [string map $map {SELECT json FROM <<table>> WHERE
json_extract(json, '$.hash') = $hash}]
%
On Fri, Jun 9, 2017 at 7:48 PM, Andreas Kupries <[email protected]> wrote:
> > On 6/9/17, Zach C. <[email protected]> wrote:
> > > I was partially unclear with using a constant table name here; what I
> > > actually need as well is the table name as effectively a const that I
> > > control as well. So more like
> > >
> > > mydb eval {$SELECT json FROM $table WHERE json_extract(json, '$.hash')
> =
> > > $someId}
> >
> > Like this then:
> >
> > mydb eval "SELECT json FROM $table WHERE
> > json_extract(json,'\$.hash')=\$someId"
> >
> > Put a backslash \ before every $ that you want passed down into
> > SQLite. And not that you definitely want the $ on $someId passed down
> > into SQLite. You do *not* want TCL to expand $someId for you.
>
> How about using the :-form of variable references ?
>
> mydb eval "SELECT json FROM $table WHERE
> json_extract(json,':.hash')=:someId"
>
> Tcl will ignore that form, and Sqlite will expand them.
> A bit less of quoting hell.
>
> Another alternative:
>
> set map [list <<table> $table]
> mydb eval [string map $map {
> SELECT json
> FROM <<table>>
> WHERE json_extract(json,'$.hash')=$someId
> }]
>
> I.e. explicit interpolation of a chosen placeholder, here <<table>>,
> via [string map], and putting the statement again into {} to prevent
> Tcl from doing variable expansion.
>
> --
> See you,
> Andreas Kupries <[email protected]>
> <http://core.tcl.tk/akupries/>
> Developer @ SUSE (MicroFocus Canada LLC)
> <[email protected]>
>
> Tcl'2017, Oct 16-20, Houston, TX, USA. http://www.tcl.tk/community/
> tcl2017/
> EuroTcl 2017, Jul 8-9, Berlin/DE, http://www.eurotcl.tcl3d.org/
> ------------------------------------------------------------
> -------------------
>
>
>
>
>
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users