首先,我是c++新手;现在,我正在尝试编写一个项目来监听来自 MySQL binlog
做点什么。我选择了一个名为mysql binlog replication的库,下面是它的示例代码,现在我可以在中跟踪事件了 MySQL binlog
,检索旧值和新值。但是,我检索不到列,我想知道如何检索列和值一起,感谢任何有用的答案!
以下是我的部分代码:
while (true) {
int result = binlog.wait_for_next_event(&event);
if (result == ERR_EOF)
break;
std::cout << "Found event of type " << event->get_event_type();
int event_type = event->get_event_type();
if (event_type == mysql::TABLE_MAP_EVENT) {
tmev = (mysql::Table_map_event *)event;
std::string tablename=tmev->table_name;
}
if (event_type == mysql::WRITE_ROWS_EVENT || event_type==mysql::UPDATE_ROWS_EVENT || event_type==mysql::DELETE_ROWS_EVENT) {
mysql::Row_event *row_event = (mysql::Row_event *)event;
mysql::Row_event_set rows(row_event, tmev);
mysql::Row_event_set::iterator itor = rows.begin();
do {
mysql::Row_of_fields fields = *itor;
mysql::Row_of_fields::iterator it = fields.begin();
// Here,fields represent values,I have no way to get columns
do {
std::string out;
converter.to(out, *it);
std::cout << "\t" << out;
} while (++it != fields.end());
} while (++itor != rows.end());
}
std::cout << std::endl;
暂无答案!
目前还没有任何答案,快来回答吧!