Skip to content
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

SelectBuilder.Where() broken #114

Closed
hahanein opened this issue Jan 11, 2018 · 3 comments
Closed

SelectBuilder.Where() broken #114

hahanein opened this issue Jan 11, 2018 · 3 comments

Comments

@hahanein
Copy link

hahanein commented Jan 11, 2018

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
Copy link
Member

lann commented Jan 11, 2018

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.

@hahanein
Copy link
Author

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

@lann lann closed this as completed in 0fcd409 Jan 11, 2018
@lann
Copy link
Member

lann commented Jan 11, 2018

Good idea. Added an FAQ section with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants