Skip to content

Commit

Permalink
Handle Oracle named parameters in compileNamedQuery
Browse files Browse the repository at this point in the history
Adding to tests as well.
  • Loading branch information
Jesse Szwedko committed Apr 8, 2014
1 parent f0de390 commit 95d2fd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions named.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@ func compileNamedQuery(qs []byte, bindType int) (query string, names []string, e
if i == last && unicode.IsOneOf(allowedBindRunes, rune(b)) {
name = append(name, b)
}
// add the string representation to the names list and reset our name buffer
// add the string representation to the names list
names = append(names, string(name))
name = make([]byte, 0, 10)
// add a proper bindvar for the bindType
switch bindType {
// oracle only supports named type bind vars even for positional
Expand Down
11 changes: 8 additions & 3 deletions named_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func TestCompileQuery(t *testing.T) {
}

for _, test := range table {
qq, names, err := compileNamedQuery([]byte(test.Q), QUESTION)
qr, names, err := compileNamedQuery([]byte(test.Q), QUESTION)
if err != nil {
t.Error(err)
}
if qq != test.R {
t.Errorf("expected %s, got %s", test.R, qq)
if qr != test.R {
t.Errorf("expected %s, got %s", test.R, qr)
}
if len(names) != len(test.N) {
t.Errorf("expected %#v, got %#v", test.N, names)
Expand All @@ -57,6 +57,11 @@ func TestCompileQuery(t *testing.T) {
if qd != test.D {
t.Errorf("expected %s, got %s", test.D, qd)
}

qq, _, _ := compileNamedQuery([]byte(test.Q), NAMED)
if qq != test.Q {
t.Errorf("expected %s, got %s", test.Q, qq)
}
}
}

Expand Down

0 comments on commit 95d2fd9

Please sign in to comment.