关闭游标错误mysql connector c ++ 8.0 [英] Closed cursor error mysql connector c++ 8.0

查看:140
本文介绍了关闭游标错误mysql connector c ++ 8.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mysql连接器8.0,并且以下代码在尝试获取行时引发了Closed cursor错误.

I'm using mysql connector 8.0 and the below code throws a Closed cursor error when trying to fetch the row.

        std::string query = "SELECT `id`, `username`, `password`, `gender`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `last_login`, `last_ip`, `birth_date`, `character_slots`, `pincode`, `pincode_expiry` FROM `game_account` WHERE username = ?;";

        mysqlx::RowResult res = server->get_mysql_session().sql(query).bind(username).execute();

        try {
            mysqlx::Row record = res.fetchOne();

错误:

CDK Error: get_rows: Closed cursor

推荐答案

server->get_mysql_session()返回一个临时Session对象.在创建临时语句的末尾将销毁所有临时变量.

server->get_mysql_session() returns a temporary Session object. All temporaries are destroyed at the end of the statement in which they were created.

由于在调用fetchOne之前会话已被破坏,因此失败.

As the session is destroyed before you call fetchOne it fails.

例如此代码:

#include <iostream>
#include <string>

struct A
{
    A() { std::cout << "A()\n"; }
    ~A() { std::cout << "~A()\n"; }
};

std::ostream& operator << (std::ostream& os, const A& a) { os << "\nA<<"; return os; }

int main()
{
    std::cout << "line1\n";
    std::cout << "line2" << A() << "\n";
    std::cout << "line3\n";
}

产生以下输出:

line1
A()
line2
A<<
~A()
line3

这篇关于关闭游标错误mysql connector c ++ 8.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆