// Searches for a QueryContextCallback and returns the result of the first callback being able to deal with this
// context, or Unknown if no such callback was found.
// TODO: should calling be exported?
176972
func (qe QueryContextEvent) Call(v *View, key string, operator util.Op, operand interface{}, match_all bool) QueryContextReturn {
	log.Fine("Query context: %s, %v, %v, %v", key, operator, operand, match_all)
	for i := range qe {
		r := qe[i](v, key, operator, operand, match_all)
		if r != Unknown {
			return r
		}
	}
	log.Fine("Unknown context: %s", key)
	return Unknown
}
998376
func Context(r *http.Request) *RequestContext {
	contextMutex.RLock()
	defer contextMutex.RUnlock()
	return requestContextMap[r]
}
1055689
func (q *ModelQuery) WithContext(ctx context.Context) *ModelQuery {
	q.ctx = ctx
	return q
}
384403
func validateQueryContext(ctx context.Context) error {
	select {
	case <-ctx.Done():
		switch err := ctx.Err(); err {
		case context.Canceled:
			return ErrQueryCancelled
		case context.DeadlineExceeded:
			return ErrQueryTimeout
		default:
			return err
		}
	default:
		return nil
	}
}
1216960
func (c *Context) Query(key string) string {
	if c.query == nil {
		c.query = c.Request.URL.Query()
	}
	return c.query.Get(key)
}
1070520
func (c *Client) AnswerCallbackQuery(callbackQueryID string, opts ...sendOption) error {
	req := url.Values{}
	req.Set("callback_query_id", callbackQueryID)
	for _, opt := range opts {
		opt(req)
	}
	var success bool
	return c.doRequest("answerCallbackQuery", req, &success)
}
774877
func (tx *Tx) QueryOneContext(
	c context.Context,
	model interface{},
	query interface{},
	params ...interface{},
) (Result, error) {
	return tx.queryOne(c, model, query, params...)
}
887701
func (q *Query) WithContext(ctx context.Context) *Query {
	q2 := *q
	q2.context = ctx
	return &q2
}
876258
func (call *GetLIFFAllCall) WithContext(ctx context.Context) *GetLIFFAllCall {
	call.ctx = ctx
	return call
}
516108
func (c *Context) Query(name string) (v string) {
	return c.query.Get(name)
}
1201892
func (client *Client) PaginateWithContext(ctx context.Context, g Listable, callback IterateItemFunc) {
	req, err := g.ListRequest()
	if err != nil {
		callback(nil, err)
		return
	}

	pageSize := client.PageSize

	page := 1

	for {
		req.SetPage(page)
		req.SetPageSize(pageSize)
		resp, err := client.RequestWithContext(ctx, req)
		if err != nil {
			// in case of 431, the response is knowingly empty
			if errResponse, ok := err.(*ErrorResponse); ok && page == 1 && errResponse.ErrorCode == ParamError {
				break
			}

			callback(nil, err)
			break
		}

		size := 0
		didErr := false
		req.Each(resp, func(element interface{}, err error) bool {
			// If the context was cancelled, kill it in flight
			if e := ctx.Err(); e != nil {
				element = nil
				err = e
			}

			if callback(element, err) {
				size++
				return true
			}

			didErr = true
			return false
		})

		if size < pageSize || didErr {
			break
		}

		page++
	}
}
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)
}
665151
func (call *GetNumberMessagesCall) WithContext(ctx context.Context) *GetNumberMessagesCall {
	call.ctx = ctx
	return call
}
164733
func (client *Client) GetWithContext(ctx context.Context, ls Listable) (interface{}, error) {
	gs, err := client.ListWithContext(ctx, ls)
	if err != nil {
		return nil, err
	}

	count := len(gs)
	if count != 1 {
		req, err := ls.ListRequest()
		if err != nil {
			return nil, err
		}
		params, err := client.Payload(req)
		if err != nil {
			return nil, err
		}

		// removing sensitive/useless informations
		params.Del("expires")
		params.Del("response")
		params.Del("signature")
		params.Del("signatureversion")

		// formatting the query string nicely
		payload := params.Encode()
		payload = strings.Replace(payload, "&", ", ", -1)

		if count == 0 {
			return nil, &ErrorResponse{
				CSErrorCode: ServerAPIException,
				ErrorCode:   ParamError,
				ErrorText:   fmt.Sprintf("not found, query: %s", payload),
			}
		}
		return nil, fmt.Errorf("more than one element found: %s", payload)
	}

	return gs[0], nil
}
336679
func (db *DB) QueryRowContext(ctx context.Context, q interface{}, args ...interface{}) *Row {
	ctx, finishTrace := db.addTracerToContext(ctx, opQueryRow)
	defer finishTrace()
	start := time.Now()
	rewrittenQuery, err := rewriteQuery(ctx, db, start, q)
	if err != nil {
		return &Row{rows: Rows{Rows: nil, db: nil}, err: err}
	}

	serializer, err := db.getSerializer(rewrittenQuery)
	if err != nil {
		return &Row{rows: Rows{Rows: nil, db: nil}, err: err}
	}
	queryStr, err := Serialize(serializer)
	if err != nil {
		return &Row{rows: Rows{Rows: nil, db: nil}, err: err}
	}

	argsConverted := argsConvert(args)
	rows, err := query(ctx, db.DB, queryStr, argsConverted...)
	db.logQuery(ctx, serializer, db, start, err)

	return &Row{rows: Rows{Rows: rows, db: db}, err: err}
}
574807
func ContextQueryParams(c *APIContext) map[string][]string {
	qp, ok := c.Get("QueryParams")
	if ok == false {
		qp = make(map[string][]string)
		c.Set("QueryParams", qp)
	}
	return qp.(map[string][]string)
}
53931
func (c *TaskResultCall) Context(ctx context.Context) *TaskResultCall {
	c.ctx_ = ctx
	return c
}