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 5 commits into
base: main
Choose a base branch
from

Conversation

iamjpotts
Copy link
Contributor

@iamjpotts iamjpotts commented Aug 1, 2025

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. The inconsistency is demonstrated in the first commit - this commit adds a test which would fail to compile without the remaining commits in the pr.

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 would fail to compile because SqliteArguments 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?

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?

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 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
…r db platforms

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
@iamjpotts iamjpotts force-pushed the jp/sqlite-arg-lifetime branch from 8bbbf1c to c3f788b Compare August 10, 2025 17:00
…arguments by removing lifetime parameter from SqliteArguments

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
…ents, and SqliteArgumentsBuffer

Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
@iamjpotts iamjpotts force-pushed the jp/sqlite-arg-lifetime branch from c3f788b to 73ea968 Compare August 10, 2025 17:01
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