包装字段名<br>
有时字段与SQL的某些关键字冲突，导致SQL出错，因此需要将字段名用单引号或者反引号包装起来，避免冲突
@param conditions 被包装的实体
@return 包装后的字段名
491521
public Condition[] wrap(Condition... conditions){
		final Condition[] clonedConditions = new Condition[conditions.length];
		if(ArrayUtil.isNotEmpty(conditions)) {
			Condition clonedCondition;
			for(int i = 0; i < conditions.length; i++) {
				clonedCondition = conditions[i].clone();
				clonedCondition.setField(wrap(clonedCondition.getField()));
				clonedConditions[i] = clonedCondition;
			}
		}
		
		return clonedConditions;
	}
1241138
public void appendQuerytoSQL(Collection<Match> matches, StringBuilder sb, List<Object> params) {

        // 如果query为空，则直接返回
        if (matches == null || matches.size() == 0) {
            return;
        }

        sb.append(" where ");
        appendMatches(matches, sb, params);
    }
427629
public Condition<S, D> or(Condition<S, D> condition) {
    Assert.notNull(condition, "condition");
    return Conditions.or(this, condition);
  }
590822
def _condition_as_sql(self, qn, connection):
        '''
        
        '''
        def escape(value):
            if isinstance(value, bool):
                value = str(int(value))
            if isinstance(value, six.string_types):
                # Escape params used with LIKE
                if '%' in value:
                    value = value.replace('%', '%%')
                # Escape single quotes
                if "'" in value:
                    value = value.replace("'", "''")
                # Add single quote to text values
                value = "'" + value + "'"
            return value

        sql, param = self.condition.query.where.as_sql(qn, connection)
        param = map(escape, param)

        return sql % tuple(param)
1007119
public static Rule conditionsRule(final Set<Condition> conditions, String key, String value) {
        HashMap<String, String> results = new HashMap<>();
        results.put(key, value);
        return conditionsRule(conditions, results);
    }
828994
@Override
    public SqlInfo buildSqlInfo(BuildSource source) {
        /* 获取拼接的参数 */
        SqlInfo sqlInfo = source.getSqlInfo();
        Node node = source.getNode();

        /* 判断必填的参数是否为空 */
        String fieldText = XmlNodeHelper.getAndCheckNodeText(node, ZealotConst.ATTR_FIELD);
        String valueText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_VALUE);
        String patternText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_PATTERN);

        /* 如果匹配中'match'属性没有值，则认为是必然生成项 */
        String matchText = XmlNodeHelper.getNodeAttrText(node, ZealotConst.ATTR_MATCH);
        if (StringHelper.isBlank(matchText)) {
            sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildLikeSql(fieldText, valueText, patternText);
        } else {
            /* 如果match匹配成功，则生成数据库sql条件和参数 */
            Boolean isTrue = (Boolean) ParseHelper.parseExpressWithException(matchText, source.getParamObj());
            if (isTrue) {
                sqlInfo = XmlSqlInfoBuilder.newInstace(source).buildLikeSql(fieldText, valueText, patternText);
            }
        }

        return sqlInfo;
    }
617085
def conditions
      return ['1=0'] if !valid?

      conds       = []
      values      = []
      for col in klass.columns do
        col_str = col_name(col)
        val     = @attrs[encode_name(col)]
        if !val.blank?
          case col.type
          when :string, :text
            if val =~ /\*$/
              conds   << col_str + ' like ?'
              values  << val.gsub(/\*$/, '%')
            else
              conds   << col_str + '=?'
              values  << val
            end
          when :datetime
            case is_dbms?
            when Dbms::MYSQL
#             conds   << col_str + @_operator.exp(encode_name(col))
              conds   << sprintf("date(%s)",
                  col_str) +
                  @_operator.exp(encode_name(col))
            else
              conds   << sprintf("date(timezone('%s',%s))",
                  DEFAULT_TIMEZONE_FOR_TIMESTAMP_DATE_COMPARISON,
                  col_str) +
                  @_operator.exp(encode_name(col))
            end
            values  << val.to_s
          when :boolean
            case is_dbms?
            when Dbms::MYSQL
              conds   << col_str + @_operator.exp(encode_name(col))
              values  << (val=='true')
            else
              conds   << col_str + @_operator.exp(encode_name(col))
              values  << val
            end
          else
            conds   << col_str + @_operator.exp(encode_name(col))
            values  << val
          end
        end
      end
      return [conds.join(' and ')] + values
    end
1282935
private List<From> findFrom(SQLTableSource from) {
        //zhongshu-comment class1.isAssignableFrom(class2) class2是不是class1的子类或者子接口
        //改成用instanceof 应该也行吧：from instanceof SQLExprTableSource
        boolean isSqlExprTable = from.getClass().isAssignableFrom(SQLExprTableSource.class);

        if (isSqlExprTable) {
            SQLExprTableSource fromExpr = (SQLExprTableSource) from;
            String[] split = fromExpr.getExpr().toString().split(",");

            ArrayList<From> fromList = new ArrayList<>();
            for (String source : split) {
                fromList.add(new From(source.trim(), fromExpr.getAlias()));
            }
            return fromList;
        }

        SQLJoinTableSource joinTableSource = ((SQLJoinTableSource) from);
        List<From> fromList = new ArrayList<>();
        fromList.addAll(findFrom(joinTableSource.getLeft()));
        fromList.addAll(findFrom(joinTableSource.getRight()));
        return fromList;
    }
90967
private static List<Map<String, Object>> handleResultSetToMapList(ResultSet result,
                                                                      List<Map<String, Object>> listProperties)
            throws SQLException {
        // 存放记录的信息
        Map<String, Object> property = null;

        // 获取结果集中的列名
        List<String> listColumns = DBUtils.getColumnLabels(result);

        // 存放记录
        while (result.next()) {
            property = new HashMap<String, Object>();
            // 将每条记录的列以及相应的列值存入一个Map对象中
            for (int i = 0; i < listColumns.size(); i++) {
                property.put(listColumns.get(i), result.getObject(i + 1));
            }
            // 将存入记录的每个map对象放入数组中
            listProperties.add(property);
        }
        return listProperties;
    }
432448
public static String isValidSqlWithMessage(Connection con, String sql, List<QueryParameter> parameters) {		
		try {
			QueryUtil qu = new QueryUtil(con, DialectUtil.getDialect(con));
			Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();			
			for (QueryParameter qp : parameters) {
				params.put(qp.getName(), qp);
			}
			qu.getColumnNames(sql, params);
		} catch (Exception ex) {
			LOG.error(ex.getMessage(), ex);
			return ex.getMessage();
		}
		return null;
	}
642745
public Collection<NrqlAlertCondition> list(List<String> queryParams)
    {
        return HTTP.GET("/v2/alerts_nrql_conditions.json", null, queryParams, NRQL_ALERT_CONDITIONS).get();
    }
362005
public SqlBuilder query(Query query) {
		return this.select(query.getFields()).from(query.getTableNames()).where(LogicalOperator.AND, query.getWhere());
	}
127574
public static Condition[] buildConditions(Entity entity) {
		if (null == entity || entity.isEmpty()) {
			return null;
		}

		final Condition[] conditions = new Condition[entity.size()];
		int i = 0;
		Object value;
		for (Entry<String, Object> entry : entity.entrySet()) {
			value = entry.getValue();
			if (value instanceof Condition) {
				conditions[i++] = (Condition) value;
			} else {
				conditions[i++] = new Condition(entry.getKey(), value);
			}
		}

		return conditions;
	}
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;
	}
1222260
public static function select(...$conditions)
    {
        $keys = [];
        foreach($conditions as $condition)
        {
            $keys[] = static::generateKey($condition);
        }
        $datas = static::__getRedis()->mGet($keys);
        $list = [];
        foreach($datas as $data)
        {
            if(null !== $data)
            {
                $list[] = static::newInstance($data);
            }
        }
        return $list;
    }
1258733
public <T extends Object, O extends Object> List<T> findBySQL(String sql, List<O> params, RowMapper<T> mapper) {

        if (sql == null) {
            recordLog(" param sql is null!");
        }

        // 构造参数
        Object[] args = null;
        if (params == null) {
            args = new Object[0];
        } else {
            args = params.toArray(new Object[params.size()]);
        }

        // 查询
        if (params != null) {
            recordLog(sql + "\t" + params.toString());
        } else {
            recordLog(sql);
        }
        return (List<T>) jdbcTemplate.query(sql, args, mapper);
    }
352382
public function get($conditions)
    {
        $sql = 'SELECT * FROM ' . $this->table .
            ' WHERE id = :id';

        $stat = $this->pdo->prepare($sql);
        $stat->bindValue(':id', $conditions);
        $stat->execute();

        return $stat->fetch(\PDO::FETCH_ASSOC);
    }