Struct basex::query::query::Query[][src]

pub struct Query<T, HasInfo = WithoutInfo> where
    T: DatabaseStream
{ has_info: PhantomData<HasInfo>, id: String, client: Client<T>, }
Expand description

Server query is composed of XQuery code, which is immutable once created.

The client may bind arguments, set context or modify options which influences the way result is generated.

Furthermore, the client can execute the query, check for updating statements or read compiler info.

Fields

has_info: PhantomData<HasInfo>id: Stringclient: Client<T>

Implementations

Deletes the query.

Example
// Delete the query, moves back the `client`.
let client = query.close()?;
// Current function now owns `client`.

Binds a variable under the given valid XML name.

You then need to make a statement about its value using either with_value or without_value.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let mut query = client.query("/")?.without_info()?;
query
    .bind("boy_sminem")?.with_value(123)?
    .bind("bogdanoff")?.without_value()?;
let mut response = query.execute()?;
let mut result = String::new();
response.read_to_string(&mut result)?;

println!("{}", result);

Executes the query and returns its response.

The response is readable using the Read trait.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let query = client.query("declare variable $points := 30;
<polygon>
  {
    for $i in 1 to $points
    let $angle := 2 * math:pi() * number($i div $points)
    return <point x=\"{round(math:cos($angle), 8)}\" y=\"{round(math:sin($angle), 8)}\"></point>
  }
</polygon>")?.without_info()?;

let mut result = String::new();
let mut response = query.execute()?;
response.read_to_string(&mut result)?;

println!("{}", result);

Returns all query serialization options.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let mut query = client.query("/")?.without_info()?;
let mut options = query.options()?;
let client = query.close()?;
options.set("indent", false);
options.save(client)?;

Replaces whatever context is set (if any) to the given value.

By default the context is set to currently opened database (if any). Setting context allows you to run query on a different data-set or without a database.

Example
let mut client = Client::connect("localhost", 1984, "admin", "admin")?;
let mut response = {
    let mut query = client.query("count(prdel/*)")?.without_info()?;
    query.context("<prdel><one/><two/><three/></prdel>")?;
    query.execute()?
};
let mut actual_result = String::new();
response.read_to_string(&mut actual_result)?;
response.close()?.close()?;

let expected_result = "3";
assert_eq!(expected_result, actual_result);

Checks if the query contains updating expressions.

Panics

Panics when the response contains non-boolean value.

Example

let mut query = client.query("replace value of node /None with 1")?.without_info()?;
assert!(query.updating()?);

let mut query = client.query("count(/None/*)")?.without_info()?;
assert!(!query.updating()?);

Attaches Query to an existing query in the session.

Attaches Query to an existing query in the session.

Returns the query compilation and profiling Info.

Example
let info = query.info()?;
println!(
    "Compilation took {} ms, query: {}",
    info.compiling_time().as_millis(),
    info.optimized_query()
);

Trait Implementations

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

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.