// GinTsqueryConsistent calls the stored procedure 'pg_catalog.gin_tsquery_consistent(internal, smallint, tsquery, integer, internal, internal, internal, smallint, tsquery, integer, internal, internal, internal, internal) boolean' on db.
514474
func GinTsqueryConsistent(db XODB, v0 pgtypes.Internal, v1 int16, v2 pgtypes.Tsquery, v3 int, v4 pgtypes.Internal, v5 pgtypes.Internal, v6 pgtypes.Internal, v7 int16, v8 pgtypes.Tsquery, v9 int, v10 pgtypes.Internal, v11 pgtypes.Internal, v12 pgtypes.Internal, v13 pgtypes.Internal) (bool, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.gin_tsquery_consistent($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)`

	// run query
	var ret bool
	XOLog(sqlstr, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13).Scan(&ret)
	if err != nil {
		return false, err
	}

	return ret, nil
}
900006
func (scope *Scope) CombinedConditionSql() string {
	joinSQL := scope.joinsSQL()
	whereSQL := scope.whereSQL()
	if scope.Search.raw {
		whereSQL = strings.TrimSuffix(strings.TrimPrefix(whereSQL, "WHERE ("), ")")
	}
	return joinSQL + whereSQL + scope.groupSQL() +
		scope.havingSQL() + scope.orderSQL() + scope.limitAndOffsetSQL()
}
775581
func Ginoptions(db XODB, v0 StringSlice, v1 bool) ([]byte, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.ginoptions($1, $2)`

	// run query
	var ret []byte
	XOLog(sqlstr, v0, v1)
	err = db.QueryRow(sqlstr, v0, v1).Scan(&ret)
	if err != nil {
		return nil, err
	}

	return ret, nil
}
1174218
func (c *SQLiteConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
	list := make([]namedValue, len(args))
	for i, nv := range args {
		list[i] = namedValue(nv)
	}
	return c.query(ctx, query, list)
}
203191
func (p *Parser) parseCreateContinuousQueryStatement() (*CreateContinuousQueryStatement, error) {
	stmt := &CreateContinuousQueryStatement{}

	// Read the id of the query to create.
	ident, err := p.ParseIdent()
	if err != nil {
		return nil, err
	}
	stmt.Name = ident

	// Expect an "ON" keyword.
	if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != ON {
		return nil, newParseError(tokstr(tok, lit), []string{"ON"}, pos)
	}

	// Read the name of the database to create the query on.
	if ident, err = p.ParseIdent(); err != nil {
		return nil, err
	}
	stmt.Database = ident

	if tok, _, _ := p.ScanIgnoreWhitespace(); tok == RESAMPLE {
		stmt.ResampleEvery, stmt.ResampleFor, err = p.parseResample()
		if err != nil {
			return nil, err
		}
	} else {
		p.Unscan()
	}

	// Expect a "BEGIN SELECT" tokens.
	if err := p.parseTokens([]Token{BEGIN, SELECT}); err != nil {
		return nil, err
	}

	// Read the select statement to be used as the source.
	source, err := p.parseSelectStatement(targetRequired)
	if err != nil {
		return nil, err
	}
	stmt.Source = source

	// validate that the statement has a non-zero group by interval if it is aggregated
	if !source.IsRawQuery {
		d, err := source.GroupByInterval()
		if d == 0 || err != nil {
			// rewind so we can output an error with some info
			p.Unscan() // Unscan the whitespace
			p.Unscan() // Unscan the last token
			tok, pos, lit := p.ScanIgnoreWhitespace()
			expected := []string{"GROUP BY time(...)"}
			if err != nil {
				expected = append(expected, err.Error())
			}
			return nil, newParseError(tokstr(tok, lit), expected, pos)
		}
	}

	// Expect a "END" keyword.
	if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != END {
		return nil, newParseError(tokstr(tok, lit), []string{"END"}, pos)
	}

	if err := stmt.validate(); err != nil {
		return nil, err
	}

	return stmt, nil
}
235107
func (q *Qbs) ContainsValue(table interface{}, column string, value interface{}) bool {
	quotedColumn := q.Dialect.quote(column)
	quotedTable := q.Dialect.quote(tableName(table))
	query := fmt.Sprintf("SELECT %v FROM %v WHERE %v = ?", quotedColumn, quotedTable, quotedColumn)
	row := q.QueryRow(query, value)
	var result interface{}
	err := row.Scan(&result)
	q.updateTxError(err)
	return err == nil
}
89847
func CreateConsistentTableScanners(ctx context.Context, tablet *topo.TabletInfo, wr *wrangler.Wrangler, cleaner *wrangler.Cleaner, numberOfScanners int) ([]TableScanner, string, error) {
	txs, gtid, err := CreateConsistentTransactions(ctx, tablet, wr, cleaner, numberOfScanners)
	if err != nil {
		return nil, "", err
	}

	queryService, _ := tabletconn.GetDialer()(tablet.Tablet, true)
	defer queryService.Close(ctx)

	scanners := make([]TableScanner, numberOfScanners)
	for i, tx := range txs {
		scanners[i] = TransactionalTableScanner{
			wr:           wr,
			cleaner:      cleaner,
			tabletAlias:  tablet.Alias,
			queryService: queryService,
			tx:           tx,
		}
	}

	return scanners, gtid, nil
}
44885
func (p *preprocessor) checkContainDotColumn(stmt *ast.CreateTableStmt) {
	tName := stmt.Table.Name.String()
	sName := stmt.Table.Schema.String()

	for _, colDef := range stmt.Cols {
		// check schema and table names.
		if colDef.Name.Schema.O != sName && len(colDef.Name.Schema.O) != 0 {
			p.err = ddl.ErrWrongDBName.GenWithStackByArgs(colDef.Name.Schema.O)
			return
		}
		if colDef.Name.Table.O != tName && len(colDef.Name.Table.O) != 0 {
			p.err = ddl.ErrWrongTableName.GenWithStackByArgs(colDef.Name.Table.O)
			return
		}
	}
}
1193348
func checkSQLSyntax(ctx *cli.Context) {
	if !ctx.Args().Present() {
		cli.ShowCommandHelpAndExit(ctx, "sql", 1) // last argument is exit code.
	}
}
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...)
}
926377
func checkCacheDiskConsistency(formats []*formatCacheV1) error {
	var disks = make([]string, len(formats))
	// Collect currently available disk uuids.
	for index, format := range formats {
		if format == nil {
			disks[index] = ""
			continue
		}
		disks[index] = format.Cache.This
	}
	for i, format := range formats {
		if format == nil {
			continue
		}
		j := findCacheDiskIndex(disks[i], format.Cache.Disks)
		if j == -1 {
			return fmt.Errorf("UUID on positions %d:%d do not match with , expected %s", i, j, disks[i])
		}
		if i != j {
			return fmt.Errorf("UUID on positions %d:%d do not match with , expected %s got %s", i, j, disks[i], format.Cache.Disks[j])
		}
	}
	return nil
}
416991
func (s *ListAttachedIndicesInput) SetConsistencyLevel(v string) *ListAttachedIndicesInput {
	s.ConsistencyLevel = &v
	return s
}
675188
func ToBoundSQL(cond interface{}) (string, error) {
	switch cond.(type) {
	case Cond:
		return condToBoundSQL(cond.(Cond))
	case *Builder:
		return cond.(*Builder).ToBoundSQL()
	}
	return "", ErrNotSupportType
}
1118506
func (ch Challenge) checkConsistency() error {
	if ch.Status != StatusPending {
		return fmt.Errorf("The challenge is not pending.")
	}

	// There always needs to be a token
	if !LooksLikeAToken(ch.Token) {
		return fmt.Errorf("The token is missing.")
	}
	return nil
}
374388
func Ginqueryarrayextract(db XODB, v0 pgtypes.Anyarray, v1 pgtypes.Internal, v2 int16, v3 pgtypes.Internal, v4 pgtypes.Internal, v5 pgtypes.Internal, v6 pgtypes.Internal) (pgtypes.Internal, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.ginqueryarrayextract($1, $2, $3, $4, $5, $6, $7)`

	// run query
	var ret pgtypes.Internal
	XOLog(sqlstr, v0, v1, v2, v3, v4, v5, v6)
	err = db.QueryRow(sqlstr, v0, v1, v2, v3, v4, v5, v6).Scan(&ret)
	if err != nil {
		return pgtypes.Internal{}, err
	}

	return ret, nil
}
441879
func NewConjunctionQuery(queries ...FtsQuery) *ConjunctionQuery {
	q := &ConjunctionQuery{newFtsQueryBase()}
	q.options["conjuncts"] = []FtsQuery{}
	return q.And(queries...)
}
404110
func (set Mysql56GTIDSet) ContainsGTID(gtid GTID) bool {
	gtid56, ok := gtid.(Mysql56GTID)
	if !ok {
		return false
	}

	for _, iv := range set[gtid56.Server] {
		if iv.start > gtid56.Sequence {
			// We assume intervals are sorted, so we can skip the rest.
			return false
		}
		if gtid56.Sequence <= iv.end {
			// Now we know that: start <= Sequence <= end.
			return true
		}
	}
	// Server wasn't in the set, or no interval contained gtid.
	return false
}