0

When I perform

#+BEGIN_SRC sql coding: utf-8-with-signature :results list :var did='2019-03-10' cid=77
  select t.titre from titres t inner join selections s on s.tid=t.tid where s.did="$did" and s.cid=$cid and s.choice=1;
#+END_SRC

I get

  • ("Airbnb, la fête est-elle vraiment finie ?" "" "")
  • ("Apprendre à manager une équipe en coachant des moutons" "" "")
  • ("« Stupéfiant ! » met à nu le mystère Houellebecq" "" "")

when I cast titre to binary and convert to utf8...

#+BEGIN_SRC sql coding: utf-8-with-signature :results list :var did='2019-03-10' cid=77
  select trim(convert(cast(t.titre as binary) using utf8)) as titre from titres t inner join selections s on s.tid=t.tid where s.did="$did" and s.cid=$cid and s.choice=1;
#+END_SRC

I get

  • ("Airbnb, la fête est-elle vraiment finie ?" "" "")
  • ("Apprendre à manager une équipe en coachant des moutons" "" "")
  • ("« Stupéfiant ! » met à nu le mystère Houellebecq" "" "")

which is nice and I can live with it... but I want the output without the quotes and the parentheses, so I added org to the list of results parameters

#+BEGIN_SRC sql coding: utf-8-with-signature :results list org :var did='2019-03-10' cid=77
  select trim(convert(cast(t.titre as binary) using utf8)) as titre from titres t inner join selections s on s.tid=t.tid where s.did="$did" and s.cid=$cid and s.choice=1;
#+END_SRC

and I get

  • Airbnb, la f\303\252 est-elle vraiment finie ?

but when I copied the previous sentence into the emacs.stackexchange.com text input it reads like it should, i.e.

  • Airbnb, la fête est-elle vraiment finie ?

the buffer coding system (shown in the lower left corner of the emacs window) says (multi-byte) utf-8-unix.

How can I get the output to print in a human-readable way?

Update I added

 #+name: echo_me
 #+BEGIN_SRC sh :var data="" :results output
   echo "$data"
 #+END_SRC

and added a :post option to the src block

#+BEGIN_SRC sql coding: utf-8-with-signature :results list org :var did='2019-03-10' cid=77  :post echo_me(data=*this*)

now it works fine, but before the output is generated Emacs asks me to pick a coding system (raw), since utf-8-unix does not contain the accented characters. I wonder whether there is a better solution, and I'd like to understand what is happening.

  • "...since utf-8-unix does not contain the accented characters." : I don't believe that is true. Is there a way to simulate what's happening without the database? It would at least make it easier for others to test. If you don't get an answer here, post it on the help-gnu-emacs mailing list. – NickD Mar 15 at 12:27
  • Thanks Nick. When I write "utf-8-unix does not contain the accented characters" I am only reporting what emacs tells me. Here is the the beginning of the message from the *Warning* buffer: These default coding systems were tried to encode text in the buffer ‘*temp*’: (utf-8-unix (20 . 4194243) (21 . 4194218) (61 . 4194243) (62 . 4194208) (76 . 4194243) (77 . 4194217) (108 . 4194242) (109 . 4194219) (115 . 4194243) (116 . 4194217) (125 . 4194242)) However, each of them encountered characters it couldn’t encode: utf-8-unix cannot encode these: – tempestcat Mar 16 at 21:04
  • Emacs then suggests to use 'raw-text' encoding. I copied the *temp* buffer to a file, and tried to reproduce the behavior with the file which is encoded in raw-text, but the shell src block outputs the results without a problem. I think the only way to reproduce the problem would be to provide code to make a temporary mysql table and then use a query on that. – tempestcat Mar 16 at 21:12
  • I removed the post command and saved the file and re-opened it. The "raw-text" output appears fine in the re-opened file. – tempestcat Mar 20 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.