title: can't read utf8 strings from MySQL DB by an odbc client
body: <p>I have a DB with utf8 default charset, and a table that contains strings with non-ascii characters. I can read the data correctly by the <code>mysql</code> client program and the <code>isql</code> odbc client program (see examples below). However, when I read the table in my C++ client using the <a href="http://libodbcxx.sourceforge.net/" rel="nofollow">libodbc++</a> odbc wrapper, I get garbage. </p>
  
  <p>Curiously, I've been using the default MySql settings until now, i.e. <code>latin1</code> charset, but the data actually contained utf8 strings. This way, I was getting utf8 ok. I changed the DB to utf8 so that I can use <code>utf8_bin</code> collation.</p>
  
  <p>Since I use <code>set names utf8</code> in the client I expect no charset conversion to happen between client and server. Am I wrong? </p>
  
  <p>Are you aware of charset problems with libodbc++?</p>
  
  <p><strong>EDIT</strong>: just tested this with a "pure" odbc client (disgusting...), works ok. Strange, since libodbc++ is just a wrapper for odbc, I'd expect it not to have such effect on the data. Anyway, the suspect is libodbc++ library.</p>
  
  <pre><code>mysql&gt; show full columns from tbl_list_domains;
  +-------+-----------+-----------+------+-----+---------+-------+---------------------------------+---------+
  | Field | Type      | Collation | Null | Key | Default | Extra | Privileges                      | Comment |
  +-------+-----------+-----------+------+-----+---------+-------+---------------------------------+---------+
  | word  | char(100) | utf8_bin  | NO   | PRI | NULL    |       | select,insert,update,references |         | 
  +-------+-----------+-----------+------+-----+---------+-------+---------------------------------+---------+
  
  
  $ mysql -u mysql navajoLocal &lt;&lt;&lt; "set names utf8; select * from tbl_list_domains order by word limit 30" &gt; out
  </code></pre>
  
  <p>The file <code>out</code> comes out good:</p>
  
  <pre><code>word
  aa
  ab
  ac
  ad
  ae
  ...etc.
  </code></pre>
  
  <p>Using <code>isql</code> odbc client:</p>
  
  <pre><code>echo -e "set names utf8 \n select * from tbl_list_domains order by word limit 30" |isql mysql3-test -v -b -x0x20 &gt; out
  </code></pre>
  
  <p>still good.</p>
  
  <p>however this:</p>
  
  <pre><code>int main()
  {
   ConnectionPtr conn = ConnectionPtr( DriverManager::getConnection("Driver=mysql3;database=navajoLocal;server=localhost;user=mysql;option=3;socket=/var/lib/mysql/mysql.sock") );
  
   StatementPtr st = StatementPtr( conn-&gt;createStatement() );
   st-&gt;executeUpdate("set names utf8 collate utf8_bin");
  
   ResultSetPtr res = ResultSetPtr( st-&gt;executeQuery("select word from tbl_list_domains order by word limit 30") );
  
   string s;
   while (res-&gt;next()) {
    s = res-&gt;getString(1);
    cout &lt;&lt; s &lt;&lt; endl;
   }
  }
  </code></pre>
  
  <p>gives out this:</p>
  
  <pre><code>a^@
  a^@
  a^@
  a^@
  </code></pre>