use string builder in buildOrderby

This commit is contained in:
Azareal 2020-03-05 10:40:40 +10:00
parent c31ca03a0d
commit 1bee9a35f2
1 changed files with 14 additions and 4 deletions

View File

@ -715,12 +715,22 @@ func (a *MysqlAdapter) buildFlexiWhere(where string, dateCutoff *dateCutoff) (q
func (a *MysqlAdapter) buildOrderby(orderby string) (q string) { func (a *MysqlAdapter) buildOrderby(orderby string) (q string) {
if len(orderby) != 0 { if len(orderby) != 0 {
q = " ORDER BY " var sb strings.Builder
for _, column := range processOrderby(orderby) { ord := processOrderby(orderby)
sb.Grow(10 + (len(ord) * 8) - 1)
sb.WriteString(" ORDER BY ")
for i, col := range ord {
// TODO: We might want to escape this column // TODO: We might want to escape this column
q += "`" + strings.Replace(column.Column, ".", "`.`", -1) + "` " + strings.ToUpper(column.Order) + "," if i != 0 {
sb.WriteString(",`")
} else {
sb.WriteString("`")
}
sb.WriteString(strings.Replace(col.Column, ".", "`.`", -1))
sb.WriteString("` ")
sb.WriteString(strings.ToUpper(col.Order))
} }
q = q[0 : len(q)-1] q = sb.String()
} }
return q return q
} }