On 1/11/17, Scott Hess <sh...@google.com> wrote:
> Though it may be cleaner long-term to implement system() to pass
> individual arguments, rather than passing a single string which will
> have to be re-processed by the shell.  So the API would end up like:
>   UPDATE result SET nRows = system('wc', '-l', fileNames);
>
> The reason I suggest this is because [fileNames] could have spaces
> which would have to be escaped, but there are probably a dozen other
> similar issues which are likely to come up.
>
> [Though, yes, this means you'll have to use fork() and execlp() and
> waitpid() to implement, rather than popen().

Which further means that the code would not be portable to Windows.

> There are examples out
> there of how to do that:
>
> https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132
> ]
>
> -scott
>
> On Wed, Jan 11, 2017 at 1:38 PM, Roman Fleysher
> <roman.fleys...@einstein.yu.edu> wrote:
>> Yes, Richard, this is exactly what I mean.
>>
>> Roman
>> ________________________________________
>> From: sqlite-users [sqlite-users-boun...@mailinglists.sqlite.org] on
>> behalf of Richard Hipp [d...@sqlite.org]
>> Sent: Wednesday, January 11, 2017 4:34 PM
>> To: SQLite mailing list
>> Subject: Re: [sqlite] extension to run bash
>>
>> On 1/11/17, Roman Fleysher <roman.fleys...@einstein.yu.edu> wrote:
>>> Dear SQLites,
>>>
>>> I am using exclusively sqlite3 shell for all the processing and may need
>>> ability to run bash commands and assign result to a column. For example:
>>>
>>> UPDATE  result SET nRows =` wc -l fileNames` ;
>>>
>>> Here I used `` as would be in bash for command substitution. This would
>>> run
>>> wc command (word count), count number of lines in each file listed in
>>> column
>>> fileNames and update the row correspondingly.
>>>
>>> As far as I understand I should be able to write loadable extension to
>>> accomplish this.
>>
>> No, You cannot do exactly what you describe with a loadable extension.
>>
>> But you could, perhaps, create a loadable extension that implements a
>> new system() SQL function like this:
>>
>>    UPDATE result SET nRows = system('wc -l ' || fileNames);
>>
>> Note that || is the SQL string concatenation operator.  You didn't
>> say, but I'm guessing that fileNames is a column in the result table.
>> --
>> D. Richard Hipp
>> d...@sqlite.org
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users@mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>> _______________________________________________
>> sqlite-users mailing list
>> sqlite-users@mailinglists.sqlite.org
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to