File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -1795,7 +1795,16 @@ func (node *ColName) Format(buf *TrackedBuffer) {
17951795 if ! node .Qualifier .IsEmpty () {
17961796 buf .astPrintf (node , "%v." , node .Qualifier )
17971797 }
1798- buf .astPrintf (node , "%v" , node .Name )
1798+ if ! buf .IsDelimitCols () {
1799+ buf .astPrintf (node , "%v" , node .Name )
1800+ return
1801+ }
1802+ if node .Name .IsEmpty () {
1803+ return
1804+ }
1805+ buf .WriteString (`"` )
1806+ buf .WriteString (node .Name .GetRawVal ())
1807+ buf .WriteString (`"` )
17991808}
18001809
18011810// Format formats the node.
Original file line number Diff line number Diff line change @@ -221,3 +221,14 @@ func String(node SQLNode) string {
221221 buf .Myprintf ("%v" , node )
222222 return buf .String ()
223223}
224+
225+ // String returns a string representation of an SQLNode.
226+ func ColDelimitedString (node SQLNode ) string {
227+ if node == nil {
228+ return "<nil>"
229+ }
230+
231+ buf := NewTrackedBuffer (nil ).WithDelimitCols (true )
232+ buf .Myprintf ("%v" , node )
233+ return buf .String ()
234+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ type TrackedBuffer struct {
3636 * strings.Builder
3737 bindLocations []bindLocation
3838 nodeFormatter NodeFormatter
39+ isDelimitCols bool
3940}
4041
4142// NewTrackedBuffer creates a new TrackedBuffer.
@@ -46,6 +47,15 @@ func NewTrackedBuffer(nodeFormatter NodeFormatter) *TrackedBuffer {
4647 }
4748}
4849
50+ func (buf * TrackedBuffer ) IsDelimitCols () bool {
51+ return buf .isDelimitCols
52+ }
53+
54+ func (buf * TrackedBuffer ) WithDelimitCols (isDelimitCols bool ) * TrackedBuffer {
55+ buf .isDelimitCols = isDelimitCols
56+ return buf
57+ }
58+
4959// WriteNode function, initiates the writing of a single SQLNode tree by passing
5060// through to Myprintf with a default format string
5161func (buf * TrackedBuffer ) WriteNode (node SQLNode ) * TrackedBuffer {
You can’t perform that action at this time.
0 commit comments