/*
@param query
selects data from database
and sends it to environment variable
322769
@When("^I query the database with '(.+?)'$")
    public void selectData(String query) throws Exception {
        Statement myStatement = null;
        //postgres table
        List<String> sqlTable = new ArrayList<String>();
        List<String> sqlTableAux = new ArrayList<String>();
        Connection myConnection = this.commonspec.getConnection();
        java.sql.ResultSet rs = null;
        try {
            myStatement = myConnection.createStatement();
            rs = myStatement.executeQuery(query);
            //column names
            ResultSetMetaData resultSetMetaData = rs.getMetaData();
            int count = resultSetMetaData.getColumnCount();
            for (int i = 1; i <= count; i++) {
                sqlTable.add(resultSetMetaData.getColumnName(i).toString());
            }
            //takes column names and column count
            while (rs.next()) {
                for (int i = 1; i <= count; i++) {
                    //aux list without column names
                    sqlTableAux.add(rs.getObject(i).toString());
                }
            }
            sqlTable.addAll(sqlTableAux);

            //sends raws to environment variable
            for (int i = 0; i < sqlTable.size(); i++) {
                ThreadProperty.set("queryresponse" + i, sqlTable.get(i));
            }
            ThreadProperty.remove("queryresponse" + sqlTable.size());
            rs.close();
            myStatement.close();
        } catch (Exception e) {
            e.printStackTrace();
            Assertions.assertThat(rs).as("There are no response from SELECT").isNotNull();
        }
    }
1304606
function runQuery(query, connection) {
  const { maxRows } = connection;
  const limit = maxRows < CRATE_LIMIT ? maxRows : CRATE_LIMIT;

  if (connection.port) {
    crate.connect(connection.host, connection.port);
  } else {
    crate.connect(connection.host);
  }

  return crate
    .execute(query)
    .then(res => {
      const results = {
        rows: res.json,
        incomplete: false
      };

      if (results.rows.length >= limit) {
        results.incomplete = true;
        results.rows = results.rows.slice(0, limit);
      }

      return results;
    })
    .catch(err => {
      throw new Error(err.message);
    });
}
535770
private static function logQuery(string $query): void
  {
    $query = trim($query);

    if (strpos($query, "\n")!==false)
    {
      // Query is a multi line query.
      self::$io->logVeryVerbose('Executing query:');
      self::$io->logVeryVerbose('<sql>%s</sql>', $query);
    }
    else
    {
      // Query is a single line query.
      self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
    }
  }
1006181
public void updateQuery(QueryControllerQuery query) {
		int position = getElementPosition(query.getID());
		queries.set(position, query);
	}
364834
@Override
  public void execute(TSDB tsdb, HttpQuery query) {
  
    final HttpMethod method = query.getAPIMethod();
    if (method != HttpMethod.GET && method != HttpMethod.POST) {
      throw new BadRequestException("Unsupported method: " + method.getName());
    }
    
    // the uri will be /api/vX/search/<type> or /api/search/<type>
    final String[] uri = query.explodeAPIPath();
    final String endpoint = uri.length > 1 ? uri[1] : "";
    final SearchType type;
    final SearchQuery search_query;
    
    try {
      type = SearchQuery.parseSearchType(endpoint);
    } catch (IllegalArgumentException e) {
      throw new BadRequestException("Invalid search query type supplied", e);
    }
    
    if (query.hasContent()) {
      search_query = query.serializer().parseSearchQueryV1();
    } else {
      search_query = parseQueryString(query, type);
    }
    
    search_query.setType(type);
    
    if (type == SearchType.LOOKUP) {
      processLookup(tsdb, query, search_query);
      return;
    }
    
    try {
      final SearchQuery results = 
        tsdb.executeSearch(search_query).joinUninterruptibly();
      query.sendReply(query.serializer().formatSearchResultsV1(results));
    } catch (IllegalStateException e) {
      throw new BadRequestException("Searching is not enabled", e);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
868397
public static int exec(String query, Object ... params){
        return new DB(DB.DEFAULT_NAME).exec(query, params);
    }
70057
public int executeUpdate(final String query) throws SQLException {
        startTimer();
        try {
            if (queryResult != null) {
                queryResult.close();
            }
            warningsCleared = false;
            if(inputStream == null)
                queryResult = protocol.executeQuery(queryFactory.createQuery(query));
            else 
                queryResult = protocol.executeQuery(queryFactory.createQuery(query), inputStream);
            return (int) ((ModifyQueryResult) queryResult).getUpdateCount();
        } catch (QueryException e) {
            throw SQLExceptionMapper.get(e);
        }
        finally
        {
            stopTimer();
            if(inputStream != null)
            {
                try
                {
                    inputStream.close();
                }
                catch (IOException e)
                {
                }
                inputStream = null;
            }
        }
    }
870053
private final void setNativeSqlParameters(final Query query, final List<NativeSqlCondition> conditions) {
        for (final NativeSqlCondition condition : conditions) {
            query.setParameter(condition.getColumn(), condition.getValue());
        }
    }
379037
@Override
    public void handlePress(CallbackQuery query) {
        value = !value;
        executeCallback();
        setText(callback.handleToggle(this, value));
    }
1300935
@Override
    public String getUsernameFromQuery(final Map<String, List<Object>> query) {
        final List<Object> usernameAttributeValues = query.get(this.usernameAttribute);

        if (usernameAttributeValues == null || usernameAttributeValues.size() == 0) {
            return null;
        }

        final Object firstValue = usernameAttributeValues.get(0);
        if (firstValue == null) {
            return null;
        }

        final String username = StringUtils.trimToNull(String.valueOf(firstValue));
        if (username == null || username.contains(IPersonAttributeDao.WILDCARD)) {
            return null;
        }

        return username;
    }
894743
@Override
    public DataSet executeQuery(String query) throws JdbcServerException {
        log.info("Received execute query request: " + query);
        Message response = handleMessageAndCheckResponse(JdbcMessage.execute(query));
        return dataSetCreator.createDataSet(response, getMessageType(response));
    }
978085
public FutureAPIResponse sendQueryAsFuture(Map<String, Object> query)
      throws ExecutionException, InterruptedException, IOException {
    RequestBuilder builder = new RequestBuilder("POST");
    builder.setUrl(apiUrl + "/queries.json");

    // handle DateTime separately
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(DateTime.class, new DateTimeAdapter());
    Gson gson = gsonBuilder.create();

    String requestJsonString = gson.toJson(query);
    builder.setBody(requestJsonString);
    builder.setHeader("Content-Type", "application/json");
    builder.setHeader("Content-Length", "" + requestJsonString.length());
    return new FutureAPIResponse(client.executeRequest(builder.build(), getHandler()));
  }
455868
@Override
    public MongodbQueryResult build(String query) throws IOException, ParserNotFoundException {
        DBObject result = (DBObject) super.parse(query);
        return new MongodbQueryResult(query, result);
    }
1294014
public void configureTaskQuery(TaskQueryImpl query) {
    configureQuery(query);

    if(query.getAuthCheck().isAuthorizationCheckEnabled()) {

      // necessary authorization check when the task is part of
      // a running process instance

      CompositePermissionCheck permissionCheck = new PermissionCheckBuilder()
              .disjunctive()
              .atomicCheck(TASK, "RES.ID_", READ)
              .atomicCheck(PROCESS_DEFINITION, "PROCDEF.KEY_", READ_TASK)
              .build();
        addPermissionCheck(query.getAuthCheck(), permissionCheck);
    }
  }
1304723
public void setQuery( String query )
    {
        _parameters = null;

        if ( query == null || query.length() == 0 ) { return; }

        for ( StringTokenizer tok = new StringTokenizer( query, "&" ); tok.hasMoreElements(); )
        {
            String queryItem = tok.nextToken();

            if ( queryItem.startsWith( "amp;" ) )
            {
                queryItem = queryItem.substring( 4 );
            }

            int eq = queryItem.indexOf( '=' );
            if ( eq != -1 )
            {
                addParameter( queryItem.substring( 0, eq ) , queryItem.substring( eq + 1 ), true );
            }
            else
            {
                addParameter( queryItem, null, true );
            }
        }
    }
949019
function(bson, ns, query, options) {
  var self = this;
  // Basic options needed to be passed in
  if (ns == null) throw new Error('ns must be specified for query');
  if (query == null) throw new Error('query must be specified for query');

  // Validate that we are not passing 0x00 in the collection name
  if (ns.indexOf('\x00') !== -1) {
    throw new Error('namespace cannot contain a null character');
  }

  // Basic options
  this.bson = bson;
  this.ns = ns;
  this.query = query;

  // Ensure empty options
  this.options = options || {};

  // Additional options
  this.numberToSkip = options.numberToSkip || 0;
  this.numberToReturn = options.numberToReturn || 0;
  this.returnFieldSelector = options.returnFieldSelector || null;
  this.requestId = Query.getRequestId();

  // special case for pre-3.2 find commands, delete ASAP
  this.pre32Limit = options.pre32Limit;

  // Serialization option
  this.serializeFunctions =
    typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  this.ignoreUndefined =
    typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : false;
  this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16;
  this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : true;
  this.batchSize = self.numberToReturn;

  // Flags
  this.tailable = false;
  this.slaveOk = typeof options.slaveOk === 'boolean' ? options.slaveOk : false;
  this.oplogReplay = false;
  this.noCursorTimeout = false;
  this.awaitData = false;
  this.exhaust = false;
  this.partial = false;
}
183555
protected void prepareQuery(org.hibernate.query.Query query) {
        if (cacheQueries) {
            query.setCacheable(true);
        }
        if (shouldPassReadOnlyToHibernate()) {
            query.setReadOnly(true);
        }
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
        if (sessionHolder != null && sessionHolder.hasTimeout()) {
            query.setTimeout(sessionHolder.getTimeToLiveInSeconds());
        }
    }