> On 6/9/17, Zach C. <fxc...@gmail.com> 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 <akupr...@shaw.ca>
                        <http://core.tcl.tk/akupries/>
        Developer @     SUSE (MicroFocus Canada LLC)
                        <andreas.kupr...@suse.com>

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

Reply via email to