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.
解决方案
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