builder_update.go 798 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2016 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import (
  6. "errors"
  7. "fmt"
  8. )
  9. func (b *Builder) updateWriteTo(w Writer) error {
  10. if len(b.tableName) <= 0 {
  11. return errors.New("no table indicated")
  12. }
  13. if len(b.updates) <= 0 {
  14. return errors.New("no column to be update")
  15. }
  16. if _, err := fmt.Fprintf(w, "UPDATE %s SET ", b.tableName); err != nil {
  17. return err
  18. }
  19. for i, s := range b.updates {
  20. if err := s.opWriteTo(",", w); err != nil {
  21. return err
  22. }
  23. if i != len(b.updates)-1 {
  24. if _, err := fmt.Fprint(w, ","); err != nil {
  25. return err
  26. }
  27. }
  28. }
  29. if _, err := fmt.Fprint(w, " WHERE "); err != nil {
  30. return err
  31. }
  32. return b.cond.WriteTo(w)
  33. }