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

Method SQL

pkg/sql/ast/sql.go:684–731  ·  view source on GitHub ↗

SQL returns the full SQL string for this UPDATE statement, including the optional WITH clause, SET assignments, FROM clause, WHERE condition, and RETURNING clause.

()

Source from the content-addressed store, hash-verified

682// optional WITH clause, SET assignments, FROM clause, WHERE condition, and
683// RETURNING clause.
684func (u *UpdateStatement) SQL() string {
685 if u == nil {
686 return ""
687 }
688 sb := getBuilder()
689 defer putBuilder(sb)
690
691 if u.With != nil {
692 sb.WriteString(u.With.SQL())
693 sb.WriteString(" ")
694 }
695
696 sb.WriteString("UPDATE ")
697 sb.WriteString(u.TableName)
698 if u.Alias != "" {
699 sb.WriteString(" ")
700 sb.WriteString(u.Alias)
701 }
702
703 sb.WriteString(" SET ")
704 updates := u.Assignments
705 upds := make([]string, len(updates))
706 for i, upd := range updates {
707 upds[i] = exprSQL(upd.Column) + " = " + exprSQL(upd.Value)
708 }
709 sb.WriteString(strings.Join(upds, ", "))
710
711 if len(u.From) > 0 {
712 sb.WriteString(" FROM ")
713 froms := make([]string, len(u.From))
714 for i := range u.From {
715 froms[i] = tableRefSQL(&u.From[i])
716 }
717 sb.WriteString(strings.Join(froms, ", "))
718 }
719
720 if u.Where != nil {
721 sb.WriteString(" WHERE ")
722 sb.WriteString(exprSQL(u.Where))
723 }
724
725 if len(u.Returning) > 0 {
726 sb.WriteString(" RETURNING ")
727 sb.WriteString(exprListSQL(u.Returning))
728 }
729
730 return sb.String()
731}
732
733// SQL returns the full SQL string for this DELETE statement, including the
734// optional WITH clause, USING clause, WHERE condition, and RETURNING clause.

Callers 3

TestNilSQLFunction · 0.95
TestUpdateStatementSQLFunction · 0.95

Calls 7

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

Tested by 3

TestNilSQLFunction · 0.76
TestUpdateStatementSQLFunction · 0.76