/*
Allow a query to be modified without affecting quoted strings within it
760535
protected function modifyQuery(&$query, callable $callback)
    {
        $regex = "/('[^']*')/";
        if (!preg_match($regex, $query)) {
            $query = $callback($query);
            return;
        }

        $parts = preg_split($regex, $query, null, PREG_SPLIT_DELIM_CAPTURE);

        $query = "";

        foreach ($parts as $part) {

            # If this part of the query isn't a string, then perform the replace on it
            if (substr($part, 0, 1) != "'") {
                $part = $callback($part);
            }

            # Append this part of the query onto the new query we are constructing
            $query .= $part;
        }
    }
4254
def _clean_query_string(q):
    
    q = q.replace("()", "").strip()
    if q.endswith("("):
        q = q[:-1].strip()
    # Remove misplaced AND/OR/NOT at end
    if q[-3:] == "AND" or q[-3:] == "NOT":
        q = q[:-3]
    elif q[-2:] == "OR":
        q = q[:-2]

    # Balance parentheses
    while q.count("(") > q.count(")"):
        q += ")"
    while q.count(")") > q.count("("):
        q = "(" + q

    return q.strip()
71218
function buildQueryString(params) {
    var querystring = '';
    for(param in params) {
        querystring += '&' + param + '=' + params[param];
    }
    return querystring;
}
1237574
def remove_query_param(self, key, value=None):
        
        parse_result = self.query_params()
        if value is not None:
            index = parse_result[key].index(value)
            del parse_result[key][index]
        else:
            del parse_result[key]
        return URL._mutate(self, query=unicode_urlencode(parse_result, doseq=True))
955232
function encodeQueryAsString(query = {}) {
  const params = Object.keys(query).map((name) =>
    [encodeURIComponent(name), encodeURIComponent(query[name])].join('=')
  );
  return params.length ? `?${params.join('&')}` : '';
}
616245
function(callback) {
			var query = this.toQuery();
			var idx = 0;
			while (query.args.length > 0) {
				var value = query.args.shift();
				query.text = query.text.replace(/\?/,callback(value,idx));
				idx++;
			}
			return query.text;
		}
114795
function appendQueryStringOptions(requestUrl, queryStringOptions) {
    requestUrl += "?";
    for (var prop in queryStringOptions) {
        if (queryStringOptions.hasOwnProperty(prop)) {
            requestUrl += prop + "=" + queryStringOptions[prop] + "&";
        }
    }

    //Remove the last & from the string
    requestUrl = requestUrl.substr(0, requestUrl.length - 1);
    return requestUrl;
}
318185
protected function modifyQuery(string $str): string
    {
        return (string) $this->filterQuery($str)->withoutParams($this->keys);
    }
475364
private String queryAsString(Map<String, Object> query) {
        ArrayList<String> queryParts = new ArrayList<String>(query.size());
        for(Map.Entry<String, Object> entry : query.entrySet()) {
            String value = this.encodeQueryParameter(entry.getValue().toString());
            String key = this.encodeQueryParameter(entry.getKey());
            String term = String.format("%s=%s", key, value);
            queryParts.add(term);
        }
        return Misc.join("&", queryParts);
    }
1130480
function processQuote(sql, startIdx) {
    const start = sql[startIdx];
    for(let i = startIdx + 1; i < sql.length; i++) {
        if(sql[i] === "\\") {
            i++;
            continue;
        }

        if(sql[i] === start) {
            return i;
        }
    }

    return sql.length;
}
87591
def _escape_query(self, query, escaped=False):
        
        if escaped:
            return query
        query = six.text_type(query)
        for e in ['+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*',
                  '?', ':', ' ']:
            query = query.replace(e, "\\%s" % e)
        return query
156644
public void updateAllowImplicidQueryCall(Boolean allow) throws SecurityException {
	checkWriteAccess();
	boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);

	if (!hasAccess) throw new SecurityException("no access to update scope setting");

	Element scope = _getRootElement("scope");
	scope.setAttribute("cascade-to-resultset", Caster.toString(allow, ""));

    }
50735
function buildQueryString (obj) {
  var query = Object.keys(obj).reduce(function (acc, key) {
    return acc + '&' + querystring.escape(key) + '=' +
      querystring.escape(obj[key])
  }, '')
  return query.replace(/^&/, '?')
}
933070
function appendQueryString(url, params){
        var key;
        url = url || '';
        if(params){
            if(url.indexOf('?') === -1){
                url += '?';
            }
            if(typeof params === 'string'){
                url += params;
            } else if (typeof params === 'object'){
                for(key in params){
                    if(!/[?&]$/.test(url)){
                        url += '&';
                    }
                    url += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
                }
            }
        }

        return url;
    }
1064818
function checkQuery(expected, actual){
    if(!expected){
        return;
    }

    //Ignore trailing ampersands
    var actualObj = actual ? queryString.parse(actual.replace(/\&$/, '')) : {};
    var expectedObj = queryString.parse(expected);

    if(! _.isEqual(actualObj, expectedObj)){
        return {
            error: "Query parameters do not match",
            expected: expectedObj,
            actual: actualObj
        };
    }
}
873174
function (key, val) {
    if ( key.indexOf( '[]' ) !== -1 ) {
      key = key.replace( '[]', '' );

      if (isArray(this.queryParams[key])) {
        this.queryParams[key].push(val);
      }
      else {
        this.queryParams[key] = [val];
      }
    }
    else {
      this.queryParams[key] = val;
    }
  }
912760
function validateQueryParams() {
        var queryString;
        if (config.queryParams) {
            if (typeof config.queryParams === 'string') {
                // strip '?' if it's there, because we add it below
                queryString = config.queryParams.replace(/^\?/, '');
            } else {
                queryString = util.param(config.queryParams);
            }
        }
        config.queryString = queryString ? '?' + queryString : '';
    }