// Constraint returns the content for a where clause, and the args
// needed to execute it.
355825
func (b *belongsToAssociation) Constraint() (string, []interface{}) {
	return fmt.Sprintf("%s = ?", b.primaryTableID), []interface{}{b.ownerID.Interface()}
}
518005
func (p *ProvisionerAPI) Constraints(args params.Entities) (params.ConstraintsResults, error) {
	result := params.ConstraintsResults{
		Results: make([]params.ConstraintsResult, len(args.Entities)),
	}
	canAccess, err := p.getAuthFunc()
	if err != nil {
		return result, err
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseMachineTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		machine, err := p.getMachine(canAccess, tag)
		if err == nil {
			var cons constraints.Value
			cons, err = machine.Constraints()
			if err == nil {
				result.Results[i].Constraints = cons
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
456964
func (ts *TableSpec) AddConstraint(cd *ConstraintDefinition) {
	ts.Constraints = append(ts.Constraints, cd)
}
871072
func (stmt SelectStmt) Where(conds ...Clause) SelectStmt {
	if len(conds) > 1 {
		// By default, multiple where clauses will be joined will AllOf
		stmt.cond = AllOf(conds...)
	} else if len(conds) == 1 {
		stmt.cond = conds[0]
	}
	return stmt
}
184693
func (r Revision) Intersect(c Constraint) Constraint {
	switch tc := c.(type) {
	case anyConstraint:
		return r
	case noneConstraint:
		return none
	case versionTypeUnion:
		return tc.Intersect(r)
	case Revision:
		if r == tc {
			return r
		}
	case versionPair:
		if r == tc.r {
			return r
		}
	}

	return none
}
923328
func (exclude ExcludeConstraint) Modify(table *aspect.TableElem) error {
	// There must be at least one clause
	if len(exclude.clauses) == 0 {
		return fmt.Errorf(
			"postgres: an EXCLUDE constraint must contain at least one clause",
		)
	}

	// All excluded elements must exist in the given table
	for _, clause := range exclude.clauses {
		_, exists := table.C[clause.Name]
		if !exists {
			return fmt.Errorf(
				"No column with the name '%s' exists in the table '%s'. Is it declared after the PrimaryKey declaration?",
				clause.Name, table.Name(),
			)
		}
	}

	table.AddCreatable(exclude)
	return nil
}
935176
func (s constraintSolver) Solve(ctx sessionctx.Context, conditions []Expression) []Expression {
	exprs := newExprSet(ctx, conditions)
	s.fixPoint(ctx, exprs)
	return exprs.Slice()
}
334073
func NewConstrain(operator, version string) *Constraint {
	constraint := new(Constraint)
	constraint.SetOperator(operator)
	constraint.SetVersion(version)

	return constraint
}
1006907
func (c *Constraint) Match(whats ...string) bool {
	var match bool

	// full string match
	for _, what := range whats {
		// case insensitive compare
		if strings.EqualFold(c.exp, what) {
			match = true
			break
		}
	}

	switch c.operator {
	case eq:
		return match
	case noteq:
		return !match
	}

	return false
}
1050601
func (u *Unit) Constraints() (*constraints.Value, error) {
	cons, err := readConstraints(u.st, u.globalAgentKey())
	if errors.IsNotFound(err) {
		// Lack of constraints indicates lack of unit.
		return nil, errors.NotFoundf("unit")
	} else if err != nil {
		return nil, err
	}
	return &cons, nil
}
1111672
func (c *ConstraintMap) Match(params map[string]string) bool {
	// when no includes or excludes automatically match
	if len(c.Include) == 0 && len(c.Exclude) == 0 {
		return true
	}

	// exclusions are processed first. So we can include everything and then
	// selectively include others.
	if len(c.Exclude) != 0 {
		var matches int

		for key, val := range c.Exclude {
			if params[key] == val {
				matches++
			}
		}
		if matches == len(c.Exclude) {
			return false
		}
	}

	for key, val := range c.Include {
		if params[key] != val {
			return false
		}
	}

	return true
}
1362499
func (c *Constraint) Check(v *Version) bool {
	return c.f(v, c.check)
}
886674
func (m *Machine) Constraints() (constraints.Value, error) {
	return readConstraints(m.st, m.globalKey())
}
713524
func NewConstraint(c string) (*Constraints, error) {

	// Rewrite - ranges into a comparison operation.
	c = rewriteRange(c)

	ors := strings.Split(c, "||")
	or := make([][]*constraint, len(ors))
	for k, v := range ors {
		cs := strings.Split(v, ",")
		result := make([]*constraint, len(cs))
		for i, s := range cs {
			pc, err := parseConstraint(s)
			if err != nil {
				return nil, err
			}

			result[i] = pc
		}
		or[k] = result
	}

	o := &Constraints{constraints: or}
	return o, nil
}
614198
func (a *Dependency) Restrict(b *Dependency) *Dependency {
	newDep := &Dependency{
		Name: a.Name,
	}

	if a.MaxVer != nil || b.MaxVer != nil {
		newDep.MaxVer = &CompleteVersion{}

		if a.MaxVer == nil {
			*newDep.MaxVer = *b.MaxVer
			newDep.slt = b.slt
		} else if b.MaxVer == nil {
			*newDep.MaxVer = *a.MaxVer
			newDep.slt = a.slt
		} else {
			cmpMax := a.MaxVer.cmp(b.MaxVer)
			if cmpMax >= 1 {
				*newDep.MaxVer = *b.MaxVer
				newDep.slt = b.slt
			} else if cmpMax <= -1 {
				*newDep.MaxVer = *a.MaxVer
				newDep.slt = a.slt
			} else if cmpMax == 0 {
				if len(a.MaxVer.Pkgrel) > len(b.MaxVer.Pkgrel) {
					*newDep.MaxVer = *a.MaxVer
				} else {
					*newDep.MaxVer = *b.MaxVer
				}
				if a.slt != b.slt {
					newDep.slt = true
				} else {
					newDep.slt = a.slt
				}
			}
		}
	}

	if a.MinVer != nil || b.MinVer != nil {
		newDep.MinVer = &CompleteVersion{}

		if a.MinVer == nil {
			*newDep.MinVer = *b.MinVer
			newDep.sgt = b.slt
		} else if b.MinVer == nil {
			*newDep.MinVer = *a.MinVer
			newDep.sgt = a.sgt
		} else {
			cmpMin := a.MinVer.cmp(b.MinVer)
			if cmpMin >= 1 {
				*newDep.MinVer = *a.MinVer
				newDep.sgt = a.sgt
			} else if cmpMin <= -1 {
				*newDep.MinVer = *b.MinVer
				newDep.sgt = b.sgt
			} else if cmpMin == 0 {
				if len(a.MinVer.Pkgrel) > len(b.MinVer.Pkgrel) {
					*newDep.MinVer = *a.MinVer
				} else {
					*newDep.MinVer = *b.MinVer
				}
				if a.sgt != b.sgt {
					newDep.sgt = true
				} else {
					newDep.sgt = a.sgt
				}
			}
		}
	}

	return newDep
}
358442
func (c *Constraint) MatchConstraintWithAtLeastOneTag(tags []string) bool {
	for _, tag := range tags {
		if glob.Glob(c.Regex, tag) {
			return true
		}
	}
	return false
}
1294651
func EscapedConstraints(constraints []*Constraint) []*Constraint {
	var escaped []*Constraint
	for _, c := range constraints {
		if constraintTargetEscapes(c.LTarget) || constraintTargetEscapes(c.RTarget) {
			escaped = append(escaped, c)
		}
	}

	return escaped
}