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
Fields
has_info: PhantomData<HasInfo>
id: String
client: 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()?);
fn connection(&mut self) -> &mut Connection<T, Authenticated>ⓘNotable traits for Connection<T, State>impl<T, State> Read for Connection<T, State> where
T: DatabaseStream,
impl<T, State> Read for Connection<T, State> where
T: DatabaseStream,
Attaches Query
to an existing query in the session.
Attaches Query
to an existing query in the session.
Trait Implementations
Mutably borrows from an owned value. Read more