MCPcopy Create free account
hub / github.com/araddon/qlbridge / parseCommand

Method parseCommand

rel/parse_sql.go:670–703  ·  view source on GitHub ↗

First keyword was SET, USE

()

Source from the content-addressed store, hash-verified

668
669// First keyword was SET, USE
670func (m *Sqlbridge) parseCommand() (*SqlCommand, error) {
671
672 /*
673 - SET CHARACTER SET utf8
674 - SET NAMES utf8
675 */
676 req := &SqlCommand{Columns: make(CommandColumns, 0)}
677 req.kw = m.Next().T // USE, SET
678
679 // USE `baseball`;
680 if req.kw == lex.TokenUse {
681 req.Identity = m.Next().V
682 return req, nil
683 }
684
685 cur := m.Cur()
686 peek := m.Peek()
687 // Look for special cases for mysql weird SET syntax
688 switch {
689 case cur.T == lex.TokenIdentity && strings.ToLower(cur.V) == "names":
690 //SET NAMES utf8
691 m.Next() // consume NAMES
692 col := &CommandColumn{Name: fmt.Sprintf("%s %s", cur.V, m.Next().V)}
693 req.Columns = append(req.Columns, col)
694 return req, nil
695 case cur.T == lex.TokenIdentity && strings.ToLower(cur.V) == "character" && strings.ToLower(peek.V) == "set":
696 m.Next() // consume character
697 m.Next() // consume set
698 col := &CommandColumn{Name: fmt.Sprintf("character set %s", m.Next().V)}
699 req.Columns = append(req.Columns, col)
700 return req, nil
701 }
702 return req, m.parseCommandColumns(req)
703}
704
705// First keyword was CREATE
706func (m *Sqlbridge) parseCreate() (*SqlCreate, error) {

Callers 1

parseMethod · 0.95

Calls 4

parseCommandColumnsMethod · 0.95
NextMethod · 0.65
CurMethod · 0.65
PeekMethod · 0.65

Tested by

no test coverage detected