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
11 changes: 10 additions & 1 deletion go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,16 @@ func (node *ColName) Format(buf *TrackedBuffer) {
if !node.Qualifier.IsEmpty() {
buf.astPrintf(node, "%v.", node.Qualifier)
}
buf.astPrintf(node, "%v", node.Name)
if !buf.IsDelimitCols() {
buf.astPrintf(node, "%v", node.Name)
return
}
if node.Name.IsEmpty() {
return
}
buf.WriteString(`"`)
buf.WriteString(node.Name.GetRawVal())
buf.WriteString(`"`)
}

// Format formats the node.
Expand Down
11 changes: 11 additions & 0 deletions go/vt/sqlparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,14 @@ func String(node SQLNode) string {
buf.Myprintf("%v", node)
return buf.String()
}

// String returns a string representation of an SQLNode.
func ColDelimitedString(node SQLNode) string {
if node == nil {
return "<nil>"
}

buf := NewTrackedBuffer(nil).WithDelimitCols(true)
buf.Myprintf("%v", node)
return buf.String()
}
10 changes: 10 additions & 0 deletions go/vt/sqlparser/tracked_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TrackedBuffer struct {
*strings.Builder
bindLocations []bindLocation
nodeFormatter NodeFormatter
isDelimitCols bool
}

// NewTrackedBuffer creates a new TrackedBuffer.
Expand All @@ -46,6 +47,15 @@ func NewTrackedBuffer(nodeFormatter NodeFormatter) *TrackedBuffer {
}
}

func (buf *TrackedBuffer) IsDelimitCols() bool {
return buf.isDelimitCols
}

func (buf *TrackedBuffer) WithDelimitCols(isDelimitCols bool) *TrackedBuffer {
buf.isDelimitCols = isDelimitCols
return buf
}

// WriteNode function, initiates the writing of a single SQLNode tree by passing
// through to Myprintf with a default format string
func (buf *TrackedBuffer) WriteNode(node SQLNode) *TrackedBuffer {
Expand Down