gpt4 book ai didi

c++ - 用于 C++ 的 MySQL 连接器 | setSchema 上的 MySQL_Connection::setReadOnly() 异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:51:14 25 4
gpt4 key购买 nike

我正在为一个不太流行的 mmorpg 游戏编写一个 server-emu 软件,我正在使用 mysql connector for c++ 连接我的数据库。在我重新安装 Windows(和我的整个开发环境)后,我遇到了一个奇怪的 mysql 连接器异常。

我用来连接数据库的代码如下所示:

try
{
this->driver = get_driver_instance();
std::cout << "SQL Driver Name: " << this->driver->getName() << std::endl;
std::cout << "Connecting as " << user << "@" << host << " using password " << password << std::endl;
this->connection = this->driver->connect(host, user, password);
std::cout << "Setting schema to " << schema << std::endl;
this->connection->setSchema(schema);

} catch(sql::SQLException &e)
{
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
return 1;
}

(所有变量如用户、密码等都是 std::strings)

这之前是有效的,但现在它在控制台中打印:

SQL Driver Name: MySQL Connector C++ (libmysql)
Connecting as root@tcp://localhost:3306 using password testpassword
Setting schema to testschema
ERR: SQLException in c:\whatever\db.cpp on line 22
ERR: MySQL_Connection::setReadOnly() (MySQL error code: 0, SQLState: )

没有这一行:

this->connection->setSchema(schema);

一切正常。

我不知道如何解决这个问题,也不知道为什么会这样。请帮忙。

最佳答案

我有一个类似的问题,虽然在 Debian Wheezy 上,版本 1.1.0-4+b1:

使用示例:

sql::Connection *con; 
con->setSchema(mysql_schema);

抛出:

MySQL_Connection::setReadOnly()

通过将 Connector/C++ 1.1.0-4+b1 替换为 1.1.5,它不再引发此错误。

关于c++ - 用于 C++ 的 MySQL 连接器 | setSchema 上的 MySQL_Connection::setReadOnly() 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28462633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com