Skip to content

Add parameters to query db #11643

Closed

Description

@giggio

Related problem

I'd like to be able to pass parameters to query db.

Describe the solution you'd like

Something like:

query db "INSERT INTO table (column_x, column_y) VALUES (?1, ?2)" --params $x $y

Describe alternatives you've considered

Invoking sqlite directly.

Additional context and details

Besides the problem of sql injection, this is cumbersome because you have to escape values when using string interpolation.

Activity

  1. added
    category:enhancement
    status:needs-triage
    on Jan 25, 2024
  2. fdncred commented on Jan 26, 2024

    @fdncred
    Contributor

    You'd have to use string interpolation now, like you suggested.

    ❯ let var = 75
    ❯ open $nu.history-path | query db $"select * from history where id = ($var)"

    I'm not even sure if you can have multiple of the same parameter like that in nushell. If someone wanted to submit a PR with something like this, we'll look at it.

  3. giggio commented on Jan 26, 2024

    @giggio
    Author

    Interpolation is subject to sql injection and other problems (like escaping).
    I'll update the description to one that fits the current language. But the idea to repeated params is something other shells use.

  4. fdncred commented on Jan 26, 2024

    @fdncred
    Contributor

    If it were to take a list, that would work too like

    query db "INSERT INTO table (column_x, column_y) VALUES (?1, ?2)" --params [$x $y]
  5. d4h0 commented on Mar 18, 2024

    @d4h0

    For reference: https://owasp.org/www-community/attacks/SQL_Injection

    Basically, query db currently shouldn't be used with any data that comes from an untrustworthy source, like the internet.

  6. added a commit that references this issue on Mar 24, 2024
    d1a8992
  7. added this to the v0.92.0 milestone on Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancementstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions