Skip to content

Commit 8d15135

Browse files
committed
Fix close
1 parent cfe8e9f commit 8d15135

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/client.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -987,19 +987,6 @@ where
987987
continue;
988988
}
989989

990-
// Close (F)
991-
'C' => {
992-
if self.prepared_statements_enabled {
993-
let close: Close = (&message).try_into()?;
994-
995-
if close.is_prepared_statement() && !close.anonymous() {
996-
self.prepared_statements.remove(&close.name);
997-
write_all_flush(&mut self.write, &close_complete()).await?;
998-
continue;
999-
}
1000-
}
1001-
}
1002-
1003990
_ => (),
1004991
}
1005992

@@ -1444,11 +1431,18 @@ where
14441431
// Close the prepared statement.
14451432
'C' => {
14461433
if self.prepared_statements_enabled {
1447-
let close: Close = (&message).try_into()?;
1434+
let mut close: Close = (&message).try_into()?;
14481435

14491436
if close.is_prepared_statement() && !close.anonymous() {
1450-
server.remove_prepared_statement_from_cache(&close.name);
1451-
self.prepared_statements.remove(&close.name);
1437+
if let Some((parse, _)) =
1438+
self.prepared_statements.remove(&close.name)
1439+
{
1440+
// Tell server we're closing this statement
1441+
server.remove_prepared_statement_from_cache(&parse.name);
1442+
1443+
close.rename(&parse.name);
1444+
message = close.try_into()?
1445+
}
14521446
}
14531447
}
14541448

src/messages.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,8 @@ impl Parse {
858858
/// Gets the name of the prepared statement from the buffer
859859
pub fn get_name(buf: &BytesMut) -> Result<String, Error> {
860860
let mut cursor = Cursor::new(buf);
861-
cursor.get_u8();
862-
cursor.get_i32();
861+
// Skip the code and length
862+
cursor.advance(mem::size_of::<u8>() + mem::size_of::<i32>());
863863
cursor.read_string()
864864
}
865865

@@ -1031,8 +1031,8 @@ impl Bind {
10311031
/// Gets the name of the prepared statement from the buffer
10321032
pub fn get_name(buf: &BytesMut) -> Result<String, Error> {
10331033
let mut cursor = Cursor::new(buf);
1034-
cursor.get_u8();
1035-
cursor.get_i32();
1034+
// Skip the code and length
1035+
cursor.advance(mem::size_of::<u8>() + mem::size_of::<i32>());
10361036
cursor.read_string()?;
10371037
cursor.read_string()
10381038
}
@@ -1188,6 +1188,10 @@ impl Close {
11881188
}
11891189
}
11901190

1191+
pub fn rename(&mut self, name: &str) {
1192+
self.name = name.to_string();
1193+
}
1194+
11911195
pub fn is_prepared_statement(&self) -> bool {
11921196
self.close_type == 'S'
11931197
}

0 commit comments

Comments
 (0)