nullism / bqb

BQB is a lightweight and easy to use query builder that works with sqlite, mysql, mariadb, postgres, and others.
MIT License
155 stars 13 forks source link

Wrapped Literal Bug #28

Closed djpalm801 closed 7 months ago

djpalm801 commented 7 months ago

Summary:

When escaping a ? using ??, the query builder fails when checking the parameter counts. This is because we aren't escaping the args text.

Adding text = strings.ReplaceAll(text, "??", tempPh) after line 182 in utils.go resolves this, tested using:

func TestQueryLiteralQWrapped(t *testing.T) {
    q := New("WHERE ??| = ?", "asdf")
    wrapped := New("?", q)
    sql, _, err := wrapped.ToPgsql()
    if err != nil {
        t.Errorf("got error from ToPgsql(): %v", err)
    }
    want := "WHERE ?| = $1"
    if want != sql {
        t.Errorf("got: %q, want:%q", sql, want)
    }
}