diff --git a/ast/dynamic.go b/ast/dynamic.go index caf93f2..7f5b0d5 100644 --- a/ast/dynamic.go +++ b/ast/dynamic.go @@ -129,51 +129,19 @@ func (n *WhenNode) Scan(start *xml.StartElement) error { } type OtherwiseNode struct { - Data *MyBatisData + *ChildrenNode } func NewOtherwiseNode() *OtherwiseNode { - return &OtherwiseNode{} + n := &OtherwiseNode{} + n.ChildrenNode = NewNode() + return n } func (n *OtherwiseNode) Scan(start *xml.StartElement) error { return nil } -func (n *OtherwiseNode) AddChildren(ns ...Node) error { - err := fmt.Errorf(` data is invalid`) - if len(ns) != 1 { - return err - } - switch d := ns[0].(type) { - case *MyBatisData: - n.Data = d - default: - return err - } - return nil -} - -func (n *OtherwiseNode) GetStmt(ctx *Context) (string, error) { - // fix: https://github.com/actiontech/sqle/issues/563 - // the label may be empty. - // - /* - - case 1 - - - case 2 - - #no default case - - */ - if n.Data != nil { - return n.Data.GetStmt(ctx) - } - return "", nil -} - type TrimNode struct { *ChildrenNode Name string diff --git a/parser_test.go b/parser_test.go index 8445e5d..89ce67b 100644 --- a/parser_test.go +++ b/parser_test.go @@ -995,3 +995,54 @@ func TestParserTrimSuffix_issue704(t *testing.T) { `, "INSERT INTO `agent` (`agent_no`,`agent_name`) VALUES (?,?);", ) } + +func TestOtherwise_issue1193(t *testing.T) { + testParser(t, ` + + + + `, "SELECT * FROM `fruits` WHERE `name`=? AND `price`=?;", + ) + + testParser(t, ` + + + + `, "SELECT * FROM `fruits` WHERE `name`=? AND `price`=? AND `category`=?;", + ) +}