// AddHaving adds the boolean expression to the
// HAVING clause as an AND condition. If the expression
// is an OR clause, it parenthesizes it. Currently,
// the OR operator is the only one that's lower precedence
// than AND.
320059
func (node *Select) AddHaving(expr Expr) {
	if _, ok := expr.(*OrExpr); ok {
		expr = &ParenExpr{Expr: expr}
	}
	if node.Having == nil {
		node.Having = &Where{
			Type: HavingStr,
			Expr: expr,
		}
		return
	}
	node.Having.Expr = &AndExpr{
		Left:  node.Having.Expr,
		Right: expr,
	}
}
1279803
func (rule *Rule) AddBehavior(behavior *Behavior) {
	for key, existingBehavior := range rule.Behaviors {
		if existingBehavior.Name == behavior.Name {
			rule.Behaviors[key] = behavior
			return
		}
	}

	rule.Behaviors = append(rule.Behaviors, behavior)
}
284399
func (session *Session) Having(conditions string) *Session {
	session.Statement.Having(conditions)
	return session
}
866914
func (engine *Engine) Having(conditions string) *Session {
	session := engine.NewSession()
	session.isAutoClose = true
	return session.Having(conditions)
}
1225161
func NewHaving(ctx *plan.Context, p *plan.Having) *Where {
	s := &Where{
		TaskBase: NewTaskBase(ctx),
		filter:   p.Stmt.Having,
	}
	s.Handler = whereFilter(p.Stmt.Having, s, p.Stmt.ColIndexes())
	return s
}
381690
func (b *SelectStmt) Having(query interface{}, value ...interface{}) *SelectStmt {
	switch query := query.(type) {
	case string:
		b.HavingCond = append(b.HavingCond, Expr(query, value...))
	case Builder:
		b.HavingCond = append(b.HavingCond, query)
	}
	return b
}
1308053
func (exclude ExcludeConstraint) Using(method IndexMethod) ExcludeConstraint {
	exclude.method = method
	return exclude
}
101541
func WithNothing() PrepareDecorator {
	return func(p Preparer) Preparer {
		return PreparerFunc(func(r *http.Request) (*http.Request, error) {
			return p.Prepare(r)
		})
	}
}
193072
func (pset *Permset) AddPerm(perm Perm) error {
	rv, _ := C.acl_add_perm(pset.p, C.acl_perm_t(perm))
	if rv < 0 {
		return fmt.Errorf("unable to add perm to permset")
	}
	return nil
}
103533
func (statement *Statement) Having(conditions string) *Statement {
	statement.HavingStr = fmt.Sprintf("HAVING %v", conditions)
	return statement
}
75895
func (s JoinTableHandler) Add(handler JoinTableHandlerInterface, db *DB, source interface{}, destination interface{}) error {
	var (
		scope        = db.NewScope("")
		conditionMap = map[string]interface{}{}
	)

	// Update condition map for source
	s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Source}, source)

	// Update condition map for destination
	s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Destination}, destination)

	var assignColumns, binVars, conditions []string
	var values []interface{}
	for key, value := range conditionMap {
		assignColumns = append(assignColumns, scope.Quote(key))
		binVars = append(binVars, `?`)
		conditions = append(conditions, fmt.Sprintf("%v = ?", scope.Quote(key)))
		values = append(values, value)
	}

	for _, value := range values {
		values = append(values, value)
	}

	quotedTable := scope.Quote(handler.Table(db))
	sql := fmt.Sprintf(
		"INSERT INTO %v (%v) SELECT %v %v WHERE NOT EXISTS (SELECT * FROM %v WHERE %v)",
		quotedTable,
		strings.Join(assignColumns, ","),
		strings.Join(binVars, ","),
		scope.Dialect().SelectFromDummyTable(),
		quotedTable,
		strings.Join(conditions, " AND "),
	)

	return db.Exec(sql, values...).Error
}
1212308
func (c *ConstructClause) AddWorkingPredicateObjectPair() {
	if c.workingPredicateObjectPair != nil && !c.workingPredicateObjectPair.IsEmpty() {
		c.predicateObjectPairs = append(c.predicateObjectPairs, c.workingPredicateObjectPair)
	}
	c.ResetWorkingPredicateObjectPair()
}
863875
func (rs *Ruleset) AddSingularExact(suffix, replacement string, exact bool) {
	// remove from uncountable
	delete(rs.uncountables, suffix)
	// create rule
	r := new(Rule)
	r.suffix = suffix
	r.replacement = replacement
	r.exact = exact
	rs.singulars = append([]*Rule{r}, rs.singulars...)
}
1360225
func (e BoolExprBuilder) Or(expr BoolExpr) BoolExprBuilder {
	var conditions []BoolExpr

	if orExpr, ok := e.BoolExpr.(*OrExpr); ok {
		conditions = append(conditions, orExpr.Exprs...)
	} else {
		conditions = append(conditions, e.BoolExpr)
	}

	unwrapped := unwrapBoolExpr(expr)
	if orExpr, ok := unwrapped.(*OrExpr); ok {
		conditions = append(conditions, orExpr.Exprs...)
	} else {
		conditions = append(conditions, unwrapped)
	}

	return BoolExprBuilder{
		&OrExpr{
			Op:    astOrExpr,
			Exprs: conditions,
		}}
}
1007240
func havingExpression() ElementHook {
	var f func(st *Statement, ce ConsumedElement) (ElementHook, error)
	f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
		if ce.IsSymbol() {
			return f, nil
		}
		if ce.token.Type != lexer.ItemHaving {
			st.havingExpression = append(st.havingExpression, ce)
		}
		return f, nil
	}
	return f
}
209313
func (conn *FakeVTGateConn) AddQuery(
	sql string,
	bindVariables map[string]*querypb.BindVariable,
	session *vtgatepb.Session,
	expectedResult *sqltypes.Result) {
	conn.execMap[sql] = &queryResponse{
		execQuery: &queryExecute{
			SQL:           sql,
			BindVariables: bindVariables,
			Session:       session,
		},
		reply: expectedResult,
	}
}
399781
func (p *parser) addConcatenate() {
	// The first (| inside a Testgroup group goes directly to the group
	p.concatenation.addChild(p.unit)
	p.unit = nil
}