MCPcopy Create free account
hub / github.com/bytebase/bytebase / parseTableReferences

Method parseTableReferences

backend/plugin/parser/mysql/completion.go:926–956  ·  view source on GitHub ↗
(fromClause string)

Source from the content-addressed store, hash-verified

924}
925
926func (c *Completer) parseTableReferences(fromClause string) {
927 const prefix = "SELECT * "
928 tokens := mysqlparser.Tokenize(fromClause)
929
930 var selStmt *ast.SelectStmt
931 var wrappedSQL string
932 for end := len(tokens); end > 0; end-- {
933 if end < len(tokens) {
934 lastTok := tokens[end-1]
935 wrappedSQL = prefix + fromClause[:lastTok.End]
936 } else {
937 wrappedSQL = prefix + fromClause
938 }
939 parsed, err := ParseMySQLOmni(wrappedSQL)
940 if err != nil || parsed == nil || len(parsed.Items) == 0 {
941 continue
942 }
943 sel, ok := parsed.Items[0].(*ast.SelectStmt)
944 if ok && len(sel.From) > 0 {
945 selStmt = sel
946 break
947 }
948 }
949 if selStmt == nil {
950 return
951 }
952
953 for _, item := range selStmt.From {
954 c.extractFromItem(item, wrappedSQL)
955 }
956}
957
958func (c *Completer) parseInsertTableReferences(insertClause string) {
959 tokens := mysqlparser.Tokenize(insertClause)

Calls 2

extractFromItemMethod · 0.95
ParseMySQLOmniFunction · 0.85

Tested by

no test coverage detected