Skip to content

fix(sqlite): query macro argument lifetime use inconsistent with other db platforms #3957

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

iamjpotts
Copy link
Contributor

@iamjpotts iamjpotts commented Aug 1, 2025

Demonstrates but does not fix Fixes an inconsistency with allowed usage of references as arguments to query macros in the context of the sqlite feature compared to features for other db platforms, such as Postgres.

Compare the test added with this pr vs the existing test by the same name for Postgres:

The existing test for Postgres compiles and passes because PgArguments does not have a lifetime parameter. The new test for sqlite fails would fail to compile because SqliteArguments has had a lifetime parameter which causes the return value of the query! macro to be borrowing a reference to a value that is an argument to query! but goes out of scope when query! returns.

Does your PR solve an issue?

No (not yet)
Yes - cannot pass a reference as a bind argument to query! unless the reference is established before the query! macro call (e.g. by assigning it to a variable with let).

Is this a breaking change?

Likely yes. A fix would likely involve adding or removing lifetime parameters on structs related to arguments, and those structs are a part of the crate's public api.

Yes, due to:

  • Deletion of lifetime parameter on SqliteArguments and SqliteArgumentValue
  • Deletion of into_static() on both of those types
  • Introduction of SqliteArgumentsBuffer type to wrap Vec<SqliteArgumentValue>
  • Changing SqliteArgumentValue::Text to store an Arc<String> instead of Cow<str>, and adding ::TextSlice for the Arc<str> variant

Commits

The first commit is a part of #3956.

The last commit (changing AnyArguments::convert_to to convert_into) could be moved out of this pr and into a new one focused on removing the lifetime arguments on AnyArguments and AnyArgumentValue to add similar support for references in the bind parameters when using the Any driver.

@iamjpotts iamjpotts changed the title Jp/sqlite arg lifetime bug(sqlite): query macro argument lifetime use inconsistent with other db platforms Aug 1, 2025
@iamjpotts iamjpotts changed the title bug(sqlite): query macro argument lifetime use inconsistent with other db platforms fix(sqlite): query macro argument lifetime use inconsistent with other db platforms Aug 1, 2025
@iamjpotts iamjpotts force-pushed the jp/sqlite-arg-lifetime branch from e9f5f5c to 8bbbf1c Compare August 1, 2025 23:29
@iamjpotts iamjpotts marked this pull request as ready for review August 1, 2025 23:40
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.

1 participant