不支持unicode/utf8?

qvk1mo1f  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(435)

似乎我有被阻止提问的“风险”,但这是一个我必须问的问题。
使用mysql连接器c++,做了我自己的小 Package 来容纳我的项目,一切正常。
但是我不能使用unicode。实际上没有人支持这一点,我们现在是在2019年。
结果集h

virtual SQLString getString(uint32_t columnIndex)  const = 0;
  virtual SQLString getString(const sql::SQLString& columnLabel) const = 0;

sql字符串.h

SQLString(const SQLString & other) : realStr(other.realStr) {}

SQLString(const std::string & other) : realStr(other) {}

SQLString(const char other[]) : realStr(other) {}

SQLString(const char * s, size_t n) : realStr(s, n) {}

所以这个问题实际上扩展到:
为什么不支持unicode?
已经有人支持了吗,我只是瞎了眼吗?
我们可以做些什么来支持unicode?
如果有人能告诉我原因和地点,我将不胜感激。更可以肯定的是,很多人都在寻找这个问题,而且没有最终的答案或解决方案,同样是在2019年。
非常感谢

ibrsph3r

ibrsph3r1#

我找到了部分解决办法。但是,不支持unicode,但是您可以检索和打印utf-8字符串。
这与我的另一个问题(使用sql::connectoptionsmap exception的遗留mysql connector c++)有关,因为为了从mysql获取utf-8字符串,您需要使用以下命令:

sql::ConnectOptionsMap connection_properties;

connection_properties["OPT_CHARSET_NAME"] = "utf8";
connection_properties["OPT_SET_CHARSET_NAME"] = "utf8";

为了使用这些选项,您需要使用mysql连接器的静态版本(mysqlcppconnStatic.lib)。
注:
这样做行不通,所以不要浪费时间:

Connection->setClientOption("OPT_CHARSET_NAME", "utf8");
Connection->setClientOption("OPT_SET_CHARSET_NAME", "utf8");

当您连接到mysql时,需要指定这样的选项。
我真的希望我的努力能在不久的将来帮助别人。

相关问题