You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
636 B

  1. package builder
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. func (b *Builder) updateWriteTo(w Writer) error {
  7. if len(b.tableName) <= 0 {
  8. return errors.New("no table indicated")
  9. }
  10. if len(b.updates) <= 0 {
  11. return errors.New("no column to be update")
  12. }
  13. if _, err := fmt.Fprintf(w, "UPDATE %s SET ", b.tableName); err != nil {
  14. return err
  15. }
  16. for i, s := range b.updates {
  17. if err := s.opWriteTo(",", w); err != nil {
  18. return err
  19. }
  20. if i != len(b.updates)-1 {
  21. if _, err := fmt.Fprint(w, ","); err != nil {
  22. return err
  23. }
  24. }
  25. }
  26. if _, err := fmt.Fprint(w, " WHERE "); err != nil {
  27. return err
  28. }
  29. return b.cond.WriteTo(w)
  30. }