// ValidateQuery validates an AQL query.
// When the query is valid, nil returned, otherwise an error is returned.
// The query is not executed.
433197
func (d *database) ValidateQuery(ctx context.Context, query string) error {
	req, err := d.conn.NewRequest("POST", path.Join(d.relPath(), "_api/query"))
	if err != nil {
		return WithStack(err)
	}
	input := parseQueryRequest{
		Query: query,
	}
	if _, err := req.SetBody(input); err != nil {
		return WithStack(err)
	}
	resp, err := d.conn.Do(ctx, req)
	if err != nil {
		return WithStack(err)
	}
	if err := resp.CheckStatus(200); err != nil {
		return WithStack(err)
	}
	return nil
}
1187138
func (schema DatabaseSchema) validateOperations(operations ...Operation) bool {
	for _, op := range operations {
		table, ok := schema.Tables[op.Table]
		if ok {
			for column := range op.Row {
				if _, ok := table.Columns[column]; !ok {
					return false
				}
			}
			for _, row := range op.Rows {
				for column := range row {
					if _, ok := table.Columns[column]; !ok {
						return false
					}
				}
			}
			for _, column := range op.Columns {
				if _, ok := table.Columns[column]; !ok {
					return false
				}
			}
		} else {
			return false
		}
	}
	return true
}
1245945
func (s *UpdateByQueryService) Query(query Query) *UpdateByQueryService {
	s.query = query
	return s
}
948578
func (q *Qbs) Query(query string, args ...interface{}) (rows *sql.Rows, err error) {
	q.log(query, args...)
	query = q.Dialect.substituteMarkers(query)
	stmt, err := q.prepare(query)
	if err != nil {
		q.updateTxError(err)
		return
	}
	return stmt.Query(args...)
}
1345646
func Query(q string) func(r *Rego) {
	return func(r *Rego) {
		r.query = q
	}
}
1014254
func (exec *TabletExecutor) Validate(ctx context.Context, sqls []string) error {
	if exec.isClosed {
		return fmt.Errorf("executor is closed")
	}

	parsedDDLs, err := exec.parseDDLs(sqls)
	if err != nil {
		return err
	}

	bigSchemaChange, err := exec.detectBigSchemaChanges(ctx, parsedDDLs)
	if bigSchemaChange && exec.allowBigSchemaChange {
		exec.wr.Logger().Warningf("Processing big schema change. This may cause visible MySQL downtime.")
		return nil
	}
	return err
}
288679
func validateSQLConfig(cfg *SQLConfig) error {
	if cfg == nil {
		return fmt.Errorf("config is required")
	}

	if cfg.Execer == nil && cfg.Queryer == nil && cfg.Pinger == nil {
		return fmt.Errorf("one of Execer, Queryer, or Pinger is required in SQLConfig")
	}

	if (cfg.Execer != nil || cfg.Queryer != nil) && len(cfg.Query) == 0 {
		return fmt.Errorf("SQLConfig.Query is required")
	}

	return nil
}
14362
func (ctx *Context) Query(key string, defaults ...string) string {
	return (*Queries)(ctx.req).MustString(key, defaults...)
}
521024
func validatePasswordExpiresAtQuery(v interface{}, k string) (ws []string, errors []error) {
	value := v.(string)
	values := strings.SplitN(value, ":", 2)
	if len(values) != 2 {
		err := fmt.Errorf("%s '%s' does not match expected format: {operator}:{timestamp}", k, value)
		errors = append(errors, err)
	}
	operator, timestamp := values[0], values[1]

	validOperators := map[string]bool{
		"lt":  true,
		"lte": true,
		"gt":  true,
		"gte": true,
		"eq":  true,
		"neq": true,
	}
	if !validOperators[operator] {
		err := fmt.Errorf("'%s' is not a valid operator for %s. Choose one of 'lt', 'lte', 'gt', 'gte', 'eq', 'neq'", operator, k)
		errors = append(errors, err)
	}

	_, err := time.Parse(time.RFC3339, timestamp)
	if err != nil {
		err = fmt.Errorf("'%s' is not a valid timestamp for %s. It should be in the form 'YYYY-MM-DDTHH:mm:ssZ'", timestamp, k)
		errors = append(errors, err)
	}

	return
}
801219
func (p *ParamValidator) Validate(data interface{}) *Result {
	result := new(Result)
	tpe := reflect.TypeOf(data)
	kind := tpe.Kind()

	// TODO: validate type
	for _, validator := range p.validators {
		if validator.Applies(p.param, kind) {
			if err := validator.Validate(data); err != nil {
				result.Merge(err)
				if err.HasErrors() {
					return result
				}
			}
		}
	}
	return nil
}
1146764
func (b *SearchRequestBuilder) Query() *QueryBuilder {
	if b.queryBuilder == nil {
		b.queryBuilder = NewQueryBuilder()
	}
	return b.queryBuilder
}
564840
func (db *Database) ValidateTransaction(selector *string, tx *core.SendTxArgs) (*core.ValidationMessages, error) {
	messages := new(core.ValidationMessages)

	// Prevent accidental erroneous usage of both 'input' and 'data' (show stopper)
	if tx.Data != nil && tx.Input != nil && !bytes.Equal(*tx.Data, *tx.Input) {
		return nil, errors.New(`ambiguous request: both "data" and "input" are set and are not identical`)
	}
	// Place data on 'data', and nil 'input'
	var data []byte
	if tx.Input != nil {
		tx.Data = tx.Input
		tx.Input = nil
	}
	if tx.Data != nil {
		data = *tx.Data
	}
	// Contract creation doesn't validate call data, handle first
	if tx.To == nil {
		// Contract creation should contain sufficient data to deploy a contract. A
		// typical error is omitting sender due to some quirk in the javascript call
		// e.g. https://github.com/ethereum/go-ethereum/issues/16106.
		if len(data) == 0 {
			// Prevent sending ether into black hole (show stopper)
			if tx.Value.ToInt().Cmp(big.NewInt(0)) > 0 {
				return nil, errors.New("tx will create contract with value but empty code")
			}
			// No value submitted at least, critically Warn, but don't blow up
			messages.Crit("Transaction will create contract with empty code")
		} else if len(data) < 40 { // arbitrary heuristic limit
			messages.Warn(fmt.Sprintf("Transaction will will create contract, but payload is suspiciously small (%d bytes)", len(data)))
		}
		// Method selector should be nil for contract creation
		if selector != nil {
			messages.Warn("Transaction will create contract, but method selector supplied, indicating intent to call a method")
		}
		return messages, nil
	}
	// Not a contract creation, validate as a plain transaction
	if !tx.To.ValidChecksum() {
		messages.Warn("Invalid checksum on recipient address")
	}
	if bytes.Equal(tx.To.Address().Bytes(), common.Address{}.Bytes()) {
		messages.Crit("Transaction recipient is the zero address")
	}
	// Semantic fields validated, try to make heads or tails of the call data
	db.validateCallData(selector, data, messages)
	return messages, nil
}
1053321
func (c *Caches) Validate() error {
	if c.RejectCacheSize < MinRejectCacheSize {
		return fmt.Errorf("reject cache size %d is less than min: %d",
			c.RejectCacheSize, MinRejectCacheSize)
	}
	if c.ChannelCacheSize < MinChannelCacheSize {
		return fmt.Errorf("channel cache size %d is less than min: %d",
			c.ChannelCacheSize, MinChannelCacheSize)
	}

	return nil
}
576110
func (s *Schema) Validate(queryString string) []*errors.QueryError {
	doc, qErr := query.Parse(queryString)
	if qErr != nil {
		return []*errors.QueryError{qErr}
	}

	return validation.Validate(s.schema, doc, s.maxDepth)
}
1016848
func (key AnnotationKey) Validate(_ interface{}) error {
	if annotationKeyRegex.Match([]byte(key)) {
		return nil
	}

	return errInvalidAnnotationKey
}
813315
func (q *Query) validateArgField(elem *callStackElem) {
	if _, exists := elem.call.Args[elem.lastField]; exists {
		panic(fmt.Sprintf("%s: %s", duplicateArgErrorMessage, elem.lastField))
	}
}
562928
func (m *MatchPredicate) Validate() error {
	if m == nil {
		return nil
	}

	switch m.Rule.(type) {

	case *MatchPredicate_OrMatch:

		{
			tmp := m.GetOrMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "OrMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_AndMatch:

		{
			tmp := m.GetAndMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "AndMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_NotMatch:

		{
			tmp := m.GetNotMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "NotMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_AnyMatch:

		if m.GetAnyMatch() != true {
			return MatchPredicateValidationError{
				field:  "AnyMatch",
				reason: "value must equal true",
			}
		}

	case *MatchPredicate_HttpRequestHeadersMatch:

		{
			tmp := m.GetHttpRequestHeadersMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "HttpRequestHeadersMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_HttpRequestTrailersMatch:

		{
			tmp := m.GetHttpRequestTrailersMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "HttpRequestTrailersMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_HttpResponseHeadersMatch:

		{
			tmp := m.GetHttpResponseHeadersMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "HttpResponseHeadersMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	case *MatchPredicate_HttpResponseTrailersMatch:

		{
			tmp := m.GetHttpResponseTrailersMatch()

			if v, ok := interface{}(tmp).(interface{ Validate() error }); ok {

				if err := v.Validate(); err != nil {
					return MatchPredicateValidationError{
						field:  "HttpResponseTrailersMatch",
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}
		}

	default:
		return MatchPredicateValidationError{
			field:  "Rule",
			reason: "value is required",
		}

	}

	return nil
}