[][src]Struct hdbconnect::ResultSet

pub struct ResultSet { /* fields omitted */ }

The result of a database query.

This is essentially a set of Rows, and each Row is a set of HdbValues.

The method try_into converts the data from this generic format in a singe step into your application specific format.

ResultSet implements std::iter::Iterator, so you can directly iterate over the rows of a resultset. While iterating, the not yet transported rows are fetched "silently" on demand, which can fail. The Iterator-Item is thus not Row, but HdbResult<Row>.

for row in connection.query(query_string)? {
    // handle fetch errors and convert each line individually:
    let entity: Entity = row?.try_into()?;
    println!("Got entity: {:?}", entity);
}

Implementations

impl ResultSet[src]

pub fn try_into<'de, T>(self) -> HdbResult<T> where
    T: Deserialize<'de>, 
[src]

Conveniently translates the complete resultset into a rust type that implements serde::Deserialize and has an adequate structure. The implementation of this method uses serde_db::de.

A resultset is essentially a two-dimensional structure, given as a list of rows, where each row is a list of fields; 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>, if the elements of line_struct match the field list of the resultset.

  • If the resultset contains only a single line (e.g. because you specified TOP 1 in your select clause), then you can optionally choose to deserialize directly into a plain line_struct.

  • If the resultset contains only a single column, then you can optionally choose to deserialize directly 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 a Vec<plain_field>, or a plain_field.

Also the translation of the individual field values provides 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 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.

As usual with serde deserialization, you need to specify the type of your target variable explicitly, so that try_into() can derive the type it needs to instantiate:

#[derive(Deserialize)]
struct Entity {
    ...
}
let typed_result: Vec<Entity> = resultset.try_into()?;

Errors

HdbError::Deserialization if the deserialization into the target type is not possible.

pub fn into_single_row(self) -> HdbResult<Row>[src]

Converts the resultset into a single row.

Errors

HdbError::Usage if the resultset contains more than a single row, or is empty.

pub fn metadata(&self) -> Arc<Vec<FieldMetadata>>[src]

Access to metadata.

Examples

let rs: ResultSet;
//...
// get the precision of the second field
let prec: i16 = resultset.metadata()[1].precision();

or

let rs: ResultSet;
//...
for field_metadata in &*rs.metadata() {
    // evaluate metadata of a field
}

pub fn total_number_of_rows(&self) -> HdbResult<usize>[src]

Returns the total number of rows in the resultset, including those that still need to be fetched from the database, but excluding those that have already been removed from the resultset.

This method can be expensive, and it can fail, since it fetches all yet outstanding rows from the database.

Errors

Several variants of HdbError are possible.

pub fn next_row(&mut self) -> HdbResult<Option<Row>>[src]

Removes the next row and returns it, or None if the ResultSet is empty.

Consequently, the ResultSet has one row less after the call. May need to fetch further rows from the database, which can fail.

Errors

Several variants of HdbError are possible.

pub fn fetch_all(&self) -> HdbResult<()>[src]

Fetches all not yet transported result lines from the server.

Bigger resultsets are typically not transported in one roundtrip from the database; the number of roundtrips depends on the total number of rows in the resultset and the configured fetch-size of the connection.

Fetching can fail, e.g. if the network connection is broken.

Errors

Several variants of HdbError are possible.

pub fn server_usage(&self) -> ServerUsage[src]

Provides information about the the server-side resource consumption that is related to this ResultSet object.

Trait Implementations

impl Debug for ResultSet[src]

impl DeserializableResultset for ResultSet[src]

type ROW = Row

Concrete type for the DB row, which must implement DeserializabeRow.

type E = DeserializationError

Error type of the database driver.

impl Display for ResultSet[src]

impl Iterator for ResultSet[src]

type Item = HdbResult<Row>

The type of the elements being iterated over.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<I> IteratorRandom for I where
    I: Iterator
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,