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

Method SQL

pkg/sql/ast/sql.go:1123–1165  ·  view source on GitHub ↗

DML types from dml.go SQL returns the SQL representation of this Select node (dml.go type), which is a simplified SELECT structure used in compatibility code paths. For full-featured SELECT parsing use SelectStatement.SQL() instead.

()

Source from the content-addressed store, hash-verified

1121// is a simplified SELECT structure used in compatibility code paths.
1122// For full-featured SELECT parsing use SelectStatement.SQL() instead.
1123func (s *Select) SQL() string {
1124 if s == nil {
1125 return ""
1126 }
1127 sb := getBuilder()
1128 defer putBuilder(sb)
1129 sb.WriteString("SELECT ")
1130 if s.Distinct {
1131 sb.WriteString("DISTINCT ")
1132 }
1133 sb.WriteString(exprListSQL(s.Columns))
1134 if len(s.From) > 0 {
1135 sb.WriteString(" FROM ")
1136 froms := make([]string, len(s.From))
1137 for i := range s.From {
1138 froms[i] = tableRefSQL(&s.From[i])
1139 }
1140 sb.WriteString(strings.Join(froms, ", "))
1141 }
1142 if s.Where != nil {
1143 sb.WriteString(" WHERE ")
1144 sb.WriteString(exprSQL(s.Where))
1145 }
1146 if len(s.GroupBy) > 0 {
1147 sb.WriteString(" GROUP BY ")
1148 sb.WriteString(exprListSQL(s.GroupBy))
1149 }
1150 if s.Having != nil {
1151 sb.WriteString(" HAVING ")
1152 sb.WriteString(exprSQL(s.Having))
1153 }
1154 if len(s.OrderBy) > 0 {
1155 sb.WriteString(" ORDER BY ")
1156 sb.WriteString(orderBySQL(s.OrderBy))
1157 }
1158 if s.Limit != nil {
1159 fmt.Fprintf(sb, " LIMIT %d", *s.Limit)
1160 }
1161 if s.Offset != nil {
1162 fmt.Fprintf(sb, " OFFSET %d", *s.Offset)
1163 }
1164 return sb.String()
1165}
1166
1167// SQL returns the SQL representation of this Insert node (dml.go type).
1168// For the full-featured INSERT use InsertStatement.SQL() instead.

Callers 2

TestSelect_SQLFunction · 0.95
TestNilSQLFunction · 0.95

Calls 7

getBuilderFunction · 0.85
putBuilderFunction · 0.85
exprListSQLFunction · 0.70
tableRefSQLFunction · 0.70
exprSQLFunction · 0.70
orderBySQLFunction · 0.70
StringMethod · 0.45

Tested by 2

TestSelect_SQLFunction · 0.76
TestNilSQLFunction · 0.76