Ihor Radchenko <[email protected]> wrote:
>> | #+HEADERS: :var p=(completing-read "Parameter: " '("a" "b" "c"))
>> | #+BEGIN_SRC sql :engine postgres :cmdline --no-psqlrc -q
>> | BEGIN WORK;
>> | \set filedata `cat /path/to/'$p'.txt`
>> | SELECT '$p', :'filedata';
>> | COMMIT WORK;
>> | #+END_SRC
>> This works well unless the argument contains a character
>> that needs to be escaped in a PostgreSQL/Bash string, for
>> example "'", as Org mode inserts the argument as is.
>> ...
>> | #+HEADERS: :var pb64=(base64-encode-string (encode-coding-string
>> (completing-read "Parameter: " '("a" "b" "c")) 'utf-8))
> What about simply shell-quote-argument instead of going rounds with encoding?
Ha! Because I only considered standard (Postgre)SQL string
constants and not escape ones. With the latter, that works
at first glance:
| SELECT E'$p', :'filedata';
… but fails for even simple special cases:
| ELISP> (shell-quote-argument "")
| "''"
| ELISP> (shell-quote-argument "foo\nbar")
| "foo'
| 'bar"
| ELISP>
| => SELECT E'''';
| ?column?
| ----------
| '
| (1 Zeile)
| => SELECT E'foo'
| -> 'bar';
| ?column?
| ----------
| foobar
| (1 Zeile)
| =>
So I probably stick with Base64.
Tim