pub struct QueryResult { /* private fields */ }Expand description
A duckdb_result — materialised, or streaming when it came from
PreparedStatement::execute_streaming (feature duckdb-1-5) — destroyed
on drop.
Iterate the rows with next_chunk until it returns
Ok(None); an Err means the rows stopped early.
Implementations§
Source§impl QueryResult
impl QueryResult
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Number of columns in the result.
Sourcepub fn column_name(&self, index: usize) -> Option<String>
pub fn column_name(&self, index: usize) -> Option<String>
Name of column index, or None if the index is out of range or the
name is not UTF-8.
Sourcepub fn column_type(&self, index: usize) -> Option<TypeId>
pub fn column_type(&self, index: usize) -> Option<TypeId>
TypeId of column index, or None if the index is out of range or
the type is one this build does not recognise.
Sourcepub fn rows_changed(&self) -> u64
pub fn rows_changed(&self) -> u64
Rows changed by an INSERT / UPDATE / DELETE. Zero for other
statements.
Sourcepub fn next_chunk(&mut self) -> Result<Option<OwnedDataChunk>, ExtensionError>
pub fn next_chunk(&mut self) -> Result<Option<OwnedDataChunk>, ExtensionError>
Fetches the next chunk of rows: Ok(None) once every row has been
read, Err if the rows stopped early.
Chunks hold at most duckdb_vector_size() rows; call this repeatedly:
while let Some(chunk) = result.next_chunk()? {
// ... read chunk.size() rows ...
}§Errors
duckdb_fetch_chunk returns null both at the end of the rows and when
fetching fails, recording the failure on the result. On a streaming
result that happens when execution fails part-way (a runtime error in
the query, an interrupt) or, up to DuckDB 1.5.x, when another
statement has run on the same connection, which invalidates the stream
(2.0.0 refuses that statement instead; see
PreparedStatement::execute_streaming).
This returns that error — with
DuckDB’s message — instead of reporting a clean end after a partial
result. Once it has returned Ok(None) or an error it keeps returning
the same thing without calling DuckDB again.
Sourcepub fn column_logical_type(&self, index: usize) -> Option<LogicalType>
pub fn column_logical_type(&self, index: usize) -> Option<LogicalType>
Returns the full LogicalType of column
index.
column_type collapses a column to its top-level
TypeId, which is all you need for a scalar but
loses everything about a STRUCT’s fields, a LIST’s element type, a
DECIMAL’s width and scale, or an ENUM’s dictionary. This keeps them.
Returns None when index is out of range.
Sourcepub fn result_kind(&self) -> ResultKind
pub fn result_kind(&self) -> ResultKind
What kind of outcome the statement produced.
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Whether this result is streaming rather than fully materialised.
Only PreparedStatement::execute_streaming can produce a streaming
result, and even then DuckDB may decide to materialise — which is why
this is a question rather than a guarantee.
Requires duckdb-1-5: duckdb_result_is_streaming sits in the unstable
region of the C API struct.
Sourcepub unsafe fn arrow_options<'conn>(
&self,
) -> Result<ArrowOptions<'conn>, ExtensionError>
pub unsafe fn arrow_options<'conn>( &self, ) -> Result<ArrowOptions<'conn>, ExtensionError>
The Arrow production settings this result was created with
(duckdb_result_get_arrow_options).
Hand these to
arrow::to_arrow_schema and
arrow::data_chunk_to_arrow when
exporting this result’s chunks: they carry the client properties captured
when the query ran, which is what the chunks were built against.
§Errors
Returns an ExtensionError when DuckDB returns null, which it does
for a result with no internal data.
§Safety
The connection that ran this query must stay open for all of 'conn:
the options point at its ClientContext, and a QueryResult does not
borrow its connection. See
ArrowOptions::from_result.
ArrowOptions::from_connection
is the safe alternative.
Sourcepub const fn as_raw(&self) -> &duckdb_result
pub const fn as_raw(&self) -> &duckdb_result
Returns the raw duckdb_result.
Use this for C API calls this crate does not wrap. Do not destroy it — this value still owns it.