Skip to content

Commit 7db4cb7

Browse files
committed
Store parameters and add accessor
1 parent c63b86d commit 7db4cb7

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ struct InnerConnection {
396396
cancel_data: CancelData,
397397
unknown_types: HashMap<Oid, Type>,
398398
cached_statements: HashMap<String, CachedStatement>,
399+
parameters: HashMap<String, String>,
399400
next_stmt_id: u32,
400401
trans_depth: u32,
401402
canary: u32,
@@ -429,6 +430,7 @@ impl InnerConnection {
429430
cancel_data: CancelData { process_id: 0, secret_key: 0 },
430431
unknown_types: HashMap::new(),
431432
cached_statements: HashMap::new(),
433+
parameters: HashMap::new(),
432434
desynchronized: false,
433435
finished: false,
434436
trans_depth: 0,
@@ -512,7 +514,7 @@ impl InnerConnection {
512514
Ok(None)
513515
}
514516
ParameterStatus { parameter, value } => {
515-
debug!("Parameter {} = {}", parameter, value);
517+
self.parameters.insert(parameter, value);
516518
Ok(None)
517519
}
518520
val => Ok(Some(val))
@@ -1108,6 +1110,11 @@ impl Connection {
11081110
self.conn.borrow().cancel_data
11091111
}
11101112

1113+
/// Returns the value of the specified parameter.
1114+
pub fn parameter(&self, param: &str) -> Option<String> {
1115+
self.conn.borrow().parameters.get(param).cloned()
1116+
}
1117+
11111118
/// Returns whether or not the stream has been desynchronized due to an
11121119
/// error in the communication channel with the server.
11131120
///
@@ -1243,6 +1250,11 @@ impl<'conn> Transaction<'conn> {
12431250
})
12441251
}
12451252

1253+
/// Returns a reference to the `Transaction`'s `Connection`.
1254+
pub fn connection(&self) -> &'conn Connection {
1255+
self.conn
1256+
}
1257+
12461258
/// Like `Connection::is_active`.
12471259
pub fn is_active(&self) -> bool {
12481260
self.conn.conn.borrow().trans_depth == self.depth

tests/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,3 +910,10 @@ fn test_is_active() {
910910
or_panic!(trans.finish());
911911
assert!(conn.is_active());
912912
}
913+
914+
#[test]
915+
fn test_parameter() {
916+
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
917+
assert_eq!(Some("UTF8".to_string()), conn.parameter("client_encoding"));
918+
assert_eq!(None, conn.parameter("asdf"));
919+
}

0 commit comments

Comments
 (0)