1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub use crate::{handles, Cursor, Error};
use widestring::U16Str;
use std::thread::panicking;
impl<'conn> Drop for Connection<'conn> {
fn drop(&mut self) {
if let Err(e) = self.connection.disconnect() {
if !panicking() {
panic!("Unexepected error disconnecting: {:?}", e)
}
}
}
}
pub struct Connection<'c> {
connection: handles::Connection<'c>
}
impl<'c> Connection<'c> {
pub (crate) fn new(connection: handles::Connection<'c>) -> Self {
Self{ connection }
}
pub fn exec_direct(&mut self, query: &U16Str) -> Result<Option<Cursor>, Error>{
let mut stmt = self.connection.allocate_statement()?;
if stmt.exec_direct(query)?{
Ok(Some(Cursor::new(stmt)))
} else {
Ok(None)
}
}
}