mysql setschema,适用于C ++的MySQL连接器| setSchema上的MySQL_Connection :: setReadOnly()异常...

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

pyqt5怎么显示class QueryThread(QThread): query_result = pyqtSignal(object) def __init__(self, id): super().__init__() self.id = id def run(self): conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.id) result = cursor.fetchone() conn.close() self.query_result.emit(result) # 发送查询结果信号 class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.query_thread = None # 查询线程 def read_data(self): data = self.ser.readline() if data: id = data.decode().strip() if not self.query_thread: # 如果查询线程不存在,则创建并启动 self.query_thread = QueryThread(id) self.query_thread.query_result.connect(self.update_ui) self.query_thread.start() else: self.query_thread.id = id # 如果查询线程已存在,则更新查询ID QTimer.singleShot(100, self.read_data) def update_ui(self, result): if result: self.id_label.setText("员工ID:" + result[0]) self.name_label.setText("姓名:" + str(result[1])) self.six_label.setText("性别:" + result[2]) self.sfz_label.setText("身份证:" + str(result[3])) self.tel_label.setText("电话:" + result[4]) else: self.id_label.setText("员工ID:") self.name_label.setText("姓名:") self.six_label.setText("性别:") self.sfz_label.setText("身份证:") self.tel_label.setText("电话:") def closeEvent(self, event): self.ser.close() if self.query_thread: self.query_thread.quit() self.query_thread.wait()
最新发布
05-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值