Skip to content

db.Raw slice arguments that have fewer than 2 elements pass invalid query parameters #279

@c2h5oh

Description

@c2h5oh

Consider 3 examples:

  1. []int64 with 2 elements as argument .OrderBy(db.Raw("CASE WHEN id IN ? THEN 0 ELSE 1 END", []int64{1000, 2000})
  2. []int64 with 1 element as argument .OrderBy(db.Raw("CASE WHEN id IN ? THEN 0 ELSE 1 END", []int64{1000})
  3. []int64 with 0 elements as argument .OrderBy(db.Raw("CASE WHEN id IN ? THEN 0 ELSE 1 END", []int64{})

All 3 generate the same, correct SQL:
ORDER BY CASE WHEN id IN $3 THEN 0 ELSE 1 END

1st example is correct and works

2nd example passes the only element of the slice instead of the slice

3rd example does not pass the argument at all

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