(To clarify, the '$.hash' as the second parameter of json_extract is
specifying to extract the 'hash' attribute from the root of the JSON object
stored in the json column, per
https://sqlite.org/json1.html#compiling_the_json1_extension )

On Fri, Jun 9, 2017 at 9:04 PM, Zach C. <fxc...@gmail.com> wrote:

> 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 <akupr...@shaw.ca> wrote:
>
>> > 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/tc
>> l2017/
>> 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