mercredi 6 mars 2019

Converting mysqlx::Value to std::string with special characters

I'm trying to convert a mysqlx::Value type that should be a string but it has special non-standard language characters in it. I need to handle it as a std::string or equivalent.

I'm using the mysql C++ Connector XDevAPI to retrieve the data.

mysqlx::Session sess(_db_conn_info.db_host, _db_conn_info.db_port, _db_conn_info.db_user, _db_conn_info.db_pass);
    mysqlx::Schema db = sess.getSchema(_db_conn_info.db_name);

    mysqlx::Table artist_table = db.getTable("Artist");
    mysqlx::RowResult artist_result = artist_table.select("id", "a_id", "name", "is_australian")
        .where("id like :artist_id").bind("artist_id", artist_id).execute(); 

mysqlx::Row row = artist_result.fetchOne();

The name column in the row[2] value can sometimes contain characters like: é or í

I want to pass the mysqlx::Value result into a std::string object or similar. Note: this works fine when the string does not contain special characters.

I've tried using a stringstream but I get "CDK Error: string conversion error" when the string contains the special characters.

std::stringstream name;
name << row[2]; // Exception throws here

Aucun commentaire:

Enregistrer un commentaire