本站源代码
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.

48 lines
982B

  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) unionWriteTo(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, u := range b.unions {
  15. current := u.builder
  16. if current.optype != selectType {
  17. return ErrUnsupportedUnionMembers
  18. }
  19. if len(b.unions) == 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. fmt.Fprint(w, fmt.Sprintf(" UNION %v ", strings.ToUpper(u.unionType)))
  29. }
  30. fmt.Fprint(w, "(")
  31. if err := current.selectWriteTo(w); err != nil {
  32. return err
  33. }
  34. fmt.Fprint(w, ")")
  35. }
  36. }
  37. return nil
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1