For connector c++ 1.1, in this example, it's quite easy to get values by specifying the column name (or alias name).
But when I upgraded to version 8.0 xdevapi, I found this feature is no longer supported.
#include <mysqlx/xdevapi.h>
using namespace std;
using namespace mysqlx;
Session sess(<server_url>);
auto result = sess.sql("SELECT * FROM student").execute();
Row row = result.fetchOne();
cout << row[0] << endl; // <- ok
cout << row["ID"] << endl; // <- can compile but garbage output
cout << row.get("ID") << endl; // <- cannot compile
I know the column names can be retrieved from result.getColumn(n).getColumnLabel()
, but IMO it's useless. A "field" -> "index" mapping can really help the developers.
I'm new to C++, so the following sentenses maybe too naive. Here's the possible ways I guess:
- construct a STL map to record the mapping
- iterate through the
result.getColumns()
, then check thegetColumnLabel()
- something like
indexOf
? But I findresult.getColumns()
does not support this method since it's adeque