// SemanticBQL contains the BQL grammar with hooks injected.
423627
func SemanticBQL() *Grammar {
	semanticBQL := BQL()
	dataAcc := semantic.DataAccumulatorHook()

	// Create and Drop semantic hooks for type.
	setClauseHook(semanticBQL, []semantic.Symbol{"CREATE_GRAPHS"}, nil, semantic.TypeBindingClauseHook(semantic.Create))
	setClauseHook(semanticBQL, []semantic.Symbol{"DROP_GRAPHS"}, nil, semantic.TypeBindingClauseHook(semantic.Drop))

	// Add graph binding collection to GRAPHS and MORE_GRAPHS clauses.
	graphSymbols := []semantic.Symbol{"GRAPHS", "MORE_GRAPHS"}
	setElementHook(semanticBQL, graphSymbols, semantic.GraphAccumulatorHook(), nil)

	// Add graph binding collection to INPUT_GRAPHS and MORE_INPUT_GRAPHS clauses.
	inputGraphSymbols := []semantic.Symbol{"INPUT_GRAPHS", "MORE_INPUT_GRAPHS"}
	setElementHook(semanticBQL, inputGraphSymbols, semantic.InputGraphAccumulatorHook(), nil)

	// Add graph binding collection to OUTPUT_GRAPHS and MORE_OUTPUT_GRAPHS clauses.
	outputGraphSymbols := []semantic.Symbol{"OUTPUT_GRAPHS", "MORE_OUTPUT_GRAPHS"}
	setElementHook(semanticBQL, outputGraphSymbols, semantic.OutputGraphAccumulatorHook(), nil)

	// Insert and Delete semantic hooks addition.
	insertSymbols := []semantic.Symbol{
		"INSERT_OBJECT", "INSERT_DATA", "DELETE_OBJECT", "DELETE_DATA",
	}
	setElementHook(semanticBQL, insertSymbols, dataAcc, nil)
	setClauseHook(semanticBQL, []semantic.Symbol{"INSERT_OBJECT"}, nil, semantic.TypeBindingClauseHook(semantic.Insert))
	setClauseHook(semanticBQL, []semantic.Symbol{"DELETE_OBJECT"}, nil, semantic.TypeBindingClauseHook(semantic.Delete))

	// Query semantic hooks.
	setClauseHook(semanticBQL, []semantic.Symbol{"WHERE"}, semantic.WhereInitWorkingClauseHook(), semantic.VarBindingsGraphChecker())

	clauseSymbols := []semantic.Symbol{
		"CLAUSES", "MORE_CLAUSES",
	}
	setClauseHook(semanticBQL, clauseSymbols, semantic.WhereNextWorkingClauseHook(), semantic.WhereNextWorkingClauseHook())

	subSymbols := []semantic.Symbol{
		"CLAUSES", "SUBJECT_EXTRACT", "SUBJECT_TYPE", "SUBJECT_ID",
	}
	setElementHook(semanticBQL, subSymbols, semantic.WhereSubjectClauseHook(), nil)

	predSymbols := []semantic.Symbol{
		"PREDICATE", "PREDICATE_AS", "PREDICATE_ID", "PREDICATE_AT", "PREDICATE_BOUND_AT",
		"PREDICATE_BOUND_AT_BINDINGS", "PREDICATE_BOUND_AT_BINDINGS_END",
	}
	setElementHook(semanticBQL, predSymbols, semantic.WherePredicateClauseHook(), nil)

	objSymbols := []semantic.Symbol{
		"OBJECT", "OBJECT_SUBJECT_EXTRACT", "OBJECT_SUBJECT_TYPE", "OBJECT_SUBJECT_ID",
		"OBJECT_PREDICATE_AS", "OBJECT_PREDICATE_ID", "OBJECT_PREDICATE_AT",
		"OBJECT_PREDICATE_BOUND_AT", "OBJECT_PREDICATE_BOUND_AT_BINDINGS",
		"OBJECT_PREDICATE_BOUND_AT_BINDINGS_END", "OBJECT_LITERAL_AS",
		"OBJECT_LITERAL_BINDING_AS", "OBJECT_LITERAL_BINDING_TYPE",
		"OBJECT_LITERAL_BINDING_ID", "OBJECT_LITERAL_BINDING_AT",
	}
	setElementHook(semanticBQL, objSymbols, semantic.WhereObjectClauseHook(), nil)

	// Collect binding variables variables.
	varSymbols := []semantic.Symbol{
		"VARS", "VARS_AS", "MORE_VARS", "COUNT_DISTINCT",
	}
	setElementHook(semanticBQL, varSymbols, semantic.VarAccumulatorHook(), nil)

	// Collect and validate group by bindings.
	grpSymbols := []semantic.Symbol{"GROUP_BY", "GROUP_BY_BINDINGS"}
	setElementHook(semanticBQL, grpSymbols, semantic.GroupByBindings(), nil)
	setClauseHook(semanticBQL, []semantic.Symbol{"GROUP_BY"}, nil, semantic.GroupByBindingsChecker())

	// Collect and validate order by bindings.
	ordSymbols := []semantic.Symbol{"ORDER_BY", "ORDER_BY_DIRECTION", "ORDER_BY_BINDINGS"}
	setElementHook(semanticBQL, ordSymbols, semantic.OrderByBindings(), nil)
	setClauseHook(semanticBQL, []semantic.Symbol{"ORDER_BY"}, nil, semantic.OrderByBindingsChecker())

	// Collect the tokens that form the having clause and build the function
	// that will evaluate the result rows.
	havingSymbols := []semantic.Symbol{"HAVING", "HAVING_CLAUSE", "HAVING_CLAUSE_BINARY_COMPOSITE"}
	setElementHook(semanticBQL, havingSymbols, semantic.HavingExpression(), nil)
	setClauseHook(semanticBQL, []semantic.Symbol{"HAVING"}, nil, semantic.HavingExpressionBuilder())

	// Global time bound semantic hooks addition.
	globalSymbols := []semantic.Symbol{"GLOBAL_TIME_BOUND"}
	setElementHook(semanticBQL, globalSymbols, semantic.CollectGlobalBounds(), nil)

	// LIMIT clause semantic hook addition.
	limitSymbols := []semantic.Symbol{"LIMIT"}
	setElementHook(semanticBQL, limitSymbols, semantic.LimitCollection(), nil)

	// Global data accumulator hook.
	setElementHook(semanticBQL, []semantic.Symbol{"START"}, dataAcc,
		func(cls *Clause) bool {
			if t := cls.Elements[0].Token(); t != lexer.ItemInsert && t != lexer.ItemDelete {
				return false
			}
			return true
		})
	setClauseHook(semanticBQL, []semantic.Symbol{"START"}, nil, semantic.GroupByBindingsChecker())

	// CONSTRUCT and DECONSTRUCT clauses semantic hooks.
	setClauseHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_FACTS"}, semantic.InitWorkingConstructClauseHook(), semantic.TypeBindingClauseHook(semantic.Construct))
	setClauseHook(semanticBQL, []semantic.Symbol{"DECONSTRUCT_FACTS"}, semantic.InitWorkingConstructClauseHook(), semantic.TypeBindingClauseHook(semantic.Deconstruct))
	constructAndDeconstructTriplesSymbols := []semantic.Symbol{"CONSTRUCT_TRIPLES", "MORE_CONSTRUCT_TRIPLES", "DECONSTRUCT_TRIPLES", "MORE_DECONSTRUCT_TRIPLES"}
	setClauseHook(semanticBQL, constructAndDeconstructTriplesSymbols, semantic.NextWorkingConstructClauseHook(), semantic.NextWorkingConstructClauseHook())
	setClauseHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_PREDICATE"}, semantic.NextWorkingConstructPredicateObjectPairClauseHook(), nil)
	setClauseHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_OBJECT"}, nil, semantic.NextWorkingConstructPredicateObjectPairClauseHook())

	setElementHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_TRIPLES", "DECONSTRUCT_TRIPLES"}, semantic.ConstructSubjectHook(), nil)
	setElementHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_PREDICATE"}, semantic.ConstructPredicateHook(), nil)
	setElementHook(semanticBQL, []semantic.Symbol{"CONSTRUCT_OBJECT"}, semantic.ConstructObjectHook(), nil)

	// SHOW GRAPHS clause semantic hooks.
	setClauseHook(semanticBQL, []semantic.Symbol{"GRAPH_SHOW"}, nil, semantic.ShowClauseHook())

	return semanticBQL
}
384287
func (db DBWrapper) Query(sqlText string, args ...interface{}) (qr QueryResult) {
	rows, err := db.DB.Query(sqlText, args...)
	defer func() {
		if rows != nil {
			rows.Close()
		}
	}()

	if err != nil {
		db.logError(err, sqlText, args)
		qr.Error = err
		return
	}

	qr.Cols, err = rows.Columns()
	if err != nil {
		db.logError(err, sqlText, args)
		qr.Error = err
		return
	}
	qr.Rows = make([]Row, 0, 10) // Default len 10
	for rows.Next() {
		row := make([]interface{}, len(qr.Cols))
		for i, _ := range row {
			row[i] = new([]byte)
		}

		rows.Scan(row...)
		qr.Rows = append(qr.Rows, row)
	}
	return
}
1207826
func (sess *Session) SelectBySql(query string, value ...interface{}) *SelectStmt {
	b := SelectBySql(query, value...)
	b.runner = sess
	b.EventReceiver = sess.EventReceiver
	b.Dialect = sess.Dialect
	return b
}
1155795
func (db *baseDB) QueryOne(model, query interface{}, params ...interface{}) (Result, error) {
	return db.queryOne(context.TODO(), model, query, params...)
}
308586
func RedactSQLQuery(sql string) (string, error) {
	bv := map[string]*querypb.BindVariable{}
	sqlStripped, comments := SplitMarginComments(sql)

	stmt, err := Parse(sqlStripped)
	if err != nil {
		return "", err
	}

	prefix := "redacted"
	Normalize(stmt, bv, prefix)

	return comments.Leading + String(stmt) + comments.Trailing, nil
}
1154334
func ToCQL(e *dosa.EntityDefinition) string {
	var buf bytes.Buffer
	// errors are ignored here, they can only happen from an invalid template, which will get caught in tests
	err := cqlCreateTableTemplate.Execute(&buf, e)
	if err != nil {
		panic(err)
	}
	return buf.String()
}
116977
func (b *InsertBuilder) ToCql() (stmt string, names []string) {
	cql := bytes.Buffer{}

	cql.WriteString("INSERT ")

	cql.WriteString("INTO ")
	cql.WriteString(b.table)
	cql.WriteByte(' ')

	cql.WriteByte('(')
	for i, c := range b.columns {
		cql.WriteString(c.column)
		if i < len(b.columns)-1 {
			cql.WriteByte(',')
		}
	}
	cql.WriteString(") ")

	cql.WriteString("VALUES (")
	for i, c := range b.columns {
		names = append(names, c.value.writeCql(&cql)...)
		if i < len(b.columns)-1 {
			cql.WriteByte(',')
		}
	}
	cql.WriteString(") ")

	if b.unique {
		cql.WriteString("IF NOT EXISTS ")
	}
	names = append(names, b.using.writeCql(&cql)...)

	stmt = cql.String()
	return
}
899843
func newFooBarQueryBuilderWithKind(kind string) *fooBarQueryBuilder {
	q := datastore.NewQuery(kind)
	bldr := &fooBarQueryBuilder{q: q}
	bldr.Foo = &fooBarQueryProperty{
		bldr: bldr,
		name: "Foo",
	}

	if plugger, ok := interface{}(bldr).(qbgutils.Plugger); ok {
		bldr.plugin = plugger.Plugin()
		bldr.plugin.Init("FooBar")
	}

	return bldr
}
1329997
func Q(c *Connection) *Query {
	return &Query{
		RawSQL:      &clause{},
		Connection:  c,
		eager:       c.eager,
		eagerFields: c.eagerFields,
	}
}
595194
func (tx *Tx) QueryContext(
	c context.Context,
	model interface{},
	query interface{},
	params ...interface{},
) (Result, error) {
	return tx.query(c, model, query, params...)
}
877387
func (conn *OCI8Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
	list := make([]namedValue, len(args))
	for i, nv := range args {
		list[i] = toNamedValue(nv)
	}
	return conn.query(ctx, query, list)
}
4507
func NewSQL(cfg *SQLConfig) (*SQL, error) {
	if err := validateSQLConfig(cfg); err != nil {
		return nil, err
	}

	return &SQL{
		Config: cfg,
	}, nil
}
82726
func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error) {
	args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
	if err != nil {
		return nil, err
	}
	return n.Stmt.QueryContext(ctx, args...)
}
660841
func (e *EgressRule) IsLabelBased() bool {
	return len(e.ToRequires)+len(e.ToCIDR)+len(e.ToCIDRSet)+len(e.ToServices)+len(e.ToFQDNs) == 0
}
1194052
func (c *Corpus) br(br blob.Ref) blob.Ref {
	if bm, ok := c.blobs[br]; ok {
		c.brInterns++
		return bm.Ref
	}
	return br
}
917741
func newSubquery(alias sqlparser.TableIdent, bldr builder) (*subquery, *symtab, error) {
	sq := &subquery{
		order:     bldr.Order() + 1,
		input:     bldr,
		esubquery: &engine.Subquery{},
	}

	// Create a 'table' that represents the subquery.
	t := &table{
		alias:  sqlparser.TableName{Name: alias},
		origin: sq,
	}

	// Create column symbols based on the result column names.
	for _, rc := range bldr.ResultColumns() {
		if _, ok := t.columns[rc.alias.Lowered()]; ok {
			return nil, nil, fmt.Errorf("duplicate column names in subquery: %s", sqlparser.String(rc.alias))
		}
		t.addColumn(rc.alias, &column{origin: sq})
	}
	t.isAuthoritative = true
	st := newSymtab()
	// AddTable will not fail because symtab is empty.
	_ = st.AddTable(t)
	return sq, st, nil
}
549811
func (d DotSql) Raw(name string) (string, error) {
	return d.lookupQuery(name)
}