MCPcopy
hub / github.com/go-gorm/gorm / QuoteTo

Method QuoteTo

statement.go:85–165  ·  view source on GitHub ↗

QuoteTo write quoted value to writer

(writer clause.Writer, field interface{})

Source from the content-addressed store, hash-verified

83
84// QuoteTo write quoted value to writer
85func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
86 write := func(raw bool, str string) {
87 if raw {
88 writer.WriteString(str)
89 } else {
90 stmt.DB.Dialector.QuoteTo(writer, str)
91 }
92 }
93
94 switch v := field.(type) {
95 case clause.Table:
96 if v.Name == clause.CurrentTable {
97 if stmt.TableExpr != nil {
98 stmt.TableExpr.Build(stmt)
99 } else if stmt.Table != "" {
100 write(v.Raw, stmt.Table)
101 } else if stmt.AddError(stmt.Parse(stmt.Model)) == nil {
102 write(v.Raw, stmt.Table)
103 }
104 } else {
105 write(v.Raw, v.Name)
106 }
107
108 if v.Alias != "" {
109 writer.WriteByte(' ')
110 write(v.Raw, v.Alias)
111 }
112 case clause.Column:
113 if v.Table != "" {
114 if v.Table == clause.CurrentTable {
115 write(v.Raw, stmt.Table)
116 } else {
117 write(v.Raw, v.Table)
118 }
119 writer.WriteByte('.')
120 }
121
122 if v.Name == clause.PrimaryKey {
123 if stmt.Schema == nil {
124 stmt.DB.AddError(ErrModelValueRequired)
125 } else if stmt.Schema.PrioritizedPrimaryField != nil {
126 write(v.Raw, stmt.Schema.PrioritizedPrimaryField.DBName)
127 } else if len(stmt.Schema.DBNames) > 0 {
128 write(v.Raw, stmt.Schema.DBNames[0])
129 } else {
130 stmt.DB.AddError(ErrModelAccessibleFieldsRequired) //nolint:typecheck,errcheck
131 }
132 } else {
133 write(v.Raw, v.Name)
134 }
135
136 if v.Alias != "" {
137 writer.WriteString(" AS ")
138 write(v.Raw, v.Alias)
139 }
140 case []clause.Column:
141 writer.WriteByte('(')
142 for idx, d := range v {

Callers 3

WriteQuotedMethod · 0.95
QuoteMethod · 0.95
AddVarMethod · 0.95

Calls 6

ParseMethod · 0.95
WriteStringMethod · 0.65
QuoteToMethod · 0.65
BuildMethod · 0.65
AddErrorMethod · 0.65
WriteByteMethod · 0.65

Tested by

no test coverage detected