duckdb / duckdb-web

DuckDB website and documentation
https://duckdb.org
MIT License
167 stars 319 forks source link

Add example code for traversing results in C++ #1024

Open szarnyasg opened 1 year ago

szarnyasg commented 1 year ago

The https://duckdb.org/docs/api/cpp.html page says:

The MaterializedQueryResult instance contains firstly two fields that indicate whether the query was successful. Query will not throw exceptions under normal circumstances. Instead, invalid queries or other issues will lead to the success boolean field in the query result instance to be set to false. In this case an error message may be available in error as a string. If successful, other fields are set: the type of statement that was just executed (e.g., StatementType::INSERT_STATEMENT) is contained in statement_type. The high-level ("SQL type") types of the result set columns are in sql_types and the low-level data representation types are in types. The names of the result columns are in the names string vector. In case multiple result sets are returned, for example because the result set contained multiple statements, the result set can be chained using the next field.

// TODO

The code block should be completed. I removed it for the time being.

adaptiverisk commented 5 months ago

The page still doesn't describe how to iterate over results in MaterializedQueryResults. I spent an hour already searching web trying to figure out how to do that.