Skip to content

Conversation

@ParkMyCar
Copy link
Owner

As it says on the tin! Upgrades the sqlx dependency to v0.8, this picks up the fix for RUSTSEC-2024-0363.

Fixes #407

self,
buf: &mut <sqlx::Sqlite as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError> {
Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf)

Choose a reason for hiding this comment

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

Suggested change
Encode::<'_, sqlx::Sqlite>::encode(self.into_string(), buf)
Encode::<'_, sqlx::Sqlite>::encode(self.as_str(), buf)

Needless allocation?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I tried this change but it doesn't work. AFAICT what's happening is buf here is a SqliteArgumentValue which contains a Cow<'q, str>. Because we have self as an owned value, trying to use self.as_str() doesn't work because self gets dropped at the end of this scope, but needs to live for 'q.

Choose a reason for hiding this comment

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

Yes, the 'q lifetime complicates life when Postgres or MySQL backend is used.

) -> IsNull {
buf: &mut <sqlx::Sqlite as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, BoxDynError> {
Encode::<'_, sqlx::Sqlite>::encode(alloc::string::String::from(self.as_str()), buf)

Choose a reason for hiding this comment

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

Suggested change
Encode::<'_, sqlx::Sqlite>::encode(alloc::string::String::from(self.as_str()), buf)
Encode::<'_, sqlx::Sqlite>::encode(self.as_str(), buf)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Similar to the above, here we have a SqliteArgumentValue. Trying to use self.as_str() doesn't work because then the lifetime of &self would need to be longer than 'q, but there's no way to enforce that because then our impl would contain more lifetimes than the definition of the Encode trait

{
fn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError> {
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
let value = value.to_owned();

Choose a reason for hiding this comment

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

Do we need to_owned() here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good call! I tried removing the to_owned() but that didn't work because all we have here is a ValueRef. Instead I refactored this to use the Decode impl for &str which presumably would do the most efficient thing

@rshigapov-bhft
Copy link

@ParkMyCar , I tried to integrate this branch and tested Encode for &[CompactString]. It works.

* skip using to_owned in impl of Decode, defer to Decode impl for &str
* fix clippy in sqlx example
@ParkMyCar ParkMyCar merged commit be93edf into main Dec 29, 2024
26 of 27 checks passed
@ParkMyCar
Copy link
Owner Author

Hey @rshigapov-bhft, thanks for the comments and extra testing here! Going to merge the PR but please let me know if there is anything I missed :)

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.

[RUSTSEC-2024-0363] Support sqlx 0.8

3 participants