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

Function SetLineForMySQLCreateTableStmt

backend/plugin/parser/tidb/tidb.go:155–169  ·  view source on GitHub ↗

SetLineForMySQLCreateTableStmt sets the line for columns and table constraints in MySQL CREATE TABLE statments. This is a temporary function. Because we do not convert tidb AST to our AST. So we have to implement this. TODO(rebelice): remove it.

(node *ast.CreateTableStmt)

Source from the content-addressed store, hash-verified

153// This is a temporary function. Because we do not convert tidb AST to our AST. So we have to implement this.
154// TODO(rebelice): remove it.
155func SetLineForMySQLCreateTableStmt(node *ast.CreateTableStmt) error {
156 // exclude CREATE TABLE ... AS and CREATE TABLE ... LIKE statement.
157 if len(node.Cols) == 0 {
158 return nil
159 }
160 // node.OriginTextPosition() is the statement's first line (the CREATE
161 // keyword). The tokenizer counts newlines from the START of node.Text(),
162 // which may retain leading newlines the native parser didn't strip, so its
163 // base must be the line of node.Text()'s first character — the statement
164 // line minus those leading newlines. Otherwise blank lines before the
165 // statement are double-counted into every column/constraint line (BYT-9381).
166 text := node.Text()
167 leadingNewlines := strings.Count(text[:len(text)-len(strings.TrimLeft(text, " \t\r\n"))], "\n")
168 return tokenizer.NewTokenizer(text).SetLineForMySQLCreateTableStmt(node, node.OriginTextPosition()-leadingNewlines)
169}
170
171// TypeString returns the string representation of the type for MySQL.
172func TypeString(tp byte) string {

Callers 2

applyTiDBLineTrackingFunction · 0.85

Calls 2

NewTokenizerFunction · 0.92

Tested by 1