MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / QualifyColumns

Function QualifyColumns

pkg/transform/tables.go:119–133  ·  view source on GitHub ↗

QualifyColumns returns a Rule that prefixes every unqualified column reference in a SELECT statement's column list and WHERE clause with tableName. Only identifiers that have no existing table qualifier and whose name is not the wildcard "*" are modified. This is useful when merging standalone colu

(tableName string)

Source from the content-addressed store, hash-verified

117//
118// Returns ErrUnsupportedStatement for non-SELECT statements.
119func QualifyColumns(tableName string) Rule {
120 return RuleFunc(func(stmt ast.Statement) error {
121 sel, err := getSelect(stmt, "QualifyColumns")
122 if err != nil {
123 return err
124 }
125 for i, col := range sel.Columns {
126 sel.Columns[i] = qualifyExpr(col, tableName)
127 }
128 if sel.Where != nil {
129 sel.Where = qualifyExpr(sel.Where, tableName)
130 }
131 return nil
132 })
133}
134
135func replaceTableInFrom(from []ast.TableReference, old, new string) {
136 for i := range from {

Callers 2

TestQualifyColumnsFunction · 0.85

Calls 3

RuleFuncFuncType · 0.85
getSelectFunction · 0.85
qualifyExprFunction · 0.85

Tested by 2

TestQualifyColumnsFunction · 0.68