Range query parameters -----------------------------------------------------------------------------------------------------
171374
public <T> void addRangeQueryParameters(List<? extends Object> paramList, String listId, Class<T> type, String fieldName, String joinClause, boolean union ) {
        List<T> listIdParams;
        if( paramList != null && paramList.size() > 0 ) { 
            Object inputObject = paramList.get(0);
            if( inputObject == null ) { 
                inputObject = paramList.get(1);
                if( inputObject == null ) { 
                    return;
                }
            }  
            listIdParams = checkAndConvertListToType(paramList, inputObject, listId, type);
        } else { 
            return;
        }
        
        T min = listIdParams.get(0);
        T max = listIdParams.get(1);
        Map<String, T> paramNameMinMaxMap = new HashMap<String, T>(2);
        StringBuilder queryClause = new StringBuilder("( " );
        if( joinClause != null ) { 
           queryClause.append("( "); 
        } 
        queryClause.append(fieldName);
        if( min == null ) { 
          if( max == null ) { 
              return;
          } else { 
              // only max
              String maxParamName = generateParamName();
              queryClause.append(" <= :" + maxParamName + " " );
              paramNameMinMaxMap.put(maxParamName, max);
          }
        } else if( max == null ) { 
            // only min
            String minParamName = generateParamName();
            queryClause.append(" >= :" + minParamName + " ");
            paramNameMinMaxMap.put(minParamName, min);
        } else { 
            // both min and max
            String minParamName = generateParamName();
            String maxParamName = generateParamName();
            if( union ) { 
                queryClause.append(" >= :" + minParamName + " OR " + fieldName + " <= :" + maxParamName + " " );
            } else { 
                queryClause.append(" BETWEEN :" + minParamName + " AND :" + maxParamName + " " );
            }
            paramNameMinMaxMap.put(minParamName, min);
            paramNameMinMaxMap.put(maxParamName, max);
        } 
        if( joinClause != null ) { 
            queryClause.append(") and " + joinClause.trim() + " ");
        }
        queryClause.append(")");
        
        // add query string to query builder and fill params map
        internalAddToQueryBuilder(queryClause.toString(), union);
        for( Entry<String, T> nameMinMaxEntry : paramNameMinMaxMap.entrySet() ) { 
            addNamedQueryParam(nameMinMaxEntry.getKey(), nameMinMaxEntry.getValue());
        }
        queryBuilderModificationCleanup();
    }
841142
function findStoresInRangeApprox(location, range, callback) { var r = range / 60
    , lat0 = location.lat - r
    , lat1 = location.lat + r
    , lng0 = location.lng - r
    , lng1 = location.lng + r
    ;

  db.collection(stores, function(err, collection) {
    if(err) return callback(err);

    var query = {
        latitude: { $gt: lat0, $lt: lat1 }
      , longitude: { $gt: lng0, $lt: lng1}
    };

    collection.find(query).toArray(function(err, docs) {
      if (err) return callback(err);
      callback(null, docs);
    });
  });
}
496150
@Override
  public Collection<Range<T>> rangesContaining(final Range<T> queryRange) {
    final ImmutableSet.Builder<Range<T>> ret = ImmutableSet.builder();
    for (final Range<T> range : ranges) {
      if (range.encloses(queryRange)) {
        ret.add(range);
      }
    }
    return ret.build();
  }
1125202
function queryDatabase(db, expr) {
  // TODO(benvanik): allow the user to switch zone.
  var zone = db.getZones()[0];

  // If the user provided an expression on the command line, use that.
  if (expr && expr.length) {
    issue(expr);
    return 0;
  }

  var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  rl.on('line', function(line) {
    line = line.trim();
    if (line == 'q' || line == 'quit') {
      rl.close();
      return;
    }

    issue(line);

    rl.prompt();
  });
  rl.on('close', function() {
    console.log('');
    db.dispose();
    process.exit(0);
  });
  rl.setPrompt('> ');
  rl.prompt();

  function issue(expr) {
    console.log('Expression: ' + expr);

    var result;
    try {
      result = zone.query(expr);
    } catch (e) {
      console.log(e);
      return;
    }

    var xexpr = result.getCompiledExpression();
    console.log(xexpr.toString());
    console.log('');

    var resultValue = result.getValue();
    if (resultValue instanceof wtf.db.EventIterator) {
      var it = resultValue;
      if (!it.getCount()) {
        console.log('Nothing matched');
      } else {
        console.log('Results: (' + it.getCount() + ' total)');
        for (; !it.done(); it.next()) {
          util.logEvent(it, zone);
        }
      }
    } else if (typeof resultValue == 'boolean' ||
        typeof resultValue == 'number' ||
        typeof resultValue == 'string') {
      console.log('Result:');
      logResult(resultValue);
    } else if (!resultValue) {
      // Note we test this after so that 0/strings/etc are handled.
      console.log('Nothing matched');
    } else if (resultValue.length) {
      console.log('Results: (' + resultValue.length + ' total)');
      for (var n = 0; n < resultValue.length; n++) {
        logResult(resultValue[n]);
      }
    } else {
      console.log('Result:');
      logResult(resultValue);
    }

    console.log('');
    console.log('Took ' + result.getDuration().toFixed(3) + 'ms');
  }
}
870682
def query(self, query, *parameters, **kwargs):
        """"""
        cursor = self._cursor()
        try:
            self._execute(cursor, query, parameters or None, kwargs)
            if cursor.description:
                column_names = [column.name for column in cursor.description]
                res = [Row(zip(column_names, row)) for row in cursor.fetchall()]
                cursor.close()
                return res
        except:
            cursor.close()
            raise
1280376
static int parametersCount(Query query) {
        if (query.names().isEmpty())
            return countQuestionMarkParameters(query.sql());
        else
            return query.names().size();
    }
116034
@Override
  public Collection<Range<T>> rangesOverlapping(final Range<T> queryRange) {
    final ImmutableSet.Builder<Range<T>> ret = ImmutableSet.builder();
    for (final Range<T> range : ranges) {
      if (range.isConnected(queryRange) && !range.intersection(queryRange).isEmpty()) {
        ret.add(range);
      }
    }
    return ret.build();
  }
723222
private void setParameters(Map<Parameter, Object> parameterMap, Query q)
    {
        if (parameterMap != null && !parameterMap.isEmpty())
        {
            for (Parameter parameter : parameterMap.keySet())
            {
                Object paramObject = parameterMap.get(parameter);
                if (parameter.getName() != null)
                {
                    if (paramObject instanceof Collection)
                    {
                        q.setParameterList(parameter.getName(), (Collection) paramObject);
                    }
                    else
                    {
                        q.setParameter(parameter.getName(), paramObject);
                    }
                }
                else if (parameter.getPosition() != null)
                {
                    if (paramObject instanceof Collection)
                    {
                        q.setParameterList(Integer.toString(parameter.getPosition()), (Collection) paramObject);
                    }
                    else
                    {
                        q.setParameter(Integer.toString(parameter.getPosition()), paramObject);
                    }
                }
            }
        }
    }
914823
function RANGE(from, to) {
        if (null == from || 1 != from.length || null == to || 1 != to.length) {
            throw 'Invalid args for RANGE';
        }

        return function (buffer, index, depth) {
            if (typeof depth === "undefined") { depth = 0; }
            var r;
            if (index < buffer.length && buffer.charAt(index) >= from && buffer.charAt(index) <= to) {
                return R.ok(paka.P.RANGE, index, 1, null);
            } else {
                r = R.error(paka.P.RANGE, index, null, 'Expects number in range [' + from + ', ' + to + ']');
                _update_last_error(r);
                return r;
            }
        };
    }
8340
function CheckParams(data, query)
{
    for (let key in data) {
        let par = data[key];
        if(par.constructor!=Object)continue;//非
        let errkey = par.lbl?par.lbl:(par.rem?par.rem:key);//发生错误时的key的称呼方式
        if(par.constructor != Object){return `${errkey}接口文档定义错误。`}
        if (null==par.rem && null==par.lbl) {//这里则认为是两层及以上对象嵌套,递归
            if(par.need && null==query[key]){query[key]={};delete par.need;delete par.rem;delete par.lbl;}//如果需要的传外层的话,且为空时,默认给空对象
            let msg =CheckParams(data[key],query[key]);
            if(msg){return msg;}
        }else {
            //参数是否缺少
            if(!query){return 0;}
            let val = query[key];
            //检验必要的请求参数,非必要参数则不验证
            if (par.need&&null==val) {return`缺少${par.lbl?par.lbl:(par.rem?par.rem:key)}参数。`;}
            //若未传,且有默认值,则设置默认值,然后继续向下检验默认值
            if(null!=par.default&&null==val){query[key]=par.default;val = par.default;CTX.usedefault = true;}
            if(null!=par.def&&null==val){query[key]=par.def;val = par.def;CTX.usedefault = true;}
            if(null==val){continue;}//未传的非必须参数不需要校验
            //参数类型
            if(par.type) {
                let isObj=true;
                try{
                    switch(par.type.toLowerCase()){
                        case 'number':
                        case 'int':
                            if((par.type == 'number'||par.type =='int')&& parseInt(val)!=val)throw Error('类型错误');
                            query[key] = parseInt(val);
                            val = query[key];
                            break;
                        case 'float':
                            if(par.type == 'float' && parseFloat(val)!=val)throw Error('类型错误');
                            query[key] = parseFloat(val);
                            val = query[key];
                            break;
                        case 'string':if(val.constructor.name != 'String')throw Error('类型错误');break;
                        case 'boolean':
                            if(par.type == 'boolean'&&val.constructor!=Boolean&&(val.trim()!="false"&&val.trim()!="true"))throw Error('类型错误');
                            if(val.constructor!=Boolean)query[key]=(val.trim()==="false"?false:true);
                            val = query[key];
                            break;
                        case 'object':
                            if(val.constructor != Object){
                                try{
                                    val=JSON.parse(val);
                                }catch(err){isObj=false;}
                            }
                            if(!isObj)throw Error('类型错误');break;
                        case 'array':
                            if(val.constructor != Array){
                                try{
                                    val=JSON.parse(val);
                                }catch(err){isObj=false}
                            }
                            if(!isObj)throw Error('类型错误');break;
                        case 'array':if(val.constructor.name != 'Array')throw Error('类型错误');break;
                        case 'file':if(val.path && !isExist(val.path)) throw Error('类型错误');break;
                        case 'json':
                            try{
                                let t=JSON.parse(val);
                                query[key]=t;
                                val=t;
                            }catch(err){
                                throw Error('json格式错误');
                            }
                            break;
                        default :
                            if(val.constructor.name != 'String')throw Error('类型错误');
                    }
                }catch(err){return `${errkey}参数类型错误。`;}
            }
            let msg;
            //参数长度控制
            if(par.len){
                //接口文档在定义的时候定义为一个对象
                var ol = 0;
                let name = "长度";
                switch (par.type.toLowerCase()){
                    case 'array':
                        ol =  val.length;
                        name = "数组长度";
                        break;
                    case 'object'://数组或者对象
                        ol =  Object.keys(val).length;
                        name = "对象长度";
                        break;
                    case 'string':
                        ol = val.length;
                        name = "字符串长度";
                        break;
                    case 'file':
                        ol = val.size;//文件大小
                        name = "文件大小";
                        break;
                    default:
                        ol = val.length;
                        name = "字符串长度";
                        break;
                }
                if((msg=getRange(ol,par.len))){
                    return `${errkey}${name}${msg}${'file'==par.type?'字节':''}`;
                }
            }
            //范围控制
            if(par.range && (msg=getRange(val,par.range))){return `${errkey}${'string'==par.type?"字符内容":""}${msg}`;}
            //枚举型判断参数是否在设置范围内
            if (par.enum && par.enum.indexOf(val)<0) {return `${errkey}参数只能是${par.enum}。`;}
            //正则验证参数是否合法
            if(par.reg && !eval(par.reg).test((par.type == 'file' ? val.name:par.type=='json'?JSON.stringify(val):val))){return `${errkey}格式错误`;}
            // RES.usedefault = null;
        }
    }
    return 0;
}
347646
function Range(min, max, step) {
  var scope = null
    , re = /^([A-Za-z]|\d+)\.{2}([A-Za-z]|\d+)$/;

  if (typeof min === 'string' && min.match(re)) {
    step = max;
    scope = min.split('..');
    min = cast(scope[0]);
    max = cast(scope[1]);
  }

  this.min(min);
  this.max(max);
  this.step(step);
}
435969
def search_range(self, value):
        """"""
        if value == 0 or not value % 16:
            self._search_range = value
        else:
            raise InvalidSearchRangeError("Search range must be a multiple of "
                                          "16.")
        self._replace_bm()
473033
def range(self, start='-', stop='+', count=None):
        
        return self.database.xrange(self.key, start, stop, count)
1307580
function indexInRange(index, rangeLength) {
        var range = calculateRange(rangeLength);
        if (index >= range.min && index <= range.max) {
            return true;
        }
        return false;
    }
689380
function setrange(key, offset, value, req) {
  var val = this.getKey(key, req)
    , str = typeof val === 'string'
    , len
    , buf;
  if(val && !(val instanceof Buffer)) val = new Buffer(val);
  if(typeof val === 'number') val = new Buffer('' + val);
  if(typeof value === 'string') {
    value = new Buffer(value);
  }
  offset = parseInt(offset);
  if(!val) {
    val = new Buffer('');
  }

  // zero pad where necessary
  while(val.length < offset) {
    val = Buffer.concat([val, new Buffer([0])], val.length + 1);
  }

  // slice the buffer to offset
  if(offset < val.length) {
    val = val.slice(0, offset);
  }

  val = Buffer.concat([val, value], val.length + value.length);

  // was a string, put back as a string
  if(str) {
    val = '' + val;
    len = Buffer.byteLength(val);
  // was a buffer
  }else{
    len = val.length;
  }
  this.setKey(key, val, undefined, undefined, undefined, req);
  return len;
}
724927
def __findout_range(self, name, decl_type, recursive):
        """"""
        if not self._optimized:
            self._logger.debug(
                'running non optimized query - optimization has not been done')
            decls = self.declarations
            if recursive:
                decls = make_flatten(self.declarations)
            if decl_type:
                decls = [d for d in decls if isinstance(d, decl_type)]
            return decls

        if name and templates.is_instantiation(name):
            # templates has tricky mode to compare them, so lets check the
            # whole range
            name = None

        if name and decl_type:
            impl_match = scopedef_t._impl_matchers[scopedef_t.decl](name=name)
            if impl_match.is_full_name():
                name = impl_match.decl_name_only
            if recursive:
                self._logger.debug(
                    'query has been optimized on type and name')
                return self._type2name2decls[decl_type].get(name, [])

            self._logger.debug(
                'non recursive query has been optimized on type and name')
            return self._type2name2decls_nr[decl_type].get(name, [])
        elif decl_type:
            if recursive:
                self._logger.debug('query has been optimized on type')
                return self._type2decls[decl_type]

            self._logger.debug(
                'non recursive query has been optimized on type')
            return self._type2decls_nr[decl_type]
        else:
            if recursive:
                self._logger.debug((
                    'query has not been optimized ( hint: query does not ' +
                    'contain type and/or name )'))
                return self._all_decls

            self._logger.debug((
                'non recursive query has not been optimized ( hint: ' +
                'query does not contain type and/or name )'))
            return self._all_decls_not_recursive
757175
public static boolean parametersInRange( double[] parameters, double[]... ranges ) {
        for( int i = 0; i < ranges.length; i++ ) {
            if (!NumericsUtilities.isBetween(parameters[i], ranges[i])) {
                return false;
            }
        }
        return true;
    }