title: MySql C++ connector getString() doesn't work correctly, while getInt works perfectly
body: <p>I tried to connect C++ to MySql and I just can't get this to work properly.  I used latest MySql and C++/Connector for Windows from Oracle site.  I also use VS2010.</p>
  
  <p>It compiles and everything works EXCEPT getString!  I used the example that they supply with some tweaking:</p>
  
  <pre><code>#include "stdafx.h"
  
  
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;stdexcept&gt;
  
  #include &lt;driver/mysql_public_iface.h&gt;
  
  #include "examples.h"
  
  using namespace std;
  
  int main(int argc, const char **argv)
  {
  string url(argc &gt;= 2 ? argv[1] : EXAMPLE_HOST);
  const string user(argc &gt;= 3 ? argv[2] : EXAMPLE_USER);
  const string pass(argc &gt;= 4 ? argv[3] : EXAMPLE_PASS);
  const string database(argc &gt;= 5 ? argv[4] : EXAMPLE_DB);
  
  /* sql::ResultSet.rowsCount() returns size_t */
  size_t row;
  stringstream sql;
  stringstream msg;
  int i, affected_rows;
  
  cout &lt;&lt; boolalpha;
  cout &lt;&lt; "1..1" &lt;&lt; endl;
  cout &lt;&lt; "# Connector/C++ connect basic usage example.." &lt;&lt; endl;
  cout &lt;&lt; "#" &lt;&lt; endl;
  
  try {
      sql::Driver * driver = sql::mysql::get_driver_instance();
      /* Using the Driver to create a connection */
      std::auto_ptr&lt; sql::Connection &gt; con(driver-&gt;connect("localhost", "root", "root"));
  
      /* Creating a "simple" statement - "simple" = not a prepared statement */
      std::auto_ptr&lt; sql::Statement &gt; stmt(con-&gt;createStatement());
  
      /* Create a test table demonstrating the use of sql::Statement.execute() */
      stmt-&gt;execute("USE publications");
      cout &lt;&lt; "#\t Test table created" &lt;&lt; endl;
  
      /* Populate the test table with data */
  
      cout &lt;&lt; "#\t Test table populated" &lt;&lt; endl;
  
      {
          /*
          Run a query which returns exactly one result set like SELECT
          Stored procedures (CALL) may return more than one result set
          */
          std::auto_ptr&lt; sql::ResultSet &gt; res(stmt-&gt;executeQuery("SELECT id, task FROM to_do_list ORDER BY id ASC"));
          cout &lt;&lt; "#\t Running 'SELECT id, task FROM to_do_list ORDER BY id ASC'" &lt;&lt; endl;
  
          /* Number of rows in the result set */
          cout &lt;&lt; "#\t\t Number of rows\t";
          cout &lt;&lt; "res-&gt;rowsCount() = " &lt;&lt; res-&gt;rowsCount() &lt;&lt; endl;
          if (res-&gt;rowsCount() != EXAMPLE_NUM_TEST_ROWS) {
              msg.str("");
              msg &lt;&lt; "Expecting " &lt;&lt; EXAMPLE_NUM_TEST_ROWS &lt;&lt; "rows, found " &lt;&lt; res-&gt;rowsCount();
              throw runtime_error(msg.str());
          }
  
          /* Fetching data */
          row = 0;
          while (res-&gt;next()) {
              cout &lt;&lt; "#\t\t Fetching row " &lt;&lt; row &lt;&lt; "\t";
              /* You can use either numeric offsets... */
              cout &lt;&lt; "id = " &lt;&lt; res-&gt;getInt("id");
              /* ... or column names for accessing results. The latter is recommended. */
              cout &lt;&lt; ", task = '" &lt;&lt; res-&gt;getString("task") &lt;&lt; "'" &lt;&lt; endl;
              row++;
              system("PAUSE");
          }
      }
  </code></pre>
  
  <p>... //the rest isn't relevant because it breaks here.</p>
  
  <p>This is the output:</p>
  
  <pre><code>1..1
  # Connector/C++ connect basic usage example..
  #
  #        Test table created
  #        Test table populated
  #        Running 'SELECT id, task FROM to_do_list ORDER BY id ASC'
  #                Number of rows res-&gt;rowsCount() = 4
  #                Fetching row 0 id = 3, task = ''
  Press any key to continue . . .
  #                Fetching row 1 id = 7, task = ''
  Press any key to continue . . .
     ☼   Ñ╤½x R=  I&gt;             ☼   £I&gt; task  ↕ 4å@ xQ@ ♦   ☼   ☻    ocalhost ½xÇ
  '
  Press any key to continue . . .
  </code></pre>
  
  <p>and this is what the table looks like so clearly it's not working properly.  I just can't get it to get the strings which are varchar(120) from MySql:</p>
  
  <pre><code>mysql&gt; use publications
  Database changed
  mysql&gt; select id, task from to_do_list;
  +----+---------------------------+
  | id | task                      |
  +----+---------------------------+
  |  9 | prepare for calculus      |
  |  3 | buy jeans                 |
  |  8 | buy new scale             |
  |  7 | buy Ethics book for class |
  +----+---------------------------+
  4 rows in set (0.00 sec)
  </code></pre>
  
  <p>I tried VS2008 and this is what I get:</p>
  
  <blockquote>
    <p>msvcp90d.dll!104e8dcb()<br>
        [Frames below may be incorrect and/or missing, no symbols loaded for msvcp90d.dll]<br>
        try_mysql_native.exe!std::operator&lt;&lt;(std::basic_ostream > &amp; os={...}, const sql::SQLString &amp; str={...})  Line 196 + 0x1f bytes  C++
        try_mysql_native.exe!main(int argc=1, const char * * argv=0x003e63e8)  Line 115 + 0xa5 bytes    C++
        try_mysql_native.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes C
        try_mysql_native.exe!mainCRTStartup()  Line 403 C
        kernel32.dll!7c817077() </p>
  </blockquote>
  
  <p>and this:</p>
  
  <p>'try_mysql_native.exe': Loaded 'C:\Documents and Settings\Eugene\My Documents\Visual Studio 2008\Projects\try_mysql_native\Debug\try_mysql_native.exe', Symbols loaded.
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\mysqlcppconn.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\libmysql.dll', Symbols loaded.
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4974_x-ww_d889290f\msvcp90.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4974_x-ww_d889290f\msvcr90.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcr90d.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_f863c71f\msvcp90d.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\mswsock.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\dnsapi.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\winrnr.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\wldap32.dll'
  'try_mysql_native.exe': Loaded 'C:\Program Files\Bonjour\mdnsNSP.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\iphlpapi.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\rasadhlp.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\hnetcfg.dll'
  'try_mysql_native.exe': Loaded 'C:\WINDOWS\system32\wshtcpip.dll'
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  First-chance exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.
  Unhandled exception at 0x104e8dcb in try_mysql_native.exe: 0xC0000005: Access violation reading location 0x6e61656a.    </p>