MySQL Connector for C++ | MySQL_Connection::setReadOnly() exception on setSchema

China☆狼群 提交于 2019-12-07 18:35:24

问题


I am writing a server-emu software for a not-so-popular mmorpg game, and I'm using mysql connector for c++ to connect with my database. After I reinstalled Windows (and my whole dev environment) I've got a weird mysql connector exception.

The code I use to connect with the database looks like this:

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;
}

(all variables like user, password etc. are std::strings)

This was working before, but now it prints in the console this:

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:  )

Without this line:

this->connection->setSchema(schema);

everything works fine.

I don't have any ideas how to fix this and why is this happening. Please help.


回答1:


I had a similar problem, though on Debian Wheezy, with version 1.1.0-4+b1:

Example of usage:

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

Which throws:

MySQL_Connection::setReadOnly()

By replacing Connector/C++ 1.1.0-4+b1 with 1.1.5, it no longer throws this error.




回答2:


I've had the same problem; it turned out to be because I was linking the 64-bit version of Connector/C++ to my compiled-as-32-bit program.




回答3:


yes,please use v1.1.5. the version of 1.16 has bug.

tar -xf mysql-connector-c++-1.1.5.tar.gz
cd mysql-connector-c++-1.1.5
cmake . -DMYSQL_CONFIG_EXECUTABLE=/usr/local/mysql/bin/mysql_config \
  -DMYSQL_LIB=/usr/local/mysql/lib/libmysqlclient.so
make
sudo make install


来源:https://stackoverflow.com/questions/28462633/mysql-connector-for-c-mysql-connectionsetreadonly-exception-on-setschema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!