Note that there are some explanatory texts on larger screens.

plurals
  1. POProcess utf-8 data from MySQL in C++ and give result back
    text
    copied!<p>I just simply want to know - how to get <strong>MySQL results to C++ in string</strong> (or another similar "string" datatype) in a way that would <strong>not deform data saved in utf8_unicode_ci</strong>.</p> <p>After C++ process, app should <strong>write results back</strong> (to another table) into the database where argument is encoded in utf8_unicode_ci as well.</p> <p>I read somewhere that using <em>wide char</em> is not recommended by Unicode consortium, but my problem is still that a second argument for mysql_query() is string which is not wide enough.</p> <p>I've already tried some "utf8 string" solutions, but unsuccessfully. I also tried to save data in common string and than write it into the database in the same way (byte after byte), but it doesn't work properly at all... (see my code below)</p> <p>DATABASE:</p> <p>save_text: text = ěščřžýáíé</p> <p>AFTER PROCESS: save_newtext: text = ?š??žýáíé</p> <pre><code>#include &lt;iostream&gt; #include &lt;mysql.h&gt; #include &lt;string&gt; #define ... // server conection using namespace std; MYSQL *connection, mysql; MYSQL_RES *result; MYSQL_ROW row; int query_state; int main(int argc, char** argv) { mysql_init(&amp;mysql); mysql_real_connect(&amp;mysql,CTH_SERVER,CTH_USER,CTH_PASSWORD,CTH_DB_IN,0,0,0)); mysql_options(&amp;mysql, MYSQL_SET_CHARSET_NAME, "utf8"); mysql_options(&amp;mysql, MYSQL_INIT_COMMAND, "SET NAMES utf8"); mysql_query(connection, "SELECT text FROM save_text WHERE id = 23"); result = mysql_store_result(connection); if ((row = mysql_fetch_row(result)) != NULL) { string sql; sql = "INSERT INTO save_newtext (text) VALUES ('"; sql += row[0]; sql += "')"; mysql_query(connection, sql.c_str()); } return 0; } </code></pre> <p>Thanks in advance!!</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