Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use libpq for identifier escaping #569

Merged
merged 1 commit into from
Jan 9, 2017
Merged

Conversation

sgrif
Copy link
Member

@sgrif sgrif commented Jan 9, 2017

The implementation of PQescapeIdentifier actually does very little,
especially if we can assume that the connection's client encoding is
UTF-8, and that the identifier is valid UTF-8. Since I'd like to share
as much code between the current PG adapter, and the new async one, we
can just re-implement this function ourselves.

This was also the only place that required an Rc on the
RawConnection, which isn't a source of any major overhead but I'm glad
to see it go.

For some reason I thought that replace returned a Cow<str>, not
String. I may add our own version since this function could avoid
allocating the majority of the time.

The implementation of `PQescapeIdentifier` actually does very little,
especially if we can assume that the connection's client encoding is
UTF-8, and that the identifier is valid UTF-8. Since I'd like to share
as much code between the current PG adapter, and the new async one, we
can just re-implement this function ourselves.

This was also the only place that required an `Rc` on the
`RawConnection`, which isn't a source of any major overhead but I'm glad
to see it go.

For some reason I thought that replace returned a `Cow<str>`, not
`String`. I may add our own version since this function could avoid
allocating the majority of the time.
@sgrif sgrif requested a review from killercup January 9, 2017 13:20
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, always nice to see Rc go!

Tiny nit re: identifier stuff, feel free to ignore. FYI, regex's replace_all returns a Cow but is far too much overhead 😆

Ok(self.push_sql(&escaped_identifier))
self.push_sql("\"");
self.push_sql(&identifier.replace('"', "\"\""));
self.push_sql("\"");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This broke the first meme generator I tested)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r#"""# is more characters. ;)

@sgrif sgrif merged commit 8459853 into master Jan 9, 2017
@sgrif sgrif deleted the sg-escape-identifier branch January 9, 2017 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants