Look up value by using Query table
199339
def _query(_node_id, value=None, **kw):
    ""
    query_result = []
    try:
        query_result = db.execute(text(fetch_query_string('select_query_from_node.sql')), **kw).fetchall()
    except DatabaseError as err:
        current_app.logger.error("DatabaseError: %s, %s", err, kw)
        return value
    #current_app.logger.debug("queries kw: %s", kw)
    #current_app.logger.debug("queries value: %s", value)
    current_app.logger.debug("queries: %s", query_result)
    if query_result:
        values = []
        for query_name in [x['name'] for x in query_result]:
            if query_name:
                result = []
                try:
                    current_app.logger.debug("query_name: %s", query_name)
                    #current_app.logger.debug("kw: %s", kw)
                    # Query string can be insert or select here
                    #statement = text(fetch_query_string(query_name))
                    #params = [x.key for x in statement.params().get_children()]
                    #skw = {key: kw[key] for key in params}
                    #result = db.execute(statement, **skw)
                    result = db.execute(text(fetch_query_string(query_name)), **kw)
                    current_app.logger.debug("result query: %s", result.keys())
                except (DatabaseError, StatementError) as err:
                    current_app.logger.error("DatabaseError (%s) %s: %s", query_name, kw, err)
                if result and result.returns_rows:
                    result = result.fetchall()
                    #values.append(([[dict(zip(result.keys(), x)) for x in result]], result.keys()))
                    #values.append((result.fetchall(), result.keys()))
                    #current_app.logger.debug("fetchall: %s", values)
                    if len(result) == 0:
                        values.append(([], []))
                    else:
                        current_app.logger.debug("result: %s", result)
                        # There may be more results, but only interested in the
                        # first one. Use the older rowify method for now.
                        # TODO: use case for rowify?
                        values.append(rowify(result, [(x, None) for x in result[0].keys()]))
                        #current_app.logger.debug("fetchone: %s", values)
        value = values
    #current_app.logger.debug("value: %s", value)
    return value
524887
public TResult queryForLike(String fieldName, Object value, String groupBy,
			String having, String orderBy) {
		String where = buildWhereLike(fieldName, value);
		String[] whereArgs = buildWhereArgs(value);
		TResult result = userDb.query(getTableName(), table.getColumnNames(),
				where, whereArgs, groupBy, having, orderBy);
		prepareResult(result);
		return result;
	}
772835
function query (options$$1, next) {

    var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1);

    each(options$$1.params, function (value, key) {
        if (urlParams.indexOf(key) === -1) {
            query[key] = value;
        }
    });

    query = Url.params(query);

    if (query) {
        url += (url.indexOf('?') == -1 ? '?' : '&') + query;
    }

    return url;
}
458531
function(cb) {
      // For a basic match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (
          typeof query[k] === 'string' ||
          typeof query[k] === 'number' ||
          typeof query[k] === 'boolean' ||
          util.isDate(query[k]) ||
          query[k] === null
        ) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(null, self.indexes[usableQueryKeys[0]].getMatching(query[usableQueryKeys[0]]));
      }

      // For a $in match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (query[k] && query[k].hasOwnProperty('$in')) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(
          null,
          self.indexes[usableQueryKeys[0]].getMatching(query[usableQueryKeys[0]].$in),
        );
      }

      // For a comparison match
      usableQueryKeys = [];
      Object.keys(query).forEach(function(k) {
        if (
          query[k] &&
          (query[k].hasOwnProperty('$lt') ||
            query[k].hasOwnProperty('$lte') ||
            query[k].hasOwnProperty('$gt') ||
            query[k].hasOwnProperty('$gte'))
        ) {
          usableQueryKeys.push(k);
        }
      });
      usableQueryKeys = _.intersection(usableQueryKeys, indexNames);
      if (usableQueryKeys.length > 0) {
        return cb(
          null,
          self.indexes[usableQueryKeys[0]].getBetweenBounds(query[usableQueryKeys[0]]),
        );
      }

      // By default, return all the DB data
      return cb(null, self.getAllData());
    }
361264
def search(query, data, replacements=None):
    """"""
    query = q.Query(query, params=replacements)
    for entry in data:
        if solve.solve(query, entry).value:
            yield entry
803049
def query_value(stmt, args=(), default=None):
    
    for row in query(stmt, args, TupleFactory):
        return row[0]
    return default
763795
public function lookup(): void
    {
        $this->request->allowMethod(['post', 'put', 'patch']);
        $result = [];
        $data = $this->request->getData();
        $searchTerm = empty($data['term']) ? '' : $data['term'];

        $query = $this->CalendarAttendees->find()
            ->where([
                'OR' => [
                    'display_name LIKE' => "%$searchTerm%",
                    'contact_details LIKE' => "%$searchTerm%"
                ]
            ]);
        $attendees = $query->toArray();

        foreach ($attendees as $k => $att) {
            $result[] = [
                'id' => $att->id,
                'text' => "{$att->display_name} - {$att->contact_details}",
            ];
        }

        $this->set(compact('result'));
        $this->set('_serialize', 'result');
    }
354766
function(query) {
        var queryObj = {q: ''};
        if(!query) {
            return queryObj;
        }

        var qArray = query.split('&');
        var qObj = qs.parse(query);
        for(var i = 0, len = qArray.length; i < len; i++) {
            var queryItem = decodeURIComponent(qArray[i]).replace('=', '');
            if(/^\?/g.test(queryItem)) {
                debug('matched query: %s', queryItem) ;
                queryObj.q = queryItem;
                break;
            }
        }

        queryObj.m = qObj._mcss == 'true' || qObj._mcss == 'y';
        return queryObj;
    }
955855
def query(self):
    """"""
    if not self.exists():
      return None
    self._table._load_info()
    if 'view' in self._table._info and 'query' in self._table._info['view']:
      return _query.Query(self._table._info['view']['query'])
    return None
1077310
function queryData($query, $keyField=null, $resultType = MYSQLI_ASSOC)
  {
    $data = [];
    $res = $this->q($query);
    if ($keyField == null)
      $data = $res->fetch_all($resultType);
    else while ($row = $res->fetch_array($resultType))
    {
      if ($keyField)
        $data[$row[$keyField]] = $row;
    }
    $res->close();
    return $data;
  }
1303170
function QueryWhere(data)
{
	//Initialize the string
	var sql = '';

	//Check the type
	if(typeof data === 'string')
	{
		//Return the where
		return data;
	}

	//Get all data
	for(var key in data)
	{
		//Save data value
		var value = data[key];

		//Check the data type
		if(typeof value === 'string' || value instanceof String)
		{
			//Add the quotes
			value = '"' + value + '"';
		}

		//Check if is necessary add the AND
		if(sql !== '')
		{
			//Add the AND
			sql = sql + ' AND ';
		}

		//Add the key=value
		sql = sql + key + '=' + value;
	}

	//Return the string
	return sql;
}
63499
public TResult queryForFieldValues(Map<String, Object> fieldValues) {
		String where = buildWhere(fieldValues.entrySet());
		String[] whereArgs = buildWhereArgs(fieldValues.values());
		TResult result = userDb.query(getTableName(), table.getColumnNames(),
				where, whereArgs, null, null, null);
		prepareResult(result);
		return result;
	}
329277
def find(self, query=None, limit=None):
        
        results = []
        query = query or {}

        # TODO: When indexes are implemented, we'll need to intelligently hit one of the
        # index stores so we don't do a full table scan
        cursor = self.db.execute("select id, data from %s" % self.name)
        apply = partial(self._apply_query, query)

        for match in filter(apply, starmap(self._load, cursor.fetchall())):
            results.append(match)

            # Just return if we already reached the limit
            if limit and len(results) == limit:
                return results

        return results
819460
function queryBitsValueByCycleIndex( oConn, uCycleIndex, pfnCallback )
{
	if ( ! oConn )
	{
		return pfnCallback( `call queryBitsValueByCycleIndex with invalid oConn` );
	}
	if ( 'number' !== typeof uCycleIndex || uCycleIndex <= 0 )
	{
		return pfnCallback( `call queryBitsValueByCycleIndex with invalid uCycleIndex` );
	}

	oConn.query
	(
		"SELECT bits \
		FROM round_cycle \
		WHERE cycle_id = ?",
		[
			_round.getCycleIdByRoundIndex( uCycleIndex )
		],
		function( arrRows )
		{
			if ( 0 === arrRows.length )
			{
				return pfnCallback( `bits not found in table [round_cycle].` );
			}

			return pfnCallback( null, parseInt( arrRows[ 0 ][ 'bits' ] ) );
		}
	);
}
1222328
def get(self, query, *parameters, **kwargs):
        """"""
        rows = self.query(query, *parameters, **kwargs)
        if not rows:
            return None
        elif len(rows) > 1:
            raise ValueError('Multiple rows returned for get() query')
        else:
            return rows[0]
1045927
def find_by(self, values={}, **kwargs):
        
        try:
            return self(
                **self.select(
                    where=values,
                    limit=1,
                    **kwargs
                    ).to_dict(orient='records')[0]
                )
        except IndexError:
            return None
503216
function query (query, params) {
        let rows = [];
        let stmt = sql.prepare(query);
        params = normalizeParams(params);
        stmt.bind(params);
        while(stmt.step()) {
            rows.push(stmt.getAsObject());
        }
        stmt.free();
        return rows;
    }