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.

builder_set_operations.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2018 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. "fmt"
  7. "strings"
  8. )
  9. func (b *Builder) setOpWriteTo(w Writer) error {
  10. if b.limitation != nil || b.cond.IsValid() ||
  11. b.orderBy != "" || b.having != "" || b.groupBy != "" {
  12. return ErrNotUnexpectedUnionConditions
  13. }
  14. for idx, o := range b.setOps {
  15. current := o.builder
  16. if current.optype != selectType {
  17. return ErrUnsupportedUnionMembers
  18. }
  19. if len(b.setOps) == 1 {
  20. if err := current.selectWriteTo(w); err != nil {
  21. return err
  22. }
  23. } else {
  24. if b.dialect != "" && b.dialect != current.dialect {
  25. return ErrInconsistentDialect
  26. }
  27. if idx != 0 {
  28. if o.distinctType == "" {
  29. fmt.Fprint(w, fmt.Sprintf(" %s ", strings.ToUpper(o.opType)))
  30. } else {
  31. fmt.Fprint(w, fmt.Sprintf(" %s %s ", strings.ToUpper(o.opType), strings.ToUpper(o.distinctType)))
  32. }
  33. }
  34. fmt.Fprint(w, "(")
  35. if err := current.selectWriteTo(w); err != nil {
  36. return err
  37. }
  38. fmt.Fprint(w, ")")
  39. }
  40. }
  41. return nil
  42. }