Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,119 @@ func TestSetLimit(t *testing.T) {
}
}

func TestSetAutocommitON(t *testing.T) {
stmt, err := Parse("SET autocommit=ON")
if err != nil {
t.Error(err)
}
s, ok := stmt.(*Set)
if !ok {
t.Errorf("SET statement is not Set: %T", s)
}

if len(s.Exprs) < 1 {
t.Errorf("SET statement has no expressions")
}

e := s.Exprs[0]
switch v := e.Expr.(type) {
case *SQLVal:
if v.Type != StrVal {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if !bytes.Equal([]byte("on"), v.Val) {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
t.Errorf("SET statement expression is not SQLVal: %T", e.Expr)
}

stmt, err = Parse("SET @@session.autocommit=ON")
if err != nil {
t.Error(err)
}
s, ok = stmt.(*Set)
if !ok {
t.Errorf("SET statement is not Set: %T", s)
}

if len(s.Exprs) < 1 {
t.Errorf("SET statement has no expressions")
}

e = s.Exprs[0]
switch v := e.Expr.(type) {
case *SQLVal:
if v.Type != StrVal {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if !bytes.Equal([]byte("on"), v.Val) {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
t.Errorf("SET statement expression is not SQLVal: %T", e.Expr)
}
}

func TestSetAutocommitOFF(t *testing.T) {
stmt, err := Parse("SET autocommit=OFF")
if err != nil {
t.Error(err)
}
s, ok := stmt.(*Set)
if !ok {
t.Errorf("SET statement is not Set: %T", s)
}

if len(s.Exprs) < 1 {
t.Errorf("SET statement has no expressions")
}

e := s.Exprs[0]
switch v := e.Expr.(type) {
case *SQLVal:
if v.Type != StrVal {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if !bytes.Equal([]byte("off"), v.Val) {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
t.Errorf("SET statement expression is not SQLVal: %T", e.Expr)
}

stmt, err = Parse("SET @@session.autocommit=OFF")
if err != nil {
t.Error(err)
}
s, ok = stmt.(*Set)
if !ok {
t.Errorf("SET statement is not Set: %T", s)
}

if len(s.Exprs) < 1 {
t.Errorf("SET statement has no expressions")
}

e = s.Exprs[0]
switch v := e.Expr.(type) {
case *SQLVal:
if v.Type != StrVal {
t.Errorf("SET statement value is not StrVal: %T", v)
}

if !bytes.Equal([]byte("off"), v.Val) {
t.Errorf("SET statement value want: on, got: %s", v.Val)
}
default:
t.Errorf("SET statement expression is not SQLVal: %T", e.Expr)
}

}

func TestWhere(t *testing.T) {
var w *Where
buf := NewTrackedBuffer(nil)
Expand Down
12 changes: 12 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ var (
input: "set @@session.'autocommit' = true",
}, {
input: "set @@session.\"autocommit\" = true",
}, {
input: "set @@session.autocommit = ON",
output: "set @@session.autocommit = 'on'",
}, {
input: "set @@session.autocommit= OFF",
output: "set @@session.autocommit = 'off'",
}, {
input: "set autocommit = on",
output: "set autocommit = 'on'",
}, {
input: "set autocommit = off",
output: "set autocommit = 'off'",
}, {
input: "set names utf8 collate foo",
output: "set names 'utf8'",
Expand Down
Loading