Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Connector/C++ code crash at line: std::cout<<res->getString("label");
    text
    copied!<p>I know there's a lot of suggestions of how to fix this issue, here in this forum, but none of them solved my problem.</p> <p>It's always the same: code compiles fine and I can use almost all of the getXX members offered by ResultSet, except for getString, that also compiles without problem, but always crash at runtime.</p> <p>I did some weird tries, like getting a char field using getInt("label") or getBlob("label"), the results weren't good as I previouslly had known, but at least I didn't experience crash.</p> <p>I tried versions 1.0.5 and 1.1.3+boost. In case of 1.1.3, I also compiled from source, using CMake, but I supose that my knowlegment about the utility is not sufficient and it would last a long time before I have CMake under control. So I'd like to get a more straight solution.</p> <p>My goal is to create some Win32_Console and WinForms codes, from MSVC 2010, that read and write data in MySQL 5.6 that runs in a XUbuntu machine of my network. And getString() is trapping me a lot.</p> <p>Thanks in advance</p> <p>I've added the code bellow:</p> <pre><code>#include "stdafx.h" #include &lt;iostream&gt; #include &lt;mysql_driver.h&gt; #include &lt;mysql_connection.h&gt; #include &lt;exception.h&gt; #include &lt;statement.h&gt; #include &lt;resultset.h&gt; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { cout&lt;&lt;"Testando uma conexao...\n"; cout&lt;&lt;"Connector 1.1.3:\n"; sql::mysql::MySQL_Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; driver = sql::mysql::get_mysql_driver_instance(); try { con = driver-&gt;connect("tcp://192.168.1.75:3306", "site_rw", ""); if (con-&gt;isClosed()==0) cout&lt;&lt;"Sucesso!\n\n"; cout&lt;&lt;"Inserindo statement...\n"; stmt = con-&gt;createStatement(); stmt-&gt;execute("USE test_area"); stmt-&gt;execute("DROP TABLE IF EXISTS test"); stmt-&gt;execute("CREATE TABLE test(id INT, label CHAR(1))"); cout&lt;&lt;"Criada a tabela...\n"; for (int k=0; k&lt;30;k++) stmt-&gt;execute("INSERT INTO test(id, label) VALUES (1, 'a')"); cout&lt;&lt;"Linhas inseridas...\n"; cout&lt;&lt;"Preparando-se para listar os inteiros:\n"; res = stmt-&gt;executeQuery("SELECT * FROM test LIMIT 0,5"); while (res-&gt;next()) cout&lt;&lt;"id = " &lt;&lt; res-&gt;getInt("id") &lt;&lt; "\n"; cout&lt;&lt;"\n\nAgora tentando o char(1):\n"; res-&gt;beforeFirst(); while (res-&gt;next()) cout&lt;&lt;"label = " &lt;&lt; res-&gt;getString("label"); delete res; delete stmt; delete con; } catch (sql::SQLException &amp;e) { cout &lt;&lt; "# ERR: SQLException in " &lt;&lt; __FILE__; cout &lt;&lt; "(" &lt;&lt; __FUNCTION__ &lt;&lt; ") on line " &lt;&lt; __LINE__ &lt;&lt; endl; cout &lt;&lt; "# ERR: " &lt;&lt; e.what() &lt;&lt; endl; cout &lt;&lt; " (MySQL error code: " &lt;&lt; e.getErrorCode() &lt;&lt; endl; cout &lt;&lt; ", SQLState: " &lt;&lt; e.getSQLState() &lt;&lt; " )" &lt;&lt; endl; } cout&lt;&lt;"Terminado...\n"; return 0; </code></pre> <p>}</p> <p>Aluísio São Paulo</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload