Struct odbc_api::Preallocated[][src]

pub struct Preallocated<'open_connection> { /* fields omitted */ }
Expand description

A preallocated SQL statement handle intended for sequential execution of different queries. See crate::Connection::preallocate.

Example

use odbc_api::{Connection, Error};
use std::io::{self, stdin, Read};

fn interactive(conn: &Connection) -> io::Result<()>{
    let mut statement = conn.preallocate().unwrap();
    let mut query = String::new();
    stdin().read_line(&mut query)?;
    while !query.is_empty() {
        match statement.execute(&query, ()) {
            Err(e) => println!("{}", e),
            Ok(None) => println!("No results set generated."),
            Ok(Some(cursor)) => {
                // ...print cursor contents...
            },
        }
        stdin().read_line(&mut query)?;
    }
    Ok(())
}

Implementations

Executes an sql statement using a wide string. See Self::execute.

Executes a statement. This is the fastest way to sequentially execute different SQL Statements.

Parameters

  • query: The text representation of the SQL statement. E.g. “SELECT * FROM my_table;”.
  • params: ? may be used as a placeholder in the statement text. You can use () to represent no parameters. Check the crate::parameter module level documentation for more information on how to pass parameters.

Return

Returns Some if a cursor is created. If None is returned no cursor has been created ( e.g. the query came back empty). Note that an empty query may also create a cursor with zero rows. Since we want to reuse the statement handle a returned cursor will not take ownership of it and instead burrow it.

Example

use odbc_api::{Connection, Error};
use std::io::{self, stdin, Read};

fn interactive(conn: &Connection) -> io::Result<()>{
    let mut statement = conn.preallocate().unwrap();
    let mut query = String::new();
    stdin().read_line(&mut query)?;
    while !query.is_empty() {
        match statement.execute(&query, ()) {
            Err(e) => println!("{}", e),
            Ok(None) => println!("No results set generated."),
            Ok(Some(cursor)) => {
                // ...print cursor contents...
            },
        }
        stdin().read_line(&mut query)?;
    }
    Ok(())
}

Transfer ownership to the underlying statement handle.

The resulting type is one level of indirection away from the raw pointer of the ODBC API. It no longer has any guarantees about bound buffers, but is still guaranteed to be a valid allocated statement handle. This serves together with crate::handles::StatementImpl::into_sys or crate::handles::Statement::as_sys this serves as an escape hatch to access the functionality provided by crate::sys not yet accessible through safe abstractions.

Query all columns that match the provided catalog name, schema pattern, table pattern, and column pattern.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.