Skip to content

Commit

Permalink
Fixes allocation bug
Browse files Browse the repository at this point in the history
Closes #37
  • Loading branch information
sanpii committed Oct 9, 2023
1 parent 585dcf2 commit 671e76e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/connection/_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ impl Connection {
/**
* Escape string literals, much like `libpq::Connection::literal`.
*
* On success, this method returns [`PqString`].
* On success, this method returns [`String`].
*
* See
* [PQescapeStringConn](https://www.postgresql.org/docs/current/libpq-exec.html#LIBPQ-PQESCAPESTRINGCONN).
*/
pub fn escape_string(&self, from: &str) -> crate::errors::Result<PqString> {
pub fn escape_string(&self, from: &str) -> crate::errors::Result<String> {
crate::escape::string_conn(self, from)
}

Expand Down
8 changes: 3 additions & 5 deletions src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn identifier(conn: &crate::Connection, str: &str) -> crate::errors::Result<
}
}

pub(crate) fn string_conn(conn: &crate::Connection, from: &str) -> crate::errors::Result<PqString> {
pub(crate) fn string_conn(conn: &crate::Connection, from: &str) -> crate::errors::Result<String> {
let mut error = 0;

// @see https://github.com/postgres/postgres/blob/REL_12_2/src/interfaces/libpq/fe-exec.c#L3329
Expand All @@ -50,7 +50,7 @@ pub(crate) fn string_conn(conn: &crate::Connection, from: &str) -> crate::errors
}
};

Ok(PqString::from_raw(raw))
crate::ffi::to_string(raw)
}

#[deprecated(note = "Use libpq::Connection::escape_string instead")]
Expand Down Expand Up @@ -151,9 +151,7 @@ mod test {
let conn = crate::test::new_conn();

assert_eq!(
crate::escape::string_conn(&conn, "'foo'")
.unwrap()
.to_string_lossy(),
crate::escape::string_conn(&conn, "'foo'").unwrap(),
"''foo''"
);
}
Expand Down

0 comments on commit 671e76e

Please sign in to comment.