// specifyClauseWithTable runs the clause, but it specifies it further based on
// the current row being processed.
186813
func (p *queryPlan) specifyClauseWithTable(ctx context.Context, cls *semantic.GraphClause, lo *storage.LookupOptions) error {
	rws := p.tbl.Rows()
	p.tbl.Truncate()
	var (
		gErr error
		mu   sync.Mutex
		wg   sync.WaitGroup
	)
	for _, tmpRow := range rws {
		wg.Add(1)
		go func(r table.Row) {
			defer wg.Done()
			var tmpCls = *cls
			// The table manipulations are now thread safe.
			if err := p.addSpecifiedData(ctx, r, &tmpCls, lo); err != nil {
				mu.Lock()
				gErr = err
				mu.Unlock()
			}
		}(tmpRow)
	}
	wg.Wait()
	return gErr
}
1193348
func checkSQLSyntax(ctx *cli.Context) {
	if !ctx.Args().Present() {
		cli.ShowCommandHelpAndExit(ctx, "sql", 1) // last argument is exit code.
	}
}
1229106
func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result {
	res, err := n.ExecContext(ctx, arg)
	if err != nil {
		panic(err)
	}
	return res
}
880590
func orderByBindingsChecker() ClauseHook {
	var f ClauseHook
	f = func(s *Statement, _ Symbol) (ClauseHook, error) {
		// Force working projection flush.
		outs := make(map[string]bool)
		for _, out := range s.OutputBindings() {
			outs[out] = true
		}
		seen, dups := make(map[string]bool), false
		for _, cfg := range s.orderBy {
			// Check there are no contradictions
			if b, ok := seen[cfg.Binding]; ok {
				if b != cfg.Desc {
					return nil, fmt.Errorf("inconsisting sorting direction for %q binding", cfg.Binding)
				}
				dups = true
			} else {
				seen[cfg.Binding] = cfg.Desc
			}
			// Check that the binding exist.
			if _, ok := outs[cfg.Binding]; !ok {
				return nil, fmt.Errorf("order by binding %q unknown; available bindings are %v", cfg.Binding, s.OutputBindings())
			}
		}
		// If dups exist rewrite the order by SortConfig.
		if dups {
			s.orderBy = table.SortConfig{}
			for b, d := range seen {
				s.orderBy = append(s.orderBy, table.SortConfig{{Binding: b, Desc: d}}...)
			}
		}
		return f, nil
	}
	return f
}
545830
func Table(table string) *RegommendTable {
	mutex.RLock()
	t, ok := tables[table]
	mutex.RUnlock()

	if !ok {
		t = &RegommendTable{
			name:  table,
			items: make(map[interface{}]*RegommendItem),
		}

		mutex.Lock()
		tables[table] = t
		mutex.Unlock()
	}

	return t
}
9606
func sqlExecStmt(stmt *sql.Stmt, execErrPrefix string, args ...interface{}) (int64, error) {
	res, err := stmt.Exec(args...)
	if err != nil {
		return 0, fmt.Errorf("%v %v", execErrPrefix, err)
	}
	if res == nil {
		return 0, nil
	}

	var N int64
	N, err = res.RowsAffected()
	if err != nil {
		return 0, fmt.Errorf(`error in RowsAffected: %v`, err)
	}
	return N, err
}
1084224
func checkAffinity(ctx Context, operand string, lVal, rVal interface{}, lFound, rFound bool) bool {
	return checkConstraint(ctx, operand, lVal, rVal, lFound, rFound)
}
28384
func (statement *Statement) Table(tableNameOrBean interface{}) *Statement {
	v := rValue(tableNameOrBean)
	t := v.Type()
	if t.Kind() == reflect.String {
		statement.AltTableName = tableNameOrBean.(string)
	} else if t.Kind() == reflect.Struct {
		statement.RefTable = statement.Engine.autoMapType(v)
		statement.AltTableName = statement.Engine.tbName(v)
	}
	return statement
}
548376
func (p *Policy) AllowTables() {

	// "table" is permitted
	p.AllowAttrs("height", "width").Matching(NumberOrPercent).OnElements("table")
	p.AllowAttrs("summary").Matching(Paragraph).OnElements("table")

	// "caption" is permitted
	p.AllowElements("caption")

	// "col" "colgroup" are permitted
	p.AllowAttrs("align").Matching(CellAlign).OnElements("col", "colgroup")
	p.AllowAttrs("height", "width").Matching(
		NumberOrPercent,
	).OnElements("col", "colgroup")
	p.AllowAttrs("span").Matching(Integer).OnElements("colgroup", "col")
	p.AllowAttrs("valign").Matching(
		CellVerticalAlign,
	).OnElements("col", "colgroup")

	// "thead" "tr" are permitted
	p.AllowAttrs("align").Matching(CellAlign).OnElements("thead", "tr")
	p.AllowAttrs("valign").Matching(CellVerticalAlign).OnElements("thead", "tr")

	// "td" "th" are permitted
	p.AllowAttrs("abbr").Matching(Paragraph).OnElements("td", "th")
	p.AllowAttrs("align").Matching(CellAlign).OnElements("td", "th")
	p.AllowAttrs("colspan", "rowspan").Matching(Integer).OnElements("td", "th")
	p.AllowAttrs("headers").Matching(
		SpaceSeparatedTokens,
	).OnElements("td", "th")
	p.AllowAttrs("height", "width").Matching(
		NumberOrPercent,
	).OnElements("td", "th")
	p.AllowAttrs(
		"scope",
	).Matching(
		regexp.MustCompile(`(?i)(?:row|col)(?:group)?`),
	).OnElements("td", "th")
	p.AllowAttrs("valign").Matching(CellVerticalAlign).OnElements("td", "th")
	p.AllowAttrs("nowrap").Matching(
		regexp.MustCompile(`(?i)|nowrap`),
	).OnElements("td", "th")

	// "tbody" "tfoot"
	p.AllowAttrs("align").Matching(CellAlign).OnElements("tbody", "tfoot")
	p.AllowAttrs("valign").Matching(
		CellVerticalAlign,
	).OnElements("tbody", "tfoot")
}
736974
func (s *Listener) SetClientAffinity(v string) *Listener {
	s.ClientAffinity = &v
	return s
}
120703
func (t *Table) SetCellSimple(row, column int, text string) *Table {
	t.SetCell(row, column, NewTableCell(text))
	return t
}
892895
func TypeBindingClauseHook(t StatementType) ClauseHook {
	var f ClauseHook
	f = func(s *Statement, _ Symbol) (ClauseHook, error) {
		s.BindType(t)
		return f, nil
	}
	return f
}
144033
func (d SqliteDialect) QuotedTableForQuery(schema string, table string) string {
	return d.QuoteField(table)
}
361322
func (s *CreateIntentVersionOutput) SetConclusionStatement(v *Statement) *CreateIntentVersionOutput {
	s.ConclusionStatement = v
	return s
}
693753
func (t *Table) MustColumn(name string) Slice {
	if c := t.Column(name); c != nil {
		return c
	}
	panic(fmt.Sprintf("unknown column %q", name))
}
1049258
func (statement *Statement) Table(tableNameOrBean interface{}) *Statement {
	v := rValue(tableNameOrBean)
	t := v.Type()
	if t.Kind() == reflect.Struct {
		var err error
		statement.RefTable, err = statement.Engine.autoMapType(v)
		if err != nil {
			statement.Engine.logger.Error(err)
			return statement
		}
	}

	statement.AltTableName = statement.Engine.TableName(tableNameOrBean, true)
	return statement
}
1032275
func wherePredicateClause() ElementHook {
	var (
		f            ElementHook
		lastNopToken *lexer.Token
	)
	f = func(st *Statement, ce ConsumedElement) (ElementHook, error) {
		if ce.IsSymbol() {
			return f, nil
		}
		tkn := ce.Token()
		c := st.WorkingClause()
		switch tkn.Type {
		case lexer.ItemPredicate:
			lastNopToken = nil
			if c.P != nil {
				return nil, fmt.Errorf("invalid predicate %s on graph clause since already set to %s", tkn.Text, c.P)
			}
			p, pID, pAnchorBinding, pTemporal, err := processPredicate(ce)
			if err != nil {
				return nil, err
			}
			c.P, c.PID, c.PAnchorBinding, c.PTemporal = p, pID, pAnchorBinding, pTemporal
			return f, nil
		case lexer.ItemPredicateBound:
			lastNopToken = nil
			if c.PLowerBound != nil || c.PUpperBound != nil || c.PLowerBoundAlias != "" || c.PUpperBoundAlias != "" {
				return nil, fmt.Errorf("invalid predicate bound %s on graph clause since already set to %s", tkn.Text, c.P)
			}
			pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp, err := processPredicateBound(ce)
			if err != nil {
				return nil, err
			}
			c.PID, c.PLowerBoundAlias, c.PUpperBoundAlias, c.PLowerBound, c.PUpperBound, c.PTemporal = pID, pLowerBoundAlias, pUpperBoundAlias, pLowerBound, pUpperBound, pTemp
			return f, nil
		case lexer.ItemBinding:
			if lastNopToken == nil {
				if c.PBinding != "" {
					return nil, fmt.Errorf("invalid binding %q loose after no valid modifier", tkn.Text)
				}
				c.PBinding = tkn.Text
				return f, nil
			}
			switch lastNopToken.Type {
			case lexer.ItemAs:
				if c.PAlias != "" {
					return nil, fmt.Errorf("AS alias binding for predicate has already being assigned on %v", st)
				}
				c.PAlias = tkn.Text
			case lexer.ItemID:
				if c.PIDAlias != "" {
					return nil, fmt.Errorf("ID alias binding for predicate has already being assigned on %v", st)
				}
				c.PIDAlias = tkn.Text
			case lexer.ItemAt:
				if c.PAnchorAlias != "" {
					return nil, fmt.Errorf("AT alias binding for predicate has already being assigned on %v", st)
				}
				c.PAnchorAlias = tkn.Text
			default:
				return nil, fmt.Errorf("binding %q found after invalid token %s", tkn.Text, lastNopToken)
			}
			lastNopToken = nil
			return f, nil
		}
		lastNopToken = tkn
		return f, nil
	}
	return f
}