From 8cb2915e14a11df1cacca11c2f5899f187276d47 Mon Sep 17 00:00:00 2001 From: Pierre Roullon Date: Fri, 25 Aug 2023 19:29:46 +0200 Subject: [PATCH] fix: AttributeSelector returns error containing unfound attribute name --- driver/driver_test.go | 9 +++++++++ engine/agnostic/relation.go | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/driver/driver_test.go b/driver/driver_test.go index 43385b2..8130426 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -197,6 +197,15 @@ func TestSelectCamelCase(t *testing.T) { if err != nil { t.Fatalf("sql.Query CamelCase error : %s", err) } + + _, err = db.Query(`SELECT TestCamelCase, nope, email_snake FROM account WHERE 1`) + if err == nil { + t.Fatalf("expected attribute not found error") + } + ee := "attribute not defined: account.nope" + if err.Error() != ee { + t.Fatalf("expected error to be '%s', got '%s'", ee, err.Error()) + } } func TestSelectSimplePredicate(t *testing.T) { diff --git a/engine/agnostic/relation.go b/engine/agnostic/relation.go index 5dd3b8d..3703214 100644 --- a/engine/agnostic/relation.go +++ b/engine/agnostic/relation.go @@ -2,7 +2,6 @@ package agnostic import ( "container/list" - "errors" "fmt" "strings" "sync" @@ -61,7 +60,7 @@ func (r *Relation) Attribute(name string) (int, Attribute, error) { name = strings.ToLower(name) index, ok := r.attrIndex[name] if !ok { - return 0, Attribute{}, errors.New("attribute not defined") + return 0, Attribute{}, fmt.Errorf("attribute not defined: %s.%s", r.name, name) } return index, r.attributes[index], nil }