Select records from database table according to search condition

@param condition valid SQL condition expression started with WHERE or
empty string if all records should be fetched.
199511
public final Cursor<T> select (Connection conn, String condition)
    {
        String query = "select " + listOfFields + " from " + name +
            " " + condition;
        return new Cursor<T>(this, conn, query);
    }
276608
public static Elements select(String query, Element root) {
        Validate.notEmpty(query);
        return select(QueryParser.parse(query), root);
    }
1203039
public final Cursor<T> straightJoin (Connection conn, String table,
                                         String condition)
    {
        String query = "select " + listOfFields +
            " from " + name + " straight_join " + table + " " + condition;
        return new Cursor<T>(this, conn, query);
    }
89890
public function filter(Condition $condition = null, int &$limit = null, int &$offset = null)
    {
        $offset = (int)$offset;

        if ($condition) {
            $limit = $condition->getLimit();
            $offset = (int)$condition->getOffset();
            $conditions = $condition->getConditions();
            return function (array $item) use ($conditions) {
                foreach ($conditions as $cond) {
                    if (!\is_array($cond)) {
                        continue;
                    }

                    $cond = \array_values($cond);
                    $type = \array_shift($cond);
                    $value = $item[$cond[0]] ?? null;
                    switch ($type) {
                        case Condition::EQUALS:
                            if (\is_array($value)) {
                                if (!\in_array($cond[1], $value, false)) {
                                    return false;
                                }
                            } else {
                                /** @noinspection TypeUnsafeComparisonInspection */
                                if ($value != $cond[1]) {
                                    return false;
                                }
                            }
                            break;
                        case Condition::NOT_EQUALS:
                            /** @noinspection TypeUnsafeComparisonInspection */
                            if ($value == $cond[1]) {
                                return false;
                            }
                            break;
                        case Condition::LESS_THAN:
                            if ($value >= $cond[1]) {
                                return false;
                            }
                            break;
                        case Condition::GREATER_THAN:
                            if ($value <= $cond[1]) {
                                return false;
                            }
                            break;
                        case Condition::LESS_OR_EQUALS:
                            if ($value > $cond[1]) {
                                return false;
                            }
                            break;
                        case Condition::GREATER_OR_EQUALS:
                            if ($value < $cond[1]) {
                                return false;
                            }
                            break;
                        case Condition::BETWEEN:
                            if ($value < $cond[1] || $value > $cond[2]) {
                                return false;
                            }
                            break;
                        case Condition::LIKE:
                            if (!\mb_strstr($value, $cond[1])) {
                                return false;
                            }
                            break;
                        case Condition::IN:
                            if (!\in_array($value, $cond[1], false)) {
                                return false;
                            }
                            break;
                    }
                }

                return true;
            };
        }

        return null;
    }
20330
void setInConditionsAsTables() {

        for (int i = rangeVariables.length - 1; i >= 0; i--) {
            RangeVariable rangeVar = rangeVariables[i];
            Expression    in       = inExpressions[i];

            if (in != null) {
                Index index = rangeVar.rangeTable.getIndexForColumn(
                    in.getLeftNode().nodes[0].getColumnIndex());
                RangeVariable newRangeVar =
                    new RangeVariable(in.getRightNode().subQuery.getTable(),
                                      null, null, null, compileContext);
                RangeVariable[] newList =
                    new RangeVariable[rangeVariables.length + 1];

                ArrayUtil.copyAdjustArray(rangeVariables, newList,
                                          newRangeVar, i, 1);

                rangeVariables = newList;

                // make two columns as arg
                ColumnSchema left = rangeVar.rangeTable.getColumn(
                    in.getLeftNode().nodes[0].getColumnIndex());
                ColumnSchema right = newRangeVar.rangeTable.getColumn(0);
                Expression e = new ExpressionLogical(rangeVar, left,
                                                     newRangeVar, right);

                rangeVar.addIndexCondition(e, index, flags[i]);
            }
        }
    }
892648
public function fetchRows($condition = array())
    {
        $query = self::getInstance($this, $condition);

        return $this->getRepository()->fetch($query, AnDomain::FETCH_ROW_LIST);
    }
546025
protected boolean checkCondition(TestContext context) {
        if (conditionExpression != null) {
            return conditionExpression.evaluate(index, context);
        }

        // replace dynamic content with each iteration
        String conditionString = condition;
        if (conditionString.indexOf(Citrus.VARIABLE_PREFIX + indexName + Citrus.VARIABLE_SUFFIX) != -1) {
            Properties props = new Properties();
            props.put(indexName, String.valueOf(index));
            conditionString = new PropertyPlaceholderHelper(Citrus.VARIABLE_PREFIX, Citrus.VARIABLE_SUFFIX).replacePlaceholders(conditionString, props);
        }

        conditionString = context.replaceDynamicContentInString(conditionString);

        if (ValidationMatcherUtils.isValidationMatcherExpression(conditionString)) {
            try {
                ValidationMatcherUtils.resolveValidationMatcher("iteratingCondition", String.valueOf(index), conditionString, context);
                return true;
            } catch (AssertionError e) {
                return false;
            }
        }

        if (conditionString.indexOf(indexName) != -1) {
            conditionString = conditionString.replaceAll(indexName, String.valueOf(index));
        }

        return BooleanExpressionParser.evaluate(conditionString);
    }
362713
protected function select(array $fields, array $criteria = array(), array $operators = array(), array $conditions = array())
    {
        $sql = "";
        $stringConditions = array();
        
        if ((!empty($criteria) && !empty($operators)) && !empty($conditions)) {
            if ((count($criteria) == count($operators) && (count($criteria) - 1) == count($conditions)) 
                && ((count($operators) -1) != count($conditions) && count($criteria) > 1)) {
                throw new \Exception("The number of Criteria, Operators and Conditions are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            $stringConditions[] = "$criteriaFields[0] $operators[0] ?";
            
            for ($i = 1; $i < count($criteriaFields); $i++) {
                $j = $i - 1;
                $stringConditions[] = "$conditions[$j] $criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' ', $stringConditions);
        } elseif ((!empty($criteria) && !empty($operators)) && count($criteria) > 1) {
            if (count($criteria) != count($operators)) {
                throw new \Exception("The number of Criteria and Operators are not equals.");
            }
            
            $criteriaFields = array_keys($criteria);
            
            for ($i = 0; $i < count($criteriaFields); $i++) {
                $stringConditions[] = "$criteriaFields[$i] $operators[$i] ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($criteria)) {
            foreach ($criteria as $field => $value) {
                $stringConditions[] = "$field = ?";
            }
            
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table " 
                . "WHERE " . implode(' AND ', $stringConditions);
        } elseif (!empty($fields)) {
            $sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table";
        }
        
        $pdos = $this->_pdo->prepare($sql);
        $pdos->execute(array_values($criteria));
        
        return $pdos->fetchAll();
    }
631590
public function fetchs($condition = NULL, $params = NULL, $fields=null, $order='',$fetchMode=PDO::FETCH_ASSOC) {
		 $this->driver->field($fields)->where($condition, $params);
         $order and $this->orderby($order);
         return  $this->fetchAll($fetchMode);
	}
690318
public List<Entity> findBy(String tableName, Condition... wheres) throws SQLException {
		final Query query = new Query(wheres, tableName);
		return find(query, EntityListHandler.create());
	}
89043
static function select(\fenrir\system\MysqlDatabaseSignature $db, $table, $constraints = null) {
		$constraints !== null or $constraints = '1';
		return $db->prepare
			(
				"
					SELECT *
					  FROM `$table`
					 WHERE $constraints
				"
			)
			->execute()
			->fetch_all();
	}
225417
def select_record(self, table, where=None, values=None, orderby=None, limit=None, columns=None):
        ''' '''
        query = self.schema.query_builder.build_select(table, where, orderby, limit, columns)
        return table.to_table(self.execute(query, values), columns=columns)
232348
public function where($condition) 
    {       
        $this->condition = $condition;
        $this->sql .= ' WHERE ' . $this->buildCondition($condition);
        
        return $this;
    }
1318426
public int queryObjCountByCondition(String tableName, String condition,Object[] paramArray){
		/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
		.getDbSource(dbName);*/
		//String tableName=changeTableNameCase(otableName);
		JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
		String sql="";
		sql="select count(1) from " + tableName + " where "+condition;
		logger.debug(sql);
		logger.debug(Arrays.toString(paramArray));
		Integer total=jdbcTemplate.queryForObject(sql,Integer.class,paramArray);
		return total;
	}
298143
private function mapCondition(Condition $condition, Select $select, array $memberMappings) : Expr
    {
        /** @var MemberMappingWithTableAliases[] $memberMappings */

        if ($condition instanceof AndCondition) {
            $expressions = [];
            foreach ($condition->getConditions() as $condition) {
                $expressions[] = $this->mapCondition($condition, $select, $memberMappings);
            }

            return Expr::compoundAnd($expressions);
        } elseif ($condition instanceof OrCondition) {
            $expressions = [];
            foreach ($condition->getConditions() as $condition) {
                $expressions[] = $this->mapCondition($condition, $select, $memberMappings);
            }

            return Expr::compoundOr($expressions);
        } elseif ($condition instanceof MemberCondition) {
            return $this->mapMemberCondition($condition, $select, $memberMappings);
        } elseif ($condition instanceof InstanceOfCondition) {
            return $this->mapper->getMapping()->getClassConditionExpr($select, $condition->getClass());
        } elseif ($condition instanceof NotCondition) {
            return Expr::not($this->mapCondition($condition->getCondition(), $select, $memberMappings));
        }

        throw InvalidArgumentException::format(
            'Unknown condition type %s', get_class($condition)
        );
    }
790665
public Query query(Schema schema, Query range) {

        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        if (range != null) {
            builder.add(range, FILTER);
        }

        filter.forEach(condition -> builder.add(condition.query(schema), FILTER));
        query.forEach(condition -> builder.add(condition.query(schema), MUST));

        BooleanQuery booleanQuery = builder.build();
        return booleanQuery.clauses().isEmpty() ? new MatchAllDocsQuery() : booleanQuery;
    }
1308371
private static void visitOnCondition(SQLExpr expr, TableItem tableItem) {
        if (!(expr instanceof SQLBinaryOpExpr)) {
            throw new UnsupportedOperationException();
        }
        SQLBinaryOpExpr sqlBinaryOpExpr = (SQLBinaryOpExpr) expr;
        if (sqlBinaryOpExpr.getOperator() == BooleanAnd) {
            visitOnCondition(sqlBinaryOpExpr.getLeft(), tableItem);
            visitOnCondition(sqlBinaryOpExpr.getRight(), tableItem);
        } else if (sqlBinaryOpExpr.getOperator() == Equality) {
            FieldItem leftFieldItem = new FieldItem();
            visitColumn(sqlBinaryOpExpr.getLeft(), leftFieldItem);
            if (leftFieldItem.getColumnItems().size() != 1 || leftFieldItem.isMethod() || leftFieldItem.isBinaryOp()) {
                throw new UnsupportedOperationException("Unsupported for complex of on-condition");
            }
            FieldItem rightFieldItem = new FieldItem();
            visitColumn(sqlBinaryOpExpr.getRight(), rightFieldItem);
            if (rightFieldItem.getColumnItems().size() != 1 || rightFieldItem.isMethod()
                || rightFieldItem.isBinaryOp()) {
                throw new UnsupportedOperationException("Unsupported for complex of on-condition");
            }
            tableItem.getRelationFields().add(new RelationFieldsPair(leftFieldItem, rightFieldItem));
        } else {
            throw new UnsupportedOperationException("Unsupported for complex of on-condition");
        }
    }