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

Method SQL

pkg/sql/ast/sql.go:1169–1199  ·  view source on GitHub ↗

SQL returns the SQL representation of this Insert node (dml.go type). For the full-featured INSERT use InsertStatement.SQL() instead.

()

Source from the content-addressed store, hash-verified

1167// SQL returns the SQL representation of this Insert node (dml.go type).
1168// For the full-featured INSERT use InsertStatement.SQL() instead.
1169func (i *Insert) SQL() string {
1170 if i == nil {
1171 return ""
1172 }
1173 sb := getBuilder()
1174 defer putBuilder(sb)
1175 sb.WriteString("INSERT INTO ")
1176 sb.WriteString(tableRefSQL(&i.Table))
1177 if len(i.Columns) > 0 {
1178 sb.WriteString(" (")
1179 sb.WriteString(exprListSQL(i.Columns))
1180 sb.WriteString(")")
1181 }
1182 if len(i.Values) > 0 {
1183 sb.WriteString(" VALUES ")
1184 rows := make([]string, len(i.Values))
1185 for idx, row := range i.Values {
1186 vals := make([]string, len(row))
1187 for j, v := range row {
1188 vals[j] = exprSQL(v)
1189 }
1190 rows[idx] = "(" + strings.Join(vals, ", ") + ")"
1191 }
1192 sb.WriteString(strings.Join(rows, ", "))
1193 }
1194 if len(i.ReturningClause) > 0 {
1195 sb.WriteString(" RETURNING ")
1196 sb.WriteString(exprListSQL(i.ReturningClause))
1197 }
1198 return sb.String()
1199}
1200
1201// SQL returns the SQL representation of this Update node (dml.go type).
1202// For the full-featured UPDATE use UpdateStatement.SQL() instead.

Callers 2

TestInsert_SQLFunction · 0.95
TestNilSQLFunction · 0.95

Calls 6

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

Tested by 2

TestInsert_SQLFunction · 0.76
TestNilSQLFunction · 0.76