Skip to content

sqlite: query! borrows Copy parameters #1151

Open
@NyxCode

Description

@NyxCode

I've struck a strange issue with sqlite.
This code

fn query<'a, 'c: 'a>(
    con: impl Executor<'c, Database = Sqlite> + 'a,
    limit: i64,
    offset: i64,
) -> BoxStream<'a, sqlx::Result<i64>> {
    sqlx::query_scalar!("SELECT id FROM users LIMIT ? OFFSET ?", limit, offset).fetch(con)
}

fails to compile with sqlite with this error:

error[E0515]: cannot return value referencing function parameter `limit`
  --> example-sqlite/src/main.rs:23:5
   |
23 |     sqlx::query_scalar!("SELECT id FROM users LIMIT ? OFFSET ?", limit, offset).fetch(con)
   |     ---------------------------------------------------------------------------^^^^^^^^^^^
   |     |
   |     returns a value referencing data owned by the current function
   |     `limit` is borrowed here

error[E0515]: cannot return value referencing function parameter `offset`
  --> example-sqlite/src/main.rs:23:5
   |
23 |     sqlx::query_scalar!("SELECT id FROM users LIMIT ? OFFSET ?", limit, offset).fetch(con)
   |     ---------------------------------------------------------------------------^^^^^^^^^^^
   |     |
   |     returns a value referencing data owned by the current function
   |     `offset` is borrowed here

error: aborting due to 2 previous errors; 2 warnings emitted

The same happens with query! and query_as!. The equivalent code compiles fine on MySql and Postgres.
It's only on sqlite that the stream borrows the parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions