Masterminds/squirrel

SelectBuilder.Where() broken

hahanein opened this issue · 3 comments

Version: a6b9300

Where statements aren't being transformed into "WHERE IN (?, ...)" statements if the value of a squirrel.Eq key is of type []uint8.

Correct:

package main

import (
        "fmt"

        "github.com/Masterminds/squirrel"
)

func main() {
        query, args, err := squirrel.Select("*").Where(squirrel.Eq{"test": []uint32{1, 2, 3}}).ToSql()
        if err != nil {
                panic(err)
        }

        fmt.Println(query) // SELECT * WHERE test IN (?,?,?)
        fmt.Println(args) // [1 2 3]
}

Bug:

package main

import (
        "fmt"

        "github.com/Masterminds/squirrel"
)

func main() {
        query, args, err := squirrel.Select("*").Where(squirrel.Eq{"test": []uint8{1, 2, 3}}).ToSql()
        if err != nil {
                panic(err)
        }

        fmt.Println(query) // SELECT * WHERE test = ?
        fmt.Println(args) // [[1 2 3]]
}
lann commented

Squirrel doesn't touch values when driver.IsValue(value) is true. It looks like byte is really just an alias for uint8, and driver.IsValue([]byte{}) is true.

I don't think this can be fixed backward-compatibly.

Thank you! Maybe you should warn about this pitfall in the README and the docs.

lann commented

Good idea. Added an FAQ section with this.