Store parameters and add accessor
This commit is contained in:
parent
c63b86d478
commit
7db4cb70b8
14
src/lib.rs
14
src/lib.rs
@ -396,6 +396,7 @@ struct InnerConnection {
|
||||
cancel_data: CancelData,
|
||||
unknown_types: HashMap<Oid, Type>,
|
||||
cached_statements: HashMap<String, CachedStatement>,
|
||||
parameters: HashMap<String, String>,
|
||||
next_stmt_id: u32,
|
||||
trans_depth: u32,
|
||||
canary: u32,
|
||||
@ -429,6 +430,7 @@ impl InnerConnection {
|
||||
cancel_data: CancelData { process_id: 0, secret_key: 0 },
|
||||
unknown_types: HashMap::new(),
|
||||
cached_statements: HashMap::new(),
|
||||
parameters: HashMap::new(),
|
||||
desynchronized: false,
|
||||
finished: false,
|
||||
trans_depth: 0,
|
||||
@ -512,7 +514,7 @@ impl InnerConnection {
|
||||
Ok(None)
|
||||
}
|
||||
ParameterStatus { parameter, value } => {
|
||||
debug!("Parameter {} = {}", parameter, value);
|
||||
self.parameters.insert(parameter, value);
|
||||
Ok(None)
|
||||
}
|
||||
val => Ok(Some(val))
|
||||
@ -1108,6 +1110,11 @@ impl Connection {
|
||||
self.conn.borrow().cancel_data
|
||||
}
|
||||
|
||||
/// Returns the value of the specified parameter.
|
||||
pub fn parameter(&self, param: &str) -> Option<String> {
|
||||
self.conn.borrow().parameters.get(param).cloned()
|
||||
}
|
||||
|
||||
/// Returns whether or not the stream has been desynchronized due to an
|
||||
/// error in the communication channel with the server.
|
||||
///
|
||||
@ -1243,6 +1250,11 @@ impl<'conn> Transaction<'conn> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a reference to the `Transaction`'s `Connection`.
|
||||
pub fn connection(&self) -> &'conn Connection {
|
||||
self.conn
|
||||
}
|
||||
|
||||
/// Like `Connection::is_active`.
|
||||
pub fn is_active(&self) -> bool {
|
||||
self.conn.conn.borrow().trans_depth == self.depth
|
||||
|
@ -910,3 +910,10 @@ fn test_is_active() {
|
||||
or_panic!(trans.finish());
|
||||
assert!(conn.is_active());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parameter() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert_eq!(Some("UTF8".to_string()), conn.parameter("client_encoding"));
|
||||
assert_eq!(None, conn.parameter("asdf"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user