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

Function balancedTableRefs

backend/plugin/parser/tidb/backup.go:783–793  ·  view source on GitHub ↗

balancedTableRefs returns s (trimmed) with parentheses balanced. omni's JoinClause/TableRef Loc excludes a wrapping "(" or ")", so a sliced table-ref list can carry an unmatched ")" (a parenthesized left join operand) and/or an unmatched "(" (a right operand). The missing parentheses only group, so

(s string)

Source from the content-addressed store, hash-verified

781// unmatched "(" (a right operand). The missing parentheses only group, so their
782// source position is irrelevant — prepend "(" and append ")" to balance.
783func balancedTableRefs(s string) string {
784 leading, trailing := parenDeficit(s)
785 s = strings.TrimSpace(s)
786 if leading > 0 {
787 s = strings.Repeat("(", leading) + s
788 }
789 if trailing > 0 {
790 s += strings.Repeat(")", trailing)
791 }
792 return s
793}
794
795// parenDeficit returns how many "(" must be prepended and ")" appended to
796// balance s, ignoring parentheses inside string/identifier literals ('...',

Callers 2

writeUpdateSuffixFunction · 0.85
writeDeleteSuffixFunction · 0.85

Calls 1

parenDeficitFunction · 0.85

Tested by

no test coverage detected