Struct hdbconnect::ResultSet
[−]
[src]
pub struct ResultSet { /* fields omitted */ }
Contains the result of a database read command, including the describing metadata.
In most cases, you will want to use the powerful method into_typed to convert the data from the generic format into your application specific format.
Methods
impl ResultSet
[src]
fn is_empty(&self) -> bool
Returns true if no rows are contained
fn has_multiple_rows(&self) -> bool
Returns true if more than 1 row is contained
fn len(&mut self) -> Result<usize, PrtError>
Returns the number of contained rows
fn last_row(&self) -> Option<&Row>
Returns a pointer to the last row
fn last_row_mut(&mut self) -> Option<&mut Row>
Returns a mutable pointer to the last row
fn reverse_rows(&mut self)
Returns a mutable pointer to the last row
fn pop_row(&mut self) -> Option<Row>
Removes the last row and returns it, or None if it is empty.
fn number_of_fields(&self) -> usize
Returns the number of fields
fn get_fieldname(&self, field_idx: usize) -> Option<&String>
Returns the name of the column at the specified index
fn get_value(&mut self, row: usize, column: usize) -> Option<&mut TypedValue>
Returns the value at the specified position.
FIXME Should be replaced with a method get_rows() -> Iterator.
fn no_of_rows(&self) -> usize
Returns the number of result rows.
fn fetch_all(&mut self) -> Result<(), PrtError>
Fetches all not yet transported result lines from the server.
Bigger resultsets are typically not transported in one DB roundtrip; the number of roundtrips depends on the size of the resultset and the configured fetch_size of the connection.
fn accumulated_server_processing_time(&self) -> i32
Returns the accumulated server processing time of the calls that produced this resultset, i.e. the initial call and potentially a subsequent number of fetches.
fn into_typed<T>(self) -> HdbResult<T> where
T: Deserialize,
T: Deserialize,
Translates a generic resultset into a given rust type (that implements Deserialize).
A resultset is essentially a two-dimensional structure, given as a list of rows
(a Vec<Row>
),
where each row is a list of fields (a Vec<TypedValue>
);
the name of each field is given in the metadata of the resultset.
The method supports a variety of target data structures, with the only strong limitation that no data loss is supported.
It depends on the dimension of the resultset what target data structure you can choose for deserialization:
You can always use a
Vec<line_struct>
, whereline_struct
matches the field list of the resultset.If the resultset contains only a single line (e.g. because you specified TOP 1 in your select), then you can optionally choose to deserialize into a plain
line_struct
.If the resultset contains only a single column, then you can optionally choose to deserialize into a
Vec<plain_field>
.If the resultset contains only a single value (one row with one column), then you can optionally choose to deserialize into a plain
line_struct
, or aVec<plain_field>
, or a plain variable.
Also the translation of the individual field values provides a lot of flexibility. You can e.g. convert values from a nullable column into a plain field, provided that no NULL values are given in the resultset.
Vice versa, you always can use an Option
<plain_field>
, even if the column is marked as NOT NULL.Similarly, integer types can differ, as long as the concrete values can be assigned without loss.
Note that you need to specify the type of your target variable explicitly, so that
into_typed()
can derive the type it needs to serialize into:
#[derive(Deserialize)] struct MyStruct { ... } let typed_result: Vec<MyStruct> = resultset.into_typed()?;